1 18 package org.apache.activemq.command; 19 20 25 public class SessionId implements DataStructure { 26 27 public static final byte DATA_STRUCTURE_TYPE=CommandTypes.SESSION_ID; 28 29 protected String connectionId; 30 protected long value; 31 32 protected transient int hashCode; 33 protected transient String key; 34 protected transient ConnectionId parentId; 35 36 public SessionId() { 37 } 38 39 public SessionId(ConnectionId connectionId, long sessionId) { 40 this.connectionId = connectionId.getValue(); 41 this.value=sessionId; 42 } 43 44 public SessionId(SessionId id) { 45 this.connectionId = id.getConnectionId(); 46 this.value=id.getValue(); 47 } 48 49 public SessionId(ProducerId id) { 50 this.connectionId = id.getConnectionId(); 51 this.value=id.getSessionId(); 52 } 53 54 public SessionId(ConsumerId id) { 55 this.connectionId = id.getConnectionId(); 56 this.value=id.getSessionId(); 57 } 58 59 public ConnectionId getParentId() { 60 if( parentId == null ) { 61 parentId = new ConnectionId(this); 62 } 63 return parentId; 64 } 65 66 public int hashCode() { 67 if( hashCode == 0 ) { 68 hashCode = connectionId.hashCode() ^ (int)value; 69 } 70 return hashCode; 71 } 72 73 public boolean equals(Object o) { 74 if( this == o ) 75 return true; 76 if( o == null || o.getClass()!=SessionId.class ) 77 return false; 78 SessionId id = (SessionId) o; 79 return value==id.value 80 && connectionId.equals(id.connectionId); 81 } 82 83 public byte getDataStructureType() { 84 return DATA_STRUCTURE_TYPE; 85 } 86 87 90 public String getConnectionId() { 91 return connectionId; 92 } 93 public void setConnectionId(String connectionId) { 94 this.connectionId = connectionId; 95 } 96 97 100 public long getValue() { 101 return value; 102 } 103 public void setValue(long sessionId) { 104 this.value = sessionId; 105 } 106 107 public String toString() { 108 if( key==null ) { 109 key = connectionId+":"+value; 110 } 111 return key; 112 } 113 114 public boolean isMarshallAware() { 115 return false; 116 } 117 } 118 | Popular Tags |