1 18 package org.apache.activemq.command; 19 20 24 public class LocalTransactionId extends TransactionId implements Comparable <LocalTransactionId>{ 25 26 public static final byte DATA_STRUCTURE_TYPE=CommandTypes.ACTIVEMQ_LOCAL_TRANSACTION_ID; 27 28 protected ConnectionId connectionId; 29 protected long value; 30 31 private transient String transactionKey; 32 private transient int hashCode; 33 34 public LocalTransactionId() { 35 } 36 37 public LocalTransactionId(ConnectionId connectionId, long transactionId) { 38 this.connectionId=connectionId; 39 this.value=transactionId; 40 } 41 42 public byte getDataStructureType() { 43 return DATA_STRUCTURE_TYPE; 44 } 45 46 public boolean isXATransaction() { 47 return false; 48 } 49 50 public boolean isLocalTransaction() { 51 return true; 52 } 53 54 public String getTransactionKey() { 55 if( transactionKey==null ) { 56 transactionKey = "TX:"+connectionId+":"+value; 57 } 58 return transactionKey; 59 } 60 61 public String toString() { 62 return getTransactionKey(); 63 } 64 65 public int hashCode() { 66 if( hashCode == 0 ) { 67 hashCode = connectionId.hashCode() ^ (int)value; 68 } 69 return hashCode; 70 } 71 72 public boolean equals(Object o) { 73 if( this == o ) 74 return true; 75 if( o == null || o.getClass()!=LocalTransactionId.class ) 76 return false; 77 LocalTransactionId tx = (LocalTransactionId) o; 78 return value==tx.value 79 && connectionId.equals(tx.connectionId); 80 } 81 82 83 88 public int compareTo(LocalTransactionId o){ 89 int result = connectionId.compareTo(o.connectionId); 90 if (result==0) { 91 result = (int) (value - o.value); 92 } 93 return result; 94 } 95 98 public long getValue() { 99 return value; 100 } 101 public void setValue(long transactionId) { 102 this.value = transactionId; 103 } 104 105 108 public ConnectionId getConnectionId() { 109 return connectionId; 110 } 111 public void setConnectionId(ConnectionId connectionId) { 112 this.connectionId = connectionId; 113 } 114 115 116 117 118 } 119 | Popular Tags |