1 18 package org.apache.activemq.command; 19 20 25 public class ProducerId implements DataStructure { 26 27 public static final byte DATA_STRUCTURE_TYPE=CommandTypes.PRODUCER_ID; 28 29 protected String connectionId; 30 protected long sessionId; 31 protected long value; 32 33 protected transient int hashCode; 34 protected transient String key; 35 protected transient SessionId parentId; 36 37 public ProducerId() { 38 } 39 40 public ProducerId(SessionId sessionId, long producerId) { 41 this.connectionId = sessionId.getConnectionId(); 42 this.sessionId = sessionId.getValue(); 43 this.value=producerId; 44 } 45 46 public ProducerId(ProducerId id) { 47 this.connectionId = id.getConnectionId(); 48 this.sessionId = id.getSessionId(); 49 this.value=id.getValue(); 50 } 51 52 public ProducerId(String producerKey) { 53 int p = producerKey.lastIndexOf(":"); 55 if( p >= 0 ) { 56 value = Long.parseLong(producerKey.substring(p+1)); 57 producerKey = producerKey.substring(0,p); 58 } 59 setProducerSessionKey(producerKey); 60 } 61 62 public SessionId getParentId() { 63 if( parentId == null ) { 64 parentId = new SessionId(this); 65 } 66 return parentId; 67 } 68 69 public int hashCode() { 70 if( hashCode == 0 ) { 71 hashCode = connectionId.hashCode() ^ (int)sessionId ^ (int)value; 72 } 73 return hashCode; 74 } 75 76 public boolean equals(Object o) { 77 if( this == o ) 78 return true; 79 if( o == null || o.getClass()!=ProducerId.class ) 80 return false; 81 ProducerId id = (ProducerId) o; 82 return sessionId==id.sessionId 83 && value==id.value 84 && connectionId.equals(id.connectionId); 85 } 86 87 88 91 private void setProducerSessionKey(String sessionKey) { 92 int p = sessionKey.lastIndexOf(":"); 94 if( p >= 0 ) { 95 sessionId = Long.parseLong(sessionKey.substring(p+1)); 96 sessionKey = sessionKey.substring(0,p); 97 } 98 connectionId = sessionKey; 100 } 101 102 public String toString() { 103 if( key == null ) { 104 key=connectionId+":"+sessionId+":"+value; 105 } 106 return key; 107 } 108 109 public byte getDataStructureType() { 110 return DATA_STRUCTURE_TYPE; 111 } 112 115 public String getConnectionId() { 116 return connectionId; 117 } 118 public void setConnectionId(String connectionId) { 119 this.connectionId = connectionId; 120 } 121 124 public long getValue() { 125 return value; 126 } 127 public void setValue(long producerId) { 128 this.value = producerId; 129 } 130 131 134 public long getSessionId() { 135 return sessionId; 136 } 137 public void setSessionId(long sessionId) { 138 this.sessionId = sessionId; 139 } 140 141 public boolean isMarshallAware() { 142 return false; 143 } 144 } 145 | Popular Tags |