001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.command; 018 019/** 020 * 021 * @openwire:marshaller code="121" 022 * 023 */ 024public class SessionId implements DataStructure { 025 026 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.SESSION_ID; 027 028 protected String connectionId; 029 protected long value; 030 031 protected transient int hashCode; 032 protected transient String key; 033 protected transient ConnectionId parentId; 034 035 public SessionId() { 036 } 037 038 public SessionId(ConnectionId connectionId, long sessionId) { 039 this.connectionId = connectionId.getValue(); 040 this.value = sessionId; 041 } 042 043 public SessionId(SessionId id) { 044 this.connectionId = id.getConnectionId(); 045 this.value = id.getValue(); 046 } 047 048 public SessionId(ProducerId id) { 049 this.connectionId = id.getConnectionId(); 050 this.value = id.getSessionId(); 051 } 052 053 public SessionId(ConsumerId id) { 054 this.connectionId = id.getConnectionId(); 055 this.value = id.getSessionId(); 056 } 057 058 public ConnectionId getParentId() { 059 if (parentId == null) { 060 parentId = new ConnectionId(this); 061 } 062 return parentId; 063 } 064 065 public int hashCode() { 066 if (hashCode == 0) { 067 hashCode = connectionId.hashCode() ^ (int)value; 068 } 069 return hashCode; 070 } 071 072 public boolean equals(Object o) { 073 if (this == o) { 074 return true; 075 } 076 if (o == null || o.getClass() != SessionId.class) { 077 return false; 078 } 079 SessionId id = (SessionId)o; 080 return value == id.value && connectionId.equals(id.connectionId); 081 } 082 083 public byte getDataStructureType() { 084 return DATA_STRUCTURE_TYPE; 085 } 086 087 /** 088 * @openwire:property version=1 cache=true 089 */ 090 public String getConnectionId() { 091 return connectionId; 092 } 093 094 public void setConnectionId(String connectionId) { 095 this.connectionId = connectionId; 096 } 097 098 /** 099 * @openwire:property version=1 100 */ 101 public long getValue() { 102 return value; 103 } 104 105 public void setValue(long sessionId) { 106 this.value = sessionId; 107 } 108 109 public String toString() { 110 if (key == null) { 111 key = connectionId + ":" + value; 112 } 113 return key; 114 } 115 116 public boolean isMarshallAware() { 117 return false; 118 } 119}