KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.tc.async.api.Sink;
8
9 import java.util.Collections JavaDoc;
10 import java.util.List JavaDoc;
11
12 /*
13  * This is a simple class that is a dummy group manager. All it does is it treats this one node that it runs in as a
14  * group. This is needed for two reasons, 1) to easly disable, test the rest of the system and 2) to provide an
15  * interface level replacement for tribes in 1.4 JVM
16  */

17 public class SingleNodeGroupManager implements GroupManager {
18
19   private static final GroupResponse DUMMY_RESPONSE = new GroupResponse() {
20                                                        public List JavaDoc getResponses() {
21                                                          return Collections.EMPTY_LIST;
22                                                        }
23
24                                                        public GroupMessage getResponse(NodeID nodeID) {
25                                                          return null;
26                                                        }
27                                                      };
28
29   private static final byte[] CURRENT_NODE_ID = new byte[] { 36, 24, 32 };
30
31   NodeID thisNode;
32
33   public NodeID join() throws GroupException {
34     if (thisNode != null) { throw new GroupException("Already Joined !"); }
35     this.thisNode = new NodeID("CurrentNode", CURRENT_NODE_ID);
36     return this.thisNode;
37   }
38   
39   public NodeID getLocalNodeID() throws GroupException {
40     if (thisNode == null) { throw new GroupException("Not Joined yet !"); }
41     return this.thisNode;
42   }
43
44
45   public void registerForMessages(Class JavaDoc msgClass, GroupMessageListener listener) {
46     // NOP : Since this doesnt talk to the network, this should never get any message
47
}
48
49   public void routeMessages(Class JavaDoc msgClass, Sink sink) {
50     // NOP : Since this doesnt talk to the network, this should never get any message
51
}
52
53   public void sendAll(GroupMessage msg) {
54     // NOP : No Network, no one to write to
55
}
56
57   public GroupResponse sendAllAndWaitForResponse(GroupMessage msg) {
58     // NOP : No Network, no one to write to, hen no response too
59
return DUMMY_RESPONSE;
60   }
61
62   public void sendTo(NodeID node, GroupMessage msg) throws GroupException {
63     throw new GroupException("Can't write to Node : " + node + " Node Not found !");
64   }
65
66   public GroupMessage sendToAndWaitForResponse(NodeID nodeID, GroupMessage msg) {
67     // Comeback
68
return null;
69   }
70
71   public void registerForGroupEvents(GroupEventsListener listener) {
72     // NOP : No network, no one joins or leaves
73
}
74
75   public void zapNode(NodeID nodeID) {
76     // what node ?
77
}
78
79 }
80
Popular Tags