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.l2.handler;
06:
07: import com.tc.async.api.AbstractEventHandler;
08: import com.tc.async.api.EventContext;
09: import com.tc.async.api.Sink;
10: import com.tc.net.groups.GroupEventsListener;
11: import com.tc.net.groups.NodeID;
12:
13: public class GroupEventsDispatchHandler extends AbstractEventHandler {
14:
15: private final GroupEventsListener target;
16:
17: public GroupEventsDispatchHandler(GroupEventsListener target) {
18: this .target = target;
19: }
20:
21: public void handleEvent(EventContext context) {
22: GroupEvent e = (GroupEvent) context;
23: if (e.nodeJoined()) {
24: target.nodeJoined(e.getNodeID());
25: } else {
26: target.nodeLeft(e.getNodeID());
27: }
28: }
29:
30: public static final class GroupEventsDispatcher implements
31: GroupEventsListener {
32: private final Sink sink;
33:
34: public GroupEventsDispatcher(Sink sink) {
35: this .sink = sink;
36: }
37:
38: public void nodeJoined(NodeID nodeID) {
39: sink.add(new GroupEvent(nodeID, true));
40: }
41:
42: public void nodeLeft(NodeID nodeID) {
43: sink.add(new GroupEvent(nodeID, false));
44: }
45: }
46:
47: private static final class GroupEvent implements EventContext {
48:
49: private final NodeID nodeID;
50: private final boolean joined;
51:
52: public GroupEvent(NodeID nodeID, boolean joined) {
53: this .nodeID = nodeID;
54: this .joined = joined;
55: }
56:
57: public boolean nodeJoined() {
58: return joined;
59: }
60:
61: public NodeID getNodeID() {
62: return nodeID;
63: }
64:
65: }
66: }
|