01: // $Id: PingHeader.java,v 1.10 2005/04/26 15:22:13 belaban Exp $
02:
03: package org.jgroups.protocols;
04:
05: import org.jgroups.Header;
06: import org.jgroups.Global;
07: import org.jgroups.util.Streamable;
08: import org.jgroups.util.Util;
09:
10: import java.io.*;
11:
12: public class PingHeader extends Header implements Streamable {
13: public static final byte GET_MBRS_REQ = 1; // arg = null
14: public static final byte GET_MBRS_RSP = 2; // arg = PingRsp(local_addr, coord_addr)
15:
16: public byte type = 0;
17: public PingRsp arg = null;
18:
19: public PingHeader() {
20: } // for externalization
21:
22: public PingHeader(byte type, PingRsp arg) {
23: this .type = type;
24: this .arg = arg;
25: }
26:
27: public long size() {
28: long retval = Global.BYTE_SIZE * 2; // type and presence
29: if (arg != null) {
30: retval += arg.size();
31: }
32: return retval;
33: }
34:
35: public String toString() {
36: return "[PING: type=" + type2Str(type) + ", arg=" + arg + ']';
37: }
38:
39: String type2Str(byte t) {
40: switch (t) {
41: case GET_MBRS_REQ:
42: return "GET_MBRS_REQ";
43: case GET_MBRS_RSP:
44: return "GET_MBRS_RSP";
45: default:
46: return "<unkown type (" + t + ")>";
47: }
48: }
49:
50: public void writeExternal(ObjectOutput out) throws IOException {
51: out.writeByte(type);
52: out.writeObject(arg);
53: }
54:
55: public void readExternal(ObjectInput in) throws IOException,
56: ClassNotFoundException {
57: type = in.readByte();
58: arg = (PingRsp) in.readObject();
59: }
60:
61: public void writeTo(DataOutputStream outstream) throws IOException {
62: outstream.writeByte(type);
63: Util.writeStreamable(arg, outstream);
64: }
65:
66: public void readFrom(DataInputStream instream) throws IOException,
67: IllegalAccessException, InstantiationException {
68: type = instream.readByte();
69: arg = (PingRsp) Util.readStreamable(PingRsp.class, instream);
70: }
71: }
|