KickJava   Java API By Example, From Geeks To Geeks.

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


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="123"
23  * @version $Revision$
24  */

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

91     private void setProducerSessionKey(String JavaDoc sessionKey) {
92         // Parse off the value
93
int p = sessionKey.lastIndexOf(":");
94         if( p >= 0 ) {
95             sessionId = Long.parseLong(sessionKey.substring(p+1));
96             sessionKey = sessionKey.substring(0,p);
97         }
98         // The rest is the value
99
connectionId = sessionKey;
100     }
101
102     public String JavaDoc toString() {
103         if( key == null ) {
104             key=connectionId+":"+sessionId+":"+value;
105         }
106         return key;
107     }
108
109     public byte getDataStructureType() {
110         return DATA_STRUCTURE_TYPE;
111     }
112     /**
113      * @openwire:property version=1 cache=true
114      */

115     public String JavaDoc getConnectionId() {
116         return connectionId;
117     }
118     public void setConnectionId(String JavaDoc connectionId) {
119         this.connectionId = connectionId;
120     }
121     /**
122      * @openwire:property version=1
123      */

124     public long getValue() {
125         return value;
126     }
127     public void setValue(long producerId) {
128         this.value = producerId;
129     }
130     
131     /**
132      * @openwire:property version=1
133      */

134     public long getSessionId() {
135         return sessionId;
136     }
137     public void setSessionId(long sessionId) {
138         this.sessionId = sessionId;
139     }
140
141     public boolean isMarshallAware() {
142         return false;
143     }
144 }
145
Popular Tags