01: // $Id: PbcastHeader.java,v 1.3 2004/07/05 05:49:41 belaban Exp $
02:
03: package org.jgroups.protocols.pbcast;
04:
05: import org.jgroups.Header;
06:
07: import java.io.IOException;
08: import java.io.ObjectInput;
09: import java.io.ObjectOutput;
10: import java.util.Hashtable;
11:
12: public class PbcastHeader extends Header {
13: public static final int MCAST_MSG = 0; // regular multicast message
14: public static final int GOSSIP = 1; // gossip message (unicast)
15: public static final int XMIT_REQ = 2; // retransmit request (unicast)
16: public static final int XMIT_RSP = 3; // retransmit response (unicast)
17: public static final int NOT_MEMBER = 4; // shun message (unicast)
18:
19: int type = -1;
20: long seqno = -1; // we start out with 0 as first seqno for an mcast message
21: Gossip gossip = null; // used to identify gossips, implements the equals() and hashCode() methods
22: Hashtable xmit_reqs = null; // for XMIT_REQs. keys=sender, vals=List of Longs (list of missing msgs)
23:
24: public PbcastHeader() {
25: type = -1;
26: }
27:
28: public PbcastHeader(int type) {
29: this .type = type;
30: }
31:
32: public PbcastHeader(int type, long seqno) {
33: this .type = type;
34: this .seqno = seqno;
35: }
36:
37: public PbcastHeader(Gossip g, int type) {
38: this .type = type;
39: gossip = g;
40: }
41:
42: public PbcastHeader(Gossip g, int type, long seqno) {
43: this .type = type;
44: this .seqno = seqno;
45: gossip = g;
46: }
47:
48: public long getSeqno() {
49: return seqno;
50: }
51:
52: public String toString() {
53: StringBuffer sb = new StringBuffer();
54: sb.append("[PBCAST(" + type2String(type) + "), seqno=" + seqno);
55: if (gossip != null)
56: sb.append(", gossip=" + gossip);
57: sb.append(']');
58: return sb.toString();
59: }
60:
61: public long size() {
62: return 500;
63: }
64:
65: public static String type2String(int t) {
66: switch (t) {
67: case MCAST_MSG:
68: return "MCAST_MSG";
69: case GOSSIP:
70: return "GOSSIP";
71: case XMIT_REQ:
72: return "XMIT_REQ";
73: case XMIT_RSP:
74: return "XMIT_RSP";
75: case NOT_MEMBER:
76: return "NOT_MEMBER";
77: default:
78: return "UNKNOWN";
79: }
80: }
81:
82: public void writeExternal(ObjectOutput out) throws IOException {
83: out.writeInt(type);
84: out.writeLong(seqno);
85: out.writeObject(gossip);
86: out.writeObject(xmit_reqs);
87: }
88:
89: public void readExternal(ObjectInput in) throws IOException,
90: ClassNotFoundException {
91: type = in.readInt();
92: seqno = in.readLong();
93: gossip = (Gossip) in.readObject();
94: xmit_reqs = (Hashtable) in.readObject();
95: }
96:
97: }
|