1 package com.ubermq.jms.common.datagram.impl; 2 3 4 import com.ubermq.jms.common.datagram.*; 5 import com.ubermq.kernel.*; 6 import java.nio.*; 7 8 11 public class AckDatagram 12 extends AbstractDatagram 13 implements IAckDatagram 14 { 15 private MessageId msgId; 16 private boolean nack; 17 18 23 AckDatagram(boolean nack) 24 { 25 super(DatagramFactory.DGRAM_ACK, 0); 26 this.msgId = null; 27 this.nack = nack; 28 } 29 30 35 AckDatagram(MessageId msgId, boolean nack) 36 { 37 super(DatagramFactory.DGRAM_ACK, 0); 38 this.msgId = msgId; 39 this.nack = nack; 40 } 41 42 45 public AckDatagram() 46 { 47 super(DatagramFactory.DGRAM_ACK, 0); 48 } 49 50 public MessageId getAckMessageId() {return msgId;} 52 public boolean isNegativeAck() {return nack;} 53 54 55 66 public void incoming(java.nio.ByteBuffer bb) 67 throws java.io.IOException 68 { 69 super.incoming(bb); 70 setDatagramProps(DatagramFactory.DGRAM_ACK, 0); 71 72 nack = (bb.get() != 0); 73 if (bb.remaining() > 0) { 74 msgId = new MessageId(bb.getLong(), bb.getInt()); 75 } else { 76 msgId = null; 77 } 78 } 79 80 83 public void outgoing(java.nio.ByteBuffer bb) 84 { 85 super.outgoing(bb); 86 87 bb.put(nack ? (byte)0x1 : (byte)0x0); 88 if (msgId != null) { 89 bb.putLong(msgId.getSenderId()); 90 bb.putInt(msgId.getSequence()); 91 } 92 } 93 94 public String toString() 95 { 96 return super.toString() + 97 "\nMsgID:\t\t" + msgId + 98 "\nnack:\t\t" + nack; 99 } 100 101 public boolean equals(Object o) 102 { 103 if (o instanceof IAckDatagram) { 104 IAckDatagram ad = (IAckDatagram)o; 105 106 return ( ((ad.getAckMessageId() == null && getAckMessageId() == null) || 107 ad.getAckMessageId().equals(getAckMessageId())) && 108 ad.isNegativeAck() == isNegativeAck()); 109 } else { 110 return false; 111 } 112 } 113 114 public int hashCode() { 115 int result = 17; 116 result = 37*result + getAckMessageId().hashCode(); 117 result = 37*result + (isNegativeAck() ? 0 : 1); 118 return result; 119 } 120 } 121 122 | Popular Tags |