01: // $Id: PingRsp.java,v 1.9 2005/08/08 12:45:43 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.jgroups.Address;
06: import org.jgroups.Global;
07: import org.jgroups.util.Streamable;
08: import org.jgroups.util.Util;
09:
10: import java.io.DataInputStream;
11: import java.io.DataOutputStream;
12: import java.io.IOException;
13: import java.io.Serializable;
14:
15: public class PingRsp implements Serializable, Streamable {
16: public Address own_addr = null;
17: public Address coord_addr = null;
18: public boolean is_server = false;
19: private static final long serialVersionUID = 3634334590904551586L;
20:
21: public PingRsp() {
22: // externalization
23: }
24:
25: public PingRsp(Address own_addr, Address coord_addr,
26: boolean is_server) {
27: this .own_addr = own_addr;
28: this .coord_addr = coord_addr;
29: this .is_server = is_server;
30: }
31:
32: public boolean equals(Object obj) {
33: PingRsp other = (PingRsp) obj;
34: return own_addr != null && other.own_addr != null
35: && own_addr.equals(other.own_addr);
36: }
37:
38: public boolean isCoord() {
39: if (!is_server)
40: return false;
41: if (own_addr != null && coord_addr != null)
42: return own_addr.equals(coord_addr);
43: return false;
44: }
45:
46: public int size() {
47: int retval = Global.BYTE_SIZE * 3; // for is_server, plus 2 presence bytes
48: retval += 2 * Global.BYTE_SIZE; // 1 boolean for each address: IpAddress or other address ?
49: if (own_addr != null)
50: retval += own_addr.size();
51: if (coord_addr != null)
52: retval += coord_addr.size();
53: return retval;
54: }
55:
56: public Address getAddress() {
57: return own_addr;
58: }
59:
60: public Address getCoordAddress() {
61: return coord_addr;
62: }
63:
64: public boolean isServer() {
65: return is_server;
66: }
67:
68: public String toString() {
69: return new StringBuffer("[own_addr=").append(own_addr).append(
70: ", coord_addr=").append(coord_addr).append(
71: ", is_server=").append(is_server).append(']')
72: .toString();
73: }
74:
75: public void writeTo(DataOutputStream outstream) throws IOException {
76: Util.writeAddress(own_addr, outstream);
77: Util.writeAddress(coord_addr, outstream);
78: outstream.writeBoolean(is_server);
79: }
80:
81: public void readFrom(DataInputStream instream) throws IOException,
82: IllegalAccessException, InstantiationException {
83: own_addr = Util.readAddress(instream);
84: coord_addr = Util.readAddress(instream);
85: is_server = instream.readBoolean();
86: }
87: }
|