KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > command > ConsumerId


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.command;
19
20
21 /**
22  *
23  * @openwire:marshaller code="122"
24  * @version $Revision$
25  */

26 public class ConsumerId implements DataStructure {
27     
28     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.CONSUMER_ID;
29     
30     protected String JavaDoc connectionId;
31     protected long sessionId;
32     protected long value;
33
34     protected transient int hashCode;
35     protected transient String JavaDoc key;
36     protected transient SessionId parentId;
37     
38     public ConsumerId() {
39     }
40     
41     public ConsumerId(SessionId sessionId, long consumerId) {
42         this.connectionId = sessionId.getConnectionId();
43         this.sessionId = sessionId.getValue();
44         this.value=consumerId;
45     }
46     
47     public ConsumerId(ConsumerId id) {
48         this.connectionId = id.getConnectionId();
49         this.sessionId = id.getSessionId();
50         this.value=id.getValue();
51     }
52     
53     public SessionId getParentId() {
54         if( parentId == null ) {
55             parentId = new SessionId(this);
56         }
57         return parentId;
58     }
59
60     public int hashCode() {
61         if( hashCode == 0 ) {
62             hashCode = connectionId.hashCode() ^ (int)sessionId ^ (int)value;
63         }
64         return hashCode;
65     }
66     
67     public boolean equals(Object JavaDoc o) {
68         if( this == o )
69             return true;
70         if( o == null || o.getClass()!=ConsumerId.class )
71             return false;
72         ConsumerId id = (ConsumerId) o;
73         return sessionId==id.sessionId
74                && value==id.value
75                && connectionId.equals(id.connectionId);
76     }
77     
78     public byte getDataStructureType() {
79         return DATA_STRUCTURE_TYPE;
80     }
81
82     public String JavaDoc toString() {
83         if( key==null ) {
84             key = connectionId+":"+sessionId+":"+value;
85         }
86         return key;
87     }
88
89     /**
90      * @openwire:property version=1
91      */

92     public String JavaDoc getConnectionId() {
93         return connectionId;
94     }
95     public void setConnectionId(String JavaDoc connectionId) {
96         this.connectionId = connectionId;
97     }
98     
99     /**
100      * @openwire:property version=1
101      */

102     public long getSessionId() {
103         return sessionId;
104     }
105     public void setSessionId(long sessionId) {
106         this.sessionId = sessionId;
107     }
108     
109
110     /**
111      * @openwire:property version=1
112      */

113     public long getValue() {
114         return value;
115     }
116     public void setValue(long consumerId) {
117         this.value = consumerId;
118     }
119
120     public boolean isMarshallAware() {
121         return false;
122     }
123 }
124
Popular Tags