01: // $Id: DUMMY.java,v 1.4 2005/08/08 12:45:42 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.jgroups.Event;
06: import org.jgroups.Message;
07: import org.jgroups.View;
08: import org.jgroups.stack.Protocol;
09:
10: import java.util.Vector;
11:
12: /**
13:
14: */
15:
16: public class DUMMY extends Protocol {
17: final Vector members = new Vector();
18: final String name = "DUMMY";
19:
20: /** All protocol names have to be unique ! */
21: public String getName() {
22: return "DUMMY";
23: }
24:
25: /** Just remove if you don't need to reset any state */
26: public static void reset() {
27: }
28:
29: public void up(Event evt) {
30: Message msg;
31:
32: switch (evt.getType()) {
33:
34: case Event.MSG:
35: msg = (Message) evt.getArg();
36: // Do something with the event, e.g. extract the message and remove a header.
37: // Optionally pass up
38: break;
39: }
40:
41: passUp(evt); // Pass up to the layer above us
42: }
43:
44: public void down(Event evt) {
45: Message msg;
46:
47: switch (evt.getType()) {
48: case Event.TMP_VIEW:
49: case Event.VIEW_CHANGE:
50: Vector new_members = ((View) evt.getArg()).getMembers();
51: synchronized (members) {
52: members.removeAllElements();
53: if (new_members != null && new_members.size() > 0)
54: for (int i = 0; i < new_members.size(); i++)
55: members.addElement(new_members.elementAt(i));
56: }
57: passDown(evt);
58: break;
59:
60: case Event.MSG:
61: msg = (Message) evt.getArg();
62: break;
63: }
64:
65: passDown(evt); // Pass on to the layer below us
66: }
67:
68: }
|