KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @openwire:marshaller code="121"
23  * @version $Revision$
24  */

25 public class SessionId implements DataStructure {
26
27     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.SESSION_ID;
28
29     protected String JavaDoc connectionId;
30     protected long value;
31     
32     protected transient int hashCode;
33     protected transient String JavaDoc 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 JavaDoc 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     /**
88      * @openwire:property version=1 cache=true
89      */

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

100     public long getValue() {
101         return value;
102     }
103     public void setValue(long sessionId) {
104         this.value = sessionId;
105     }
106     
107     public String JavaDoc 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