KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > stack > GossipData


1 // $Id: GossipData.java,v 1.2 2004/03/30 06:47:27 belaban Exp $
2

3 package org.jgroups.stack;
4
5
6 import org.jgroups.Address;
7
8 import java.io.Externalizable JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.io.ObjectInput JavaDoc;
11 import java.io.ObjectOutput JavaDoc;
12 import java.util.Vector JavaDoc;
13
14
15
16 /**
17  * Encapsulates data sent between GossipServer and GossipClient
18  * @author Bela Ban Oct 4 2001
19  */

20 public class GossipData implements Externalizable JavaDoc {
21     public static final int REGISTER_REQ = 1;
22     public static final int GET_REQ = 2;
23     public static final int GET_RSP = 3;
24
25     int type=0;
26     String JavaDoc group=null; // REGISTER, GET_REQ and GET_RSP
27
Address mbr=null; // REGISTER
28
Vector JavaDoc mbrs=null; // GET_RSP
29

30
31     public GossipData() {
32     ; // used for externalization
33
}
34
35     public GossipData(int type, String JavaDoc group, Address mbr, Vector JavaDoc mbrs) {
36     this.type=type;
37     this.group=group;
38     this.mbr=mbr;
39     this.mbrs=mbrs;
40     }
41
42
43     public int getType() {return type;}
44     public String JavaDoc getGroup() {return group;}
45     public Address getMbr() {return mbr;}
46     public Vector JavaDoc getMbrs() {return mbrs;}
47     
48
49
50     public String JavaDoc toString() {
51     StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
52     sb.append(type2String(type));
53     switch(type) {
54     case REGISTER_REQ:
55         sb.append(" group=" + group + ", mbr=" + mbr);
56         break;
57
58     case GET_REQ:
59         sb.append(" group=" + group);
60         break;
61
62     case GET_RSP:
63         sb.append(" group=" + group + ", mbrs=" + mbrs);
64         break;
65     }
66     return sb.toString();
67     }
68
69
70     public static String JavaDoc type2String(int t) {
71     switch(t) {
72     case REGISTER_REQ: return "REGISTER_REQ";
73     case GET_REQ: return "GET_REQ";
74     case GET_RSP: return "GET_RSP";
75     default: return "<unknown>";
76     }
77     }
78
79
80     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
81     out.writeInt(type);
82     out.writeUTF(group);
83     out.writeObject(mbr);
84     out.writeObject(mbrs);
85     }
86     
87     
88     
89     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
90     type=in.readInt();
91     group=in.readUTF();
92     mbr=(Address)in.readObject();
93     mbrs=(Vector JavaDoc)in.readObject();
94     }
95
96 }
97
Popular Tags