1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Address; 6 import org.jgroups.Global; 7 import org.jgroups.util.Streamable; 8 import org.jgroups.util.Util; 9 10 import java.io.DataInputStream ; 11 import java.io.DataOutputStream ; 12 import java.io.IOException ; 13 import java.io.Serializable ; 14 15 16 public class PingRsp implements Serializable , Streamable { 17 public Address own_addr=null; 18 public Address coord_addr=null; 19 public boolean is_server=false; 20 21 public PingRsp() { 22 } 24 25 public PingRsp(Address own_addr, Address coord_addr, boolean is_server) { 26 this.own_addr=own_addr; 27 this.coord_addr=coord_addr; 28 this.is_server=is_server; 29 } 30 31 public boolean equals(Object obj) { 32 PingRsp other=(PingRsp)obj; 33 if(own_addr != null && other.own_addr != null && own_addr.equals(other.own_addr)) 34 return true; 35 return false; 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; if(own_addr != null) 49 retval+=own_addr.size(); 50 if(coord_addr != null) 51 retval+=coord_addr.size(); 52 return retval; 53 } 54 55 public Address getAddress() { 56 return own_addr; 57 } 58 59 public Address getCoordAddress() { 60 return coord_addr; 61 } 62 63 public boolean isServer() { 64 return is_server; 65 } 66 67 public String toString() { 68 return "[own_addr=" + own_addr + ", coord_addr=" + coord_addr + ", is_server=" + is_server + ']'; 69 } 70 71 public void writeTo(DataOutputStream outstream) throws IOException { 72 Util.writeAddress(own_addr, outstream); 73 Util.writeAddress(coord_addr, outstream); 74 outstream.writeBoolean(is_server); 75 } 76 77 public void readFrom(DataInputStream instream) throws IOException , IllegalAccessException , InstantiationException { 78 own_addr=Util.readAddress(instream); 79 coord_addr=Util.readAddress(instream); 80 is_server=instream.readBoolean(); 81 } 82 } 83 | Popular Tags |