1 3 package org.jgroups.protocols; 4 5 import org.jgroups.Header; 6 import org.jgroups.Global; 7 import org.jgroups.util.Streamable; 8 import org.jgroups.util.Util; 9 10 import java.io.*; 11 12 13 public class PingHeader extends Header implements Streamable { 14 public static final byte GET_MBRS_REQ=1; public static final byte GET_MBRS_RSP=2; 17 public byte type=0; 18 public PingRsp arg=null; 19 20 public PingHeader() { 21 } 23 public PingHeader(byte type, PingRsp arg) { 24 this.type=type; 25 this.arg=arg; 26 } 27 28 public long size() { 29 long retval=Global.BYTE_SIZE *2; if(arg != null) { 31 retval+=arg.size(); 32 } 33 return retval; 34 } 35 36 public String toString() { 37 return "[PING: type=" + type2Str(type) + ", arg=" + arg + ']'; 38 } 39 40 String type2Str(byte t) { 41 switch(t) { 42 case GET_MBRS_REQ: 43 return "GET_MBRS_REQ"; 44 case GET_MBRS_RSP: 45 return "GET_MBRS_RSP"; 46 default: 47 return "<unkown type (" + t + ")>"; 48 } 49 } 50 51 52 public void writeExternal(ObjectOutput out) throws IOException { 53 out.writeByte(type); 54 out.writeObject(arg); 55 } 56 57 58 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 59 type=in.readByte(); 60 arg=(PingRsp)in.readObject(); 61 } 62 63 public void writeTo(DataOutputStream outstream) throws IOException { 64 outstream.writeByte(type); 65 Util.writeStreamable(arg, outstream); 66 } 67 68 public void readFrom(DataInputStream instream) throws IOException, IllegalAccessException , InstantiationException { 69 type=instream.readByte(); 70 arg=(PingRsp)Util.readStreamable(PingRsp.class, instream); 71 } 72 } 73 | Popular Tags |