KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > groups > NodeIDChannelIDConverter


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.net.groups;
6
7 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
8
9 import com.tc.net.protocol.tcm.ChannelID;
10
11 import java.util.Map JavaDoc;
12
13 /**
14  * HACK::FIXME::TODO This method is a quick hack to brick NodeIDs to ChannelIDs. This mapping is only valid for the
15  * current VM. The ChannelIDs are given out in the range -100 to Integer.MIN_VALUE to not clash with the regular client
16  * channelID. This definitely needs some cleanup
17  */

18 public class NodeIDChannelIDConverter {
19
20   private static final Map map = new ConcurrentReaderHashMap();
21
22   private static int nextChannelID = -100;
23
24   public static ChannelID getChannelIDFor(NodeID nodeID) {
25     ChannelID cid = (ChannelID) map.get(nodeID);
26     if (cid != null) return cid;
27     synchronized (map) {
28       if (!map.containsKey(nodeID)) {
29         map.put(nodeID, (cid = new ChannelID(nextChannelID--)));
30       }
31     }
32     return cid;
33   }
34
35 }
36
Popular Tags