01: // $Id: GossipData.java,v 1.3 2006/10/11 14:35:45 belaban Exp $
02:
03: package org.jgroups.stack;
04:
05: import org.jgroups.Address;
06: import org.jgroups.util.Streamable;
07: import org.jgroups.util.Util;
08:
09: import java.io.*;
10: import java.util.Vector;
11: import java.util.List;
12: import java.util.ArrayList;
13: import java.util.LinkedList;
14:
15: /**
16: * Encapsulates data sent between GossipRouter and GossipClient
17: * @author Bela Ban Oct 4 2001
18: */
19: public class GossipData implements Streamable {
20: byte type = 0; // One of GossipRouter type, e.g. CONNECT, REGISTER etc
21: String group = null; // CONNECT, GET_REQ and GET_RSP
22: Address addr = null; // CONNECT
23: List mbrs = null; // GET_RSP
24:
25: public GossipData() { // for streamable
26: }
27:
28: public GossipData(byte type) {
29: this .type = type;
30: }
31:
32: public GossipData(byte type, String group, Address addr, List mbrs) {
33: this .type = type;
34: this .group = group;
35: this .addr = addr;
36: this .mbrs = mbrs;
37: }
38:
39: public byte getType() {
40: return type;
41: }
42:
43: public String getGroup() {
44: return group;
45: }
46:
47: public Address getAddress() {
48: return addr;
49: }
50:
51: public List getMembers() {
52: return mbrs;
53: }
54:
55: public void setMembers(List mbrs) {
56: this .mbrs = mbrs;
57: }
58:
59: public String toString() {
60: StringBuffer sb = new StringBuffer();
61: sb.append(GossipRouter.type2String(type)).append("(").append(
62: "group=").append(group).append(", addr=").append(addr);
63: sb.append(", mbrs=").append(mbrs);
64: return sb.toString();
65: }
66:
67: public void writeTo(DataOutputStream out) throws IOException {
68: out.writeByte(type);
69: Util.writeString(group, out);
70: Util.writeAddress(addr, out);
71: Util.writeAddresses(mbrs, out);
72: }
73:
74: public void readFrom(DataInputStream in) throws IOException,
75: IllegalAccessException, InstantiationException {
76: type = in.readByte();
77: group = Util.readString(in);
78: addr = Util.readAddress(in);
79: mbrs = (List) Util.readAddresses(in, LinkedList.class);
80: }
81:
82: }
|