Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/message/ConsumerInfo.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.message;
19  
20  import java.io.Serializable;
21  
22  /**
23   * Describes a Message consumer
24   *
25   * @version $Revision: 1.1.1.1 $
26   */
27  public class ConsumerInfo extends AbstractPacket implements Serializable{
28      static final long serialVersionUID = 3489666609L;
29      private ActiveMQDestination destination;
30      private String clientId;
31      private short sessionId;
32      private String consumerName;
33      private String selector;
34      private long startTime;
35      private boolean started;
36      private int consumerNo;
37      private boolean noLocal;
38      private boolean browser;
39      private int prefetchNumber = 100;
40      private transient String consumerKey;
41      private String consumerId;
42  
43      
44      
45      /**
46       * @return Returns the sessionId.
47       */
48      public short getSessionId() {
49          return sessionId;
50      }
51  
52      /**
53       * @param sessionId The sessionId to set.
54       */
55      public void setSessionId(short sessionId) {
56          this.sessionId = sessionId;
57      }
58  
59      /**
60       * Return the type of Packet
61       *
62       * @return integer representation of the type of Packet
63       */
64      public int getPacketType() {
65          return CONSUMER_INFO;
66      }
67  
68      /**
69       * Test for equality
70       *
71       * @param obj object to test
72       * @return true if equivalent
73       */
74      public boolean equals(Object obj) {
75          boolean result = false;
76          if (obj != null && obj instanceof ConsumerInfo) {
77              ConsumerInfo that = (ConsumerInfo) obj;
78              result = this.getConsumerId().equals(that.getConsumerId());
79          }
80          return result;
81      }
82  
83      /**
84       * @return hash code for instance
85       */
86      public int hashCode() {
87          return getConsumerId().hashCode();
88      }
89  
90      /**
91       * @return Returns the clientId.
92       */
93      public String getClientId() {
94          return this.clientId;
95      }
96  
97      /**
98       * @param newClientId The clientId to set.
99       */
100     public void setClientId(String newClientId) {
101         this.clientId = newClientId;
102     }
103 
104     /**
105      * @return Returns the destination.
106      */
107     public ActiveMQDestination getDestination() {
108         return this.destination;
109     }
110 
111     /**
112      * @param newDestination The destination to set.
113      */
114     public void setDestination(ActiveMQDestination newDestination) {
115         this.destination = newDestination;
116     }
117 
118     /**
119      * @return Returns the selector.
120      */
121     public String getSelector() {
122         return this.selector;
123     }
124 
125     /**
126      * @param newSelector The selector to set.
127      */
128     public void setSelector(String newSelector) {
129         this.selector = newSelector;
130     }
131 
132     /**
133      * @return Returns the started.
134      */
135     public boolean isStarted() {
136         return this.started;
137     }
138 
139     /**
140      * @param flag to indicate if started
141      */
142     public void setStarted(boolean flag) {
143         this.started = flag;
144     }
145 
146     /**
147      * @return Returns the startTime.
148      */
149     public long getStartTime() {
150         return this.startTime;
151     }
152 
153     /**
154      * @param newStartTime The startTime to set.
155      */
156     public void setStartTime(long newStartTime) {
157         this.startTime = newStartTime;
158     }
159 
160     /**
161      * @return Returns the consumerNo.
162      */
163     public int getConsumerNo() {
164         return this.consumerNo;
165     }
166 
167     /**
168      * @param newConsumerNo The consumerNo to set.
169      */
170     public void setConsumerNo(int newConsumerNo) {
171         this.consumerNo = newConsumerNo;
172     }
173 
174     /**
175      * @return Returns the consumer name.
176      */
177     public String getConsumerName() {
178         return this.consumerName;
179     }
180 
181     /**
182      * @param newconsumerName The consumerName to set.
183      */
184     public void setConsumerName(String newconsumerName) {
185         this.consumerName = newconsumerName;
186     }
187 
188     /**
189      * @return Returns true if the Consumer is a durable Topic subscriber
190      */
191     public boolean isDurableTopic() {
192         return this.destination.isTopic() && !this.destination.isTemporary() && this.consumerName != null
193                 && this.consumerName.length() > 0;
194     }
195 
196     /**
197      * @return Returns the noLocal.
198      */
199     public boolean isNoLocal() {
200         return noLocal;
201     }
202 
203     /**
204      * @param noLocal The noLocal to set.
205      */
206     public void setNoLocal(boolean noLocal) {
207         this.noLocal = noLocal;
208     }
209 
210     /**
211      * @return Returns the browser.
212      */
213     public boolean isBrowser() {
214         return browser;
215     }
216 
217     /**
218      * @param browser The browser to set.
219      */
220     public void setBrowser(boolean browser) {
221         this.browser = browser;
222     }
223 
224     /**
225      * @return Returns the prefetchNumber.
226      */
227     public int getPrefetchNumber() {
228         return prefetchNumber;
229     }
230 
231     /**
232      * @param prefetchNumber The prefetchNumber to set.
233      */
234     public void setPrefetchNumber(int prefetchNumber) {
235         this.prefetchNumber = prefetchNumber;
236     }
237 
238 
239     /**
240      * Creates a primary key for the consumer info which uniquely
241      * describes the consumer using a combination of clientID and
242      * consumerName
243      *
244      * @return the consumerKey
245      */
246     public String getConsumerKey() {
247         if (consumerKey == null){
248             consumerKey = generateConsumerKey(clientId,consumerName);
249         }
250         return consumerKey;
251     }
252     
253     /**
254      * @return Returns the consumerIdentifier.
255      */
256     public String getConsumerId() {
257         if (consumerId == null){
258             consumerId = clientId + "." + sessionId + "." + consumerNo;
259         }
260         return consumerId;
261     }
262     /**
263      * @param consumerIdentifier The consumerIdentifier to set.
264      */
265     public void setConsumerId(String consumerIdentifier) {
266         this.consumerId = consumerIdentifier;
267     }
268     
269     
270     /**
271      * Generate a primary key for a consumer from the clientId and consumerName
272      * @param clientId
273      * @param consumerName
274      * @return
275      */
276     public static String generateConsumerKey(String clientId, String consumerName){
277         return "[" + clientId + ":" + consumerName + "]";
278     }
279 
280     /**
281      * @return true if the consumer is interested in advisory messages
282      */
283     public boolean isAdvisory(){
284         return destination != null && destination.isAdvisory();
285     }
286     
287     /**
288      * @return a pretty print
289      */
290     public String toString() {
291         return super.toString() + " ConsumerInfo{ " +
292                 "browser = " + browser +
293                 ", destination = " + destination +
294                 ", consumerIdentifier = '" + getConsumerId() + "' " +
295                 ", clientId = '" + clientId + "' " +
296                 ", sessionId = '" + sessionId + "' " +
297                 ", consumerName = '" + consumerName + "' " +
298                 ", selector = '" + selector + "' " +
299                 ", startTime = " + startTime +
300                 ", started = " + started +
301                 ", consumerNo = " + consumerNo +
302                 ", noLocal = " + noLocal +
303                 ", prefetchNumber = " + prefetchNumber +
304                 ", consumerKey = '" + getConsumerKey() + "' " +
305                 " }";
306     }
307 }