01: // $Id: JoinRsp.java,v 1.10 2006/01/14 14:00:33 belaban Exp $
02:
03: package org.jgroups.protocols.pbcast;
04:
05: import org.jgroups.View;
06: import org.jgroups.Global;
07: import org.jgroups.util.Streamable;
08: import org.jgroups.util.Util;
09:
10: import java.io.Serializable;
11: import java.io.DataOutputStream;
12: import java.io.IOException;
13: import java.io.DataInputStream;
14:
15: public class JoinRsp implements Serializable, Streamable {
16: View view = null;
17: Digest digest = null;
18: /** only set if JOIN failed, e.g. in AUTH */
19: String fail_reason = null;
20: private static final long serialVersionUID = -212620440767943314L;
21:
22: public JoinRsp() {
23:
24: }
25:
26: public JoinRsp(View v, Digest d) {
27: view = v;
28: digest = d;
29: }
30:
31: public JoinRsp(String fail_reason) {
32: this .fail_reason = fail_reason;
33: }
34:
35: View getView() {
36: return view;
37: }
38:
39: Digest getDigest() {
40: return digest;
41: }
42:
43: public String getFailReason() {
44: return fail_reason;
45: }
46:
47: public void setFailReason(String r) {
48: fail_reason = r;
49: }
50:
51: public void writeTo(DataOutputStream out) throws IOException {
52: Util.writeStreamable(view, out);
53: Util.writeStreamable(digest, out);
54: Util.writeString(fail_reason, out);
55: }
56:
57: public void readFrom(DataInputStream in) throws IOException,
58: IllegalAccessException, InstantiationException {
59: view = (View) Util.readStreamable(View.class, in);
60: digest = (Digest) Util.readStreamable(Digest.class, in);
61: fail_reason = Util.readString(in);
62: }
63:
64: public int serializedSize() {
65: int retval = Global.BYTE_SIZE * 2; // presence for view and digest
66: if (view != null)
67: retval += view.serializedSize();
68: if (digest != null)
69: retval += digest.serializedSize();
70:
71: retval += Global.BYTE_SIZE; // presence byte for fail_reason
72: if (fail_reason != null)
73: retval += fail_reason.length() + 2;
74: return retval;
75: }
76:
77: public String toString() {
78: StringBuffer sb = new StringBuffer();
79: sb.append("view: ");
80: if (view == null)
81: sb.append("<null>");
82: else
83: sb.append(view);
84: sb.append(", digest: ");
85: if (digest == null)
86: sb.append("<null>");
87: else
88: sb.append(digest);
89: if (fail_reason != null)
90: sb.append(", fail reason: ").append(fail_reason);
91: return sb.toString();
92: }
93: }
|