KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: MergeData.java,v 1.3 2004/09/06 13:55:40 belaban Exp $
2

3 package org.jgroups.protocols.pbcast;
4
5
6 import org.jgroups.Address;
7 import org.jgroups.View;
8
9 import java.io.Externalizable JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.io.ObjectInput JavaDoc;
12 import java.io.ObjectOutput JavaDoc;
13
14
15 /**
16  * Encapsulates data sent with a MERGE_RSP (handleMergeResponse()) and INSTALL_MERGE_VIEW
17  * (handleMergeView()).
18  *
19  * @author Bela Ban Oct 22 2001
20  */

21 public class MergeData implements Externalizable JavaDoc {
22     Address sender=null;
23     boolean merge_rejected=false;
24     View view=null;
25     Digest digest=null;
26
27     /**
28      * Empty constructor needed for externalization
29      */

30     public MergeData() {
31         ;
32     }
33
34     public MergeData(Address sender, View view, Digest digest) {
35         this.sender=sender;
36         this.view=view;
37         this.digest=digest;
38     }
39
40     public Address getSender() {
41         return sender;
42     }
43
44     public View getView() {
45         return view;
46     }
47
48     public Digest getDigest() {
49         return digest;
50     }
51
52     public void setView(View v) {
53         view=v;
54     }
55
56     public void setDigest(Digest d) {
57         digest=d;
58     }
59
60
61     public boolean equals(Object JavaDoc other) {
62         return sender != null && other != null && other instanceof MergeData &&
63                 ((MergeData)other).sender != null && ((MergeData)other).sender.equals(sender);
64     }
65
66
67     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
68         out.writeObject(sender);
69         out.writeBoolean(merge_rejected);
70         if(!merge_rejected) {
71             out.writeObject(view);
72             out.writeObject(digest);
73         }
74     }
75
76     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
77         sender=(Address)in.readObject();
78         merge_rejected=in.readBoolean();
79         if(!merge_rejected) {
80             view=(View)in.readObject();
81             digest=(Digest)in.readObject();
82         }
83     }
84
85
86     public String JavaDoc toString() {
87         StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
88         sb.append("sender=" + sender);
89         if(merge_rejected)
90             sb.append(" (merge_rejected)");
91         else {
92             sb.append(", view=" + view + ", digest=" + digest);
93         }
94         return sb.toString();
95     }
96
97
98 }
99
100
101
102
Popular Tags