1 3 package org.jgroups.protocols; 4 5 6 import org.jgroups.Address; 7 import org.jgroups.Header; 8 import org.jgroups.ViewId; 9 10 import java.io.IOException ; 11 import java.io.ObjectInput ; 12 import java.io.ObjectOutput ; 13 import java.util.Vector ; 14 15 16 17 public class NakAckHeader extends Header { 18 public static final int NAK_MSG = 1; public static final int NAK_ACK_MSG = 2; public static final int WRAPPED_MSG = 3; public static final int RETRANSMIT_MSG = 4; public static final int NAK_ACK_RSP = 5; public static final int OUT_OF_BAND_MSG = 6; public static final int OUT_OF_BAND_RSP = 7; 26 int type=0; 27 long seqno=-1; long last_seqno=-1; ViewId vid=null; 30 31 Vector stable_msgs=null; 33 Address sender=null; 35 36 37 public NakAckHeader() {} 38 39 40 41 public NakAckHeader(int type, long seqno, ViewId vid) { 42 this.type=type; 43 this.seqno=seqno; 44 this.vid=vid; 45 } 46 47 48 public long size() { 49 return 512; 50 } 51 52 53 public void writeExternal(ObjectOutput out) throws IOException { 54 out.writeInt(type); 55 out.writeLong(seqno); 56 out.writeLong(last_seqno); 57 out.writeObject(vid); 58 out.writeObject(stable_msgs); 59 out.writeObject(sender); 60 } 61 62 63 64 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 65 type=in.readInt(); 66 seqno=in.readLong(); 67 last_seqno=in.readLong(); 68 vid=(ViewId)in.readObject(); 69 stable_msgs=(Vector )in.readObject(); 70 sender=(Address)in.readObject(); 71 } 72 73 74 public NakAckHeader copy() { 75 NakAckHeader ret=new NakAckHeader(type, seqno, vid); 76 ret.last_seqno=last_seqno; 77 ret.stable_msgs=stable_msgs != null ? (Vector )stable_msgs.clone() : null; 78 ret.sender=sender; 79 return ret; 80 } 81 82 83 public static String type2Str(int t) { 84 switch(t) { 85 case NAK_MSG: return "NAK_MSG"; 86 case NAK_ACK_MSG: return "NAK_ACK_MSG"; 87 case WRAPPED_MSG: return "WRAPPED_MSG"; 88 case RETRANSMIT_MSG: return "RETRANSMIT_MSG"; 89 case NAK_ACK_RSP: return "NAK_ACK_RSP"; 90 case OUT_OF_BAND_MSG: return "OUT_OF_BAND_MSG"; 91 case OUT_OF_BAND_RSP: return "OUT_OF_BAND_RSP"; 92 default: return "<undefined>"; 93 } 94 } 95 96 public String toString() { 97 StringBuffer ret=new StringBuffer (); 98 ret.append("[NAKACK: " + type2Str(type) + ", seqno=" + seqno + ", last_seqno=" + last_seqno + 99 ", vid=" + vid ); 100 if(type == WRAPPED_MSG) 101 ret.append(", sender=" + sender); 102 ret.append(']'); 103 104 return ret.toString(); 105 } 106 107 } 108 | Popular Tags |