1 3 package org.jgroups.stack; 4 5 6 import org.jgroups.Address; 7 8 import java.io.Externalizable ; 9 import java.io.IOException ; 10 import java.io.ObjectInput ; 11 import java.io.ObjectOutput ; 12 import java.util.Vector ; 13 14 15 16 20 public class GossipData implements Externalizable { 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 group=null; Address mbr=null; Vector mbrs=null; 30 31 public GossipData() { 32 ; } 34 35 public GossipData(int type, String group, Address mbr, Vector 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 getGroup() {return group;} 45 public Address getMbr() {return mbr;} 46 public Vector getMbrs() {return mbrs;} 47 48 49 50 public String toString() { 51 StringBuffer sb=new StringBuffer (); 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 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 out) throws IOException { 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 in) throws IOException , ClassNotFoundException { 90 type=in.readInt(); 91 group=in.readUTF(); 92 mbr=(Address)in.readObject(); 93 mbrs=(Vector )in.readObject(); 94 } 95 96 } 97 | Popular Tags |