1 3 package org.jgroups.protocols.pbcast; 4 5 6 import org.jgroups.Header; 7 import org.jgroups.Global; 8 import org.jgroups.util.Range; 9 import org.jgroups.util.Streamable; 10 import org.jgroups.util.Util; 11 12 import java.io.*; 13 14 15 public class NakAckHeader extends Header implements Streamable { 16 public static final byte MSG=1; public static final byte XMIT_REQ=2; public static final byte XMIT_RSP=3; 20 21 byte type=0; 22 long seqno=-1; Range range=null; 25 26 public NakAckHeader() { 27 } 28 29 30 33 public NakAckHeader(byte type, long seqno) { 34 this.type=type; 35 this.seqno=seqno; 36 } 37 38 41 public NakAckHeader(byte type, long low, long high) { 42 this.type=type; 43 range=new Range(low, high); 44 } 45 46 47 public long size() { 48 int retval=Global.BYTE_SIZE + Global.LONG_SIZE + Global.BYTE_SIZE; 50 if(range != null) 51 retval+= (2 * Global.LONG_SIZE); return retval; 53 } 54 55 56 public void writeExternal(ObjectOutput out) throws IOException { 57 out.writeByte(type); 58 out.writeLong(seqno); 59 if(range != null) { 60 out.writeBoolean(true); range.writeExternal(out); 62 } 63 else 64 out.writeBoolean(false); 65 } 66 67 68 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 69 boolean read_range; 70 type=in.readByte(); 71 seqno=in.readLong(); 72 read_range=in.readBoolean(); 73 if(read_range) { 74 range=new Range(); 75 range.readExternal(in); 76 } 77 } 78 79 public void writeTo(DataOutputStream out) throws IOException { 80 out.writeByte(type); 81 out.writeLong(seqno); 82 Util.writeStreamable(range, out); 83 } 84 85 public void readFrom(DataInputStream in) throws IOException, IllegalAccessException , InstantiationException { 86 type=in.readByte(); 87 seqno=in.readLong(); 88 range=(Range)Util.readStreamable(Range.class, in); 89 } 90 91 92 public NakAckHeader copy() { 93 NakAckHeader ret=new NakAckHeader(type, seqno); 94 ret.range=range; 95 return ret; 96 } 97 98 99 public static String type2Str(byte t) { 100 switch(t) { 101 case MSG: 102 return "MSG"; 103 case XMIT_REQ: 104 return "XMIT_REQ"; 105 case XMIT_RSP: 106 return "XMIT_RSP"; 107 default: 108 return "<undefined>"; 109 } 110 } 111 112 113 public String toString() { 114 StringBuffer ret=new StringBuffer (); 115 ret.append("[NAKACK: ").append(type2Str(type)).append(", seqno=").append(seqno); 116 ret.append(", range=").append(range); 117 ret.append(']'); 118 return ret.toString(); 119 } 120 121 122 } 123 | Popular Tags |