1 18 package org.apache.activemq.command; 19 20 21 25 public class MessageId implements DataStructure, Comparable <MessageId> { 26 27 public static final byte DATA_STRUCTURE_TYPE=CommandTypes.MESSAGE_ID; 28 29 protected ProducerId producerId; 30 protected long producerSequenceId; 31 protected long brokerSequenceId; 32 33 transient private String key; 34 transient private int hashCode; 35 36 public MessageId() { 37 this.producerId = new ProducerId(); 38 } 39 40 public MessageId(ProducerInfo producerInfo, long producerSequenceId) { 41 this.producerId = producerInfo.getProducerId(); 42 this.producerSequenceId = producerSequenceId; 43 } 44 45 public MessageId(String messageKey) { 46 setValue(messageKey); 47 } 48 49 public MessageId(String producerId, long producerSequenceId) { 50 this( new ProducerId(producerId), producerSequenceId); 51 } 52 53 public MessageId(ProducerId producerId, long producerSequenceId) { 54 this.producerId=producerId; 55 this.producerSequenceId = producerSequenceId; 56 } 57 58 61 public void setValue(String messageKey) { 62 key = messageKey; 63 int p = messageKey.lastIndexOf(":"); 65 if( p >= 0 ) { 66 producerSequenceId = Long.parseLong(messageKey.substring(p+1)); 67 messageKey = messageKey.substring(0,p); 68 } 69 producerId = new ProducerId(messageKey); 70 } 71 72 77 public void setTextView(String key) { 78 this.key = key; 79 } 80 81 public byte getDataStructureType() { 82 return DATA_STRUCTURE_TYPE; 83 } 84 85 public boolean equals(Object o) { 86 if( this == o ) 87 return true; 88 if( o==null || o.getClass() != getClass() ) 89 return false; 90 91 MessageId id = (MessageId) o; 92 return producerSequenceId==id.producerSequenceId && producerId.equals(id.producerId); 93 } 94 95 public int hashCode() { 96 if( hashCode == 0 ) { 97 hashCode = producerId.hashCode() ^ (int)producerSequenceId; 98 } 99 return hashCode; 100 } 101 102 public String toString() { 103 if(key==null) { 104 key = producerId.toString()+":"+producerSequenceId; 105 } 106 return key; 107 } 108 109 112 public ProducerId getProducerId() { 113 return producerId; 114 } 115 public void setProducerId(ProducerId producerId) { 116 this.producerId = producerId; 117 } 118 119 122 public long getProducerSequenceId() { 123 return producerSequenceId; 124 } 125 public void setProducerSequenceId(long producerSequenceId) { 126 this.producerSequenceId = producerSequenceId; 127 } 128 129 132 public long getBrokerSequenceId() { 133 return brokerSequenceId; 134 } 135 public void setBrokerSequenceId(long brokerSequenceId) { 136 this.brokerSequenceId = brokerSequenceId; 137 } 138 139 public boolean isMarshallAware() { 140 return false; 141 } 142 143 public MessageId copy(){ 144 MessageId copy = new MessageId(producerId, producerSequenceId); 145 copy.key = key; 146 copy.brokerSequenceId = brokerSequenceId ; 147 return copy; 148 } 149 150 155 public int compareTo(MessageId other){ 156 int result = -1; 157 if (other != null) { 158 result = this.toString().compareTo(other.toString()); 159 } 160 return result; 161 } 162 } 163 | Popular Tags |