01: // $Id: MergeData.java,v 1.5 2006/01/14 14:00:33 belaban Exp $
02:
03: package org.jgroups.protocols.pbcast;
04:
05: import org.jgroups.Address;
06: import org.jgroups.View;
07:
08: import java.io.Externalizable;
09: import java.io.IOException;
10: import java.io.ObjectInput;
11: import java.io.ObjectOutput;
12:
13: /**
14: * Encapsulates data sent with a MERGE_RSP (handleMergeResponse()) and INSTALL_MERGE_VIEW
15: * (handleMergeView()).
16: *
17: * @author Bela Ban Oct 22 2001
18: */
19: public class MergeData implements Externalizable {
20: Address sender = null;
21: boolean merge_rejected = false;
22: View view = null;
23: Digest digest = null;
24:
25: /**
26: * Empty constructor needed for externalization
27: */
28: public MergeData() {
29: }
30:
31: public MergeData(Address sender, View view, Digest digest) {
32: this .sender = sender;
33: this .view = view;
34: this .digest = digest;
35: }
36:
37: public Address getSender() {
38: return sender;
39: }
40:
41: public View getView() {
42: return view;
43: }
44:
45: public Digest getDigest() {
46: return digest;
47: }
48:
49: public void setView(View v) {
50: view = v;
51: }
52:
53: public void setDigest(Digest d) {
54: digest = d;
55: }
56:
57: public boolean equals(Object other) {
58: return sender != null && other != null
59: && other instanceof MergeData
60: && ((MergeData) other).sender != null
61: && ((MergeData) other).sender.equals(sender);
62: }
63:
64: public void writeExternal(ObjectOutput out) throws IOException {
65: out.writeObject(sender);
66: out.writeBoolean(merge_rejected);
67: if (!merge_rejected) {
68: out.writeObject(view);
69: out.writeObject(digest);
70: }
71: }
72:
73: public void readExternal(ObjectInput in) throws IOException,
74: ClassNotFoundException {
75: sender = (Address) in.readObject();
76: merge_rejected = in.readBoolean();
77: if (!merge_rejected) {
78: view = (View) in.readObject();
79: digest = (Digest) in.readObject();
80: }
81: }
82:
83: public String toString() {
84: StringBuffer sb = new StringBuffer();
85: sb.append("sender=").append(sender);
86: if (merge_rejected)
87: sb.append(" (merge_rejected)");
88: else {
89: sb.append(", view=").append(view).append(", digest=")
90: .append(digest);
91: }
92: return sb.toString();
93: }
94:
95: }
|