01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.groups;
06:
07: import com.tc.async.api.Sink;
08:
09: import java.util.Collections;
10: import java.util.List;
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 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,
30: 32 };
31:
32: NodeID this Node;
33:
34: public NodeID join(final Node this N, final Node[] allNodes)
35: throws GroupException {
36: if (this Node != null) {
37: throw new GroupException("Already Joined !");
38: }
39: this .this Node = new NodeIDImpl("CurrentNode", CURRENT_NODE_ID);
40: return this .this Node;
41: }
42:
43: public NodeID getLocalNodeID() throws GroupException {
44: if (this Node == null) {
45: throw new GroupException("Not Joined yet !");
46: }
47: return this .this Node;
48: }
49:
50: public void registerForMessages(Class msgClass,
51: GroupMessageListener listener) {
52: // NOP : Since this doesnt talk to the network, this should never get any message
53: }
54:
55: public void routeMessages(Class msgClass, Sink sink) {
56: // NOP : Since this doesnt talk to the network, this should never get any message
57: }
58:
59: public void sendAll(GroupMessage msg) {
60: // NOP : No Network, no one to write to
61: }
62:
63: public GroupResponse sendAllAndWaitForResponse(GroupMessage msg) {
64: // NOP : No Network, no one to write to, hen no response too
65: return DUMMY_RESPONSE;
66: }
67:
68: public void sendTo(NodeID node, GroupMessage msg)
69: throws GroupException {
70: throw new GroupException("Can't write to Node : " + node
71: + " Node Not found !");
72: }
73:
74: public GroupMessage sendToAndWaitForResponse(NodeID nodeID,
75: GroupMessage msg) {
76: // Comeback
77: return null;
78: }
79:
80: public void registerForGroupEvents(GroupEventsListener listener) {
81: // NOP : No network, no one joins or leaves
82: }
83:
84: public void zapNode(NodeID nodeID, int type, String reason) {
85: // what node ?
86: }
87:
88: public void setZapNodeRequestProcessor(
89: ZapNodeRequestProcessor processor) {
90: // NOP
91: }
92: }
|