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 * @openwire:marshaller code="122"
021 * 
022 */
023public class ConsumerId implements DataStructure {
024
025    public static final byte DATA_STRUCTURE_TYPE = CommandTypes.CONSUMER_ID;
026
027    protected String connectionId;
028    protected long sessionId;
029    protected long value;
030
031    protected transient int hashCode;
032    protected transient String key;
033    protected transient SessionId parentId;
034
035    public ConsumerId() {
036    }
037
038    public ConsumerId(SessionId sessionId, long consumerId) {
039        this.connectionId = sessionId.getConnectionId();
040        this.sessionId = sessionId.getValue();
041        this.value = consumerId;
042    }
043
044    public ConsumerId(ConsumerId id) {
045        this.connectionId = id.getConnectionId();
046        this.sessionId = id.getSessionId();
047        this.value = id.getValue();
048    }
049
050    public SessionId getParentId() {
051        if (parentId == null) {
052            parentId = new SessionId(this);
053        }
054        return parentId;
055    }
056
057    public int hashCode() {
058        if (hashCode == 0) {
059            hashCode = connectionId.hashCode() ^ (int)sessionId ^ (int)value;
060        }
061        return hashCode;
062    }
063
064    public boolean equals(Object o) {
065        if (this == o) {
066            return true;
067        }
068        if (o == null || o.getClass() != ConsumerId.class) {
069            return false;
070        }
071        ConsumerId id = (ConsumerId)o;
072        return sessionId == id.sessionId && value == id.value && connectionId.equals(id.connectionId);
073    }
074
075    public byte getDataStructureType() {
076        return DATA_STRUCTURE_TYPE;
077    }
078
079    public String toString() {
080        if (key == null) {
081            key = connectionId + ":" + sessionId + ":" + value;
082        }
083        return key;
084    }
085
086    /**
087     * @openwire:property version=1
088     */
089    public String getConnectionId() {
090        return connectionId;
091    }
092
093    public void setConnectionId(String connectionId) {
094        this.connectionId = connectionId;
095    }
096
097    /**
098     * @openwire:property version=1
099     */
100    public long getSessionId() {
101        return sessionId;
102    }
103
104    public void setSessionId(long sessionId) {
105        this.sessionId = sessionId;
106    }
107
108    /**
109     * @openwire:property version=1
110     */
111    public long getValue() {
112        return value;
113    }
114
115    public void setValue(long consumerId) {
116        this.value = consumerId;
117    }
118
119    public boolean isMarshallAware() {
120        return false;
121    }
122}