1 3 package org.jgroups.protocols.pbcast; 4 5 import org.jgroups.Header; 6 7 import java.io.IOException ; 8 import java.io.ObjectInput ; 9 import java.io.ObjectOutput ; 10 import java.util.Hashtable ; 11 12 13 14 15 public class PbcastHeader extends Header { 16 public static final int MCAST_MSG = 0; public static final int GOSSIP = 1; public static final int XMIT_REQ = 2; public static final int XMIT_RSP = 3; public static final int NOT_MEMBER = 4; 22 23 24 int type=-1; 25 long seqno=-1; Gossip gossip=null; Hashtable xmit_reqs=null; 29 30 31 public PbcastHeader() { 32 type=-1; 33 } 34 35 36 public PbcastHeader(int type) { 37 this.type=type; 38 } 39 40 41 public PbcastHeader(int type, long seqno) { 42 this.type=type; this.seqno=seqno; 43 } 44 45 46 public PbcastHeader(Gossip g, int type) { 47 this.type=type; gossip=g; 48 } 49 50 51 public PbcastHeader(Gossip g, int type, long seqno) { 52 this.type=type; this.seqno=seqno; 53 gossip=g; 54 } 55 56 57 58 public long getSeqno() {return seqno;} 59 60 61 public String toString() { 62 StringBuffer sb=new StringBuffer (); 63 sb.append("[PBCAST(" + type2String(type) + "), seqno=" + seqno); 64 if(gossip != null) sb.append(", gossip=" + gossip); 65 sb.append(']'); 66 return sb.toString(); 67 } 68 69 70 public long size() { 71 return 500; 72 } 73 74 75 public static String type2String(int t) { 76 switch(t) { 77 case MCAST_MSG: return "MCAST_MSG"; 78 case GOSSIP: return "GOSSIP"; 79 case XMIT_REQ: return "XMIT_REQ"; 80 case XMIT_RSP: return "XMIT_RSP"; 81 case NOT_MEMBER: return "NOT_MEMBER"; 82 default: return "UNKNOWN"; 83 } 84 } 85 86 87 public void writeExternal(ObjectOutput out) throws IOException { 88 out.writeInt(type); 89 out.writeLong(seqno); 90 out.writeObject(gossip); 91 out.writeObject(xmit_reqs); 92 } 93 94 95 96 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 97 type=in.readInt(); 98 seqno=in.readLong(); 99 gossip=(Gossip)in.readObject(); 100 xmit_reqs=(Hashtable )in.readObject(); 101 } 102 103 104 } 105 | Popular Tags |