KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > protocols > pbcast > PbcastHeader


1 // $Id: PbcastHeader.java,v 1.3 2004/07/05 05:49:41 belaban Exp $
2

3 package org.jgroups.protocols.pbcast;
4
5 import org.jgroups.Header;
6
7 import java.io.IOException JavaDoc;
8 import java.io.ObjectInput JavaDoc;
9 import java.io.ObjectOutput JavaDoc;
10 import java.util.Hashtable JavaDoc;
11
12
13
14
15 public class PbcastHeader extends Header {
16     public static final int MCAST_MSG = 0; // regular multicast message
17
public static final int GOSSIP = 1; // gossip message (unicast)
18
public static final int XMIT_REQ = 2; // retransmit request (unicast)
19
public static final int XMIT_RSP = 3; // retransmit response (unicast)
20
public static final int NOT_MEMBER = 4; // shun message (unicast)
21

22
23
24     int type=-1;
25     long seqno=-1; // we start out with 0 as first seqno for an mcast message
26
Gossip gossip=null; // used to identify gossips, implements the equals() and hashCode() methods
27
Hashtable JavaDoc xmit_reqs=null; // for XMIT_REQs. keys=sender, vals=List of Longs (list of missing msgs)
28

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 JavaDoc toString() {
62     StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc out) throws IOException JavaDoc {
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 JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
97     type=in.readInt();
98     seqno=in.readLong();
99     gossip=(Gossip)in.readObject();
100     xmit_reqs=(Hashtable JavaDoc)in.readObject();
101     }
102
103
104 }
105
Popular Tags