View Javadoc

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.codehaus.activemq.message;
19  
20  /***
21   * Describes a Message consumer
22   *
23   * @version $Revision: 1.9 $
24   */
25  public class ConsumerInfo extends AbstractPacket {
26      private ActiveMQDestination destination;
27      private String consumerId;
28      private String clientId;
29      private String sessionId;
30      private String consumerName;
31      private String selector;
32      private long startTime;
33      private boolean started;
34      private int consumerNo;
35      private boolean noLocal;
36      private boolean browser;
37      private int prefetchNumber = 100;
38      private transient String consumerKey;
39  
40      /***
41       * @return Returns the consumerId.
42       */
43      public String getConsumerId() {
44          return consumerId;
45      }
46  
47      /***
48       * @param consumerId The consumerId to set.
49       */
50      public void setConsumerId(String consumerId) {
51          this.consumerId = consumerId;
52      }
53  
54      /***
55       * @return Returns the sessionId.
56       */
57      public String getSessionId() {
58          return sessionId;
59      }
60  
61      /***
62       * @param sessionId The sessionId to set.
63       */
64      public void setSessionId(String sessionId) {
65          this.sessionId = sessionId;
66      }
67  
68      /***
69       * Return the type of Packet
70       *
71       * @return integer representation of the type of Packet
72       */
73      public int getPacketType() {
74          return CONSUMER_INFO;
75      }
76  
77      /***
78       * Test for equality
79       *
80       * @param obj object to test
81       * @return true if equivalent
82       */
83      public boolean equals(Object obj) {
84          boolean result = false;
85          if (obj != null && obj instanceof ConsumerInfo) {
86              ConsumerInfo that = (ConsumerInfo) obj;
87              result = this.consumerId.equals(that.consumerId);
88          }
89          return result;
90      }
91  
92      /***
93       * @return hash code for instance
94       */
95      public int hashCode() {
96          return this.consumerId.hashCode();
97      }
98  
99      /***
100      * @return a pretty print
101      */
102 
103     public String toString() {
104         return super.toString() + " consumerId: " + consumerId + " clientId: " + clientId + " consumerName: " + consumerName + " destination: " + destination;
105     }
106 
107     /***
108      * @return Returns the clientId.
109      */
110     public String getClientId() {
111         return this.clientId;
112     }
113 
114     /***
115      * @param newClientId The clientId to set.
116      */
117     public void setClientId(String newClientId) {
118         this.clientId = newClientId;
119     }
120 
121     /***
122      * @return Returns the destination.
123      */
124     public ActiveMQDestination getDestination() {
125         return this.destination;
126     }
127 
128     /***
129      * @param newDestination The destination to set.
130      */
131     public void setDestination(ActiveMQDestination newDestination) {
132         this.destination = newDestination;
133     }
134 
135     /***
136      * @return Returns the selector.
137      */
138     public String getSelector() {
139         return this.selector;
140     }
141 
142     /***
143      * @param newSelector The selector to set.
144      */
145     public void setSelector(String newSelector) {
146         this.selector = newSelector;
147     }
148 
149     /***
150      * @return Returns the started.
151      */
152     public boolean isStarted() {
153         return this.started;
154     }
155 
156     /***
157      * @param flag to indicate if started
158      */
159     public void setStarted(boolean flag) {
160         this.started = flag;
161     }
162 
163     /***
164      * @return Returns the startTime.
165      */
166     public long getStartTime() {
167         return this.startTime;
168     }
169 
170     /***
171      * @param newStartTime The startTime to set.
172      */
173     public void setStartTime(long newStartTime) {
174         this.startTime = newStartTime;
175     }
176 
177     /***
178      * @return Returns the consumerNo.
179      */
180     public int getConsumerNo() {
181         return this.consumerNo;
182     }
183 
184     /***
185      * @param newConsumerNo The consumerNo to set.
186      */
187     public void setConsumerNo(int newConsumerNo) {
188         this.consumerNo = newConsumerNo;
189     }
190 
191     /***
192      * @return Returns the consumer name.
193      */
194     public String getConsumerName() {
195         return this.consumerName;
196     }
197 
198     /***
199      * @param newconsumerName The consumerName to set.
200      */
201     public void setConsumerName(String newconsumerName) {
202         this.consumerName = newconsumerName;
203     }
204 
205     /***
206      * @return Returns true if the Consumer is a durable Topic subscriber
207      */
208     public boolean isDurableTopic() {
209         return this.destination.isTopic() && !this.destination.isTemporary() && this.consumerName != null
210                 && this.consumerName.length() > 0;
211     }
212 
213     /***
214      * @return Returns the noLocal.
215      */
216     public boolean isNoLocal() {
217         return noLocal;
218     }
219 
220     /***
221      * @param noLocal The noLocal to set.
222      */
223     public void setNoLocal(boolean noLocal) {
224         this.noLocal = noLocal;
225     }
226 
227     /***
228      * @return Returns the browser.
229      */
230     public boolean isBrowser() {
231         return browser;
232     }
233 
234     /***
235      * @param browser The browser to set.
236      */
237     public void setBrowser(boolean browser) {
238         this.browser = browser;
239     }
240 
241     /***
242      * @return Returns the prefetchNumber.
243      */
244     public int getPrefetchNumber() {
245         return prefetchNumber;
246     }
247 
248     /***
249      * @param prefetchNumber The prefetchNumber to set.
250      */
251     public void setPrefetchNumber(int prefetchNumber) {
252         this.prefetchNumber = prefetchNumber;
253     }
254 
255 
256     /***
257      * Creates a primary key for the consumer info which uniquely
258      * describes the consumer using a combination of clientID and
259      * consumerName
260      *
261      * @return the consumerKey
262      */
263     public String getConsumerKey() {
264         if (consumerKey == null){
265             consumerKey = generateConsumerKey(clientId,consumerName);
266         }
267         return consumerKey;
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 }