KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > DUMMY


1 // $Id: DUMMY.java,v 1.3 2004/09/23 16:29:41 belaban Exp $
2

3 package org.jgroups.protocols;
4
5 import org.jgroups.Event;
6 import org.jgroups.Message;
7 import org.jgroups.View;
8 import org.jgroups.stack.Protocol;
9
10 import java.util.Vector JavaDoc;
11
12
13 /**
14
15  */

16
17 public class DUMMY extends Protocol {
18     final Vector JavaDoc members=new Vector JavaDoc();
19     final String JavaDoc name="DUMMY";
20
21     /** All protocol names have to be unique ! */
22     public String JavaDoc getName() {return "DUMMY";}
23
24
25
26     /** Just remove if you don't need to reset any state */
27     public void reset() {}
28
29
30
31
32     public void up(Event evt) {
33     Message msg;
34
35     switch(evt.getType()) {
36
37     case Event.MSG:
38         msg=(Message)evt.getArg();
39         // Do something with the event, e.g. extract the message and remove a header.
40
// Optionally pass up
41
break;
42     }
43
44     passUp(evt); // Pass up to the layer above us
45
}
46
47
48
49
50
51     public void down(Event evt) {
52     Message msg;
53
54     switch(evt.getType()) {
55     case Event.TMP_VIEW:
56     case Event.VIEW_CHANGE:
57         Vector JavaDoc new_members=((View)evt.getArg()).getMembers();
58         synchronized(members) {
59         members.removeAllElements();
60         if(new_members != null && new_members.size() > 0)
61             for(int i=0; i < new_members.size(); i++)
62             members.addElement(new_members.elementAt(i));
63         }
64         passDown(evt);
65         break;
66
67     case Event.MSG:
68         msg=(Message)evt.getArg();
69         break;
70     }
71
72     passDown(evt); // Pass on to the layer below us
73
}
74
75
76
77 }
78
Popular Tags