KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.activemq.filter.BooleanExpression;
21 import org.apache.activemq.state.CommandVisitor;
22
23
24 /**
25  *
26  * @openwire:marshaller code="5"
27  * @version $Revision: 1.20 $
28  */

29 public class ConsumerInfo extends BaseCommand {
30     
31     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.CONSUMER_INFO;
32     
33     public static final byte HIGH_PRIORITY = 10;
34     public static final byte NORMAL_PRIORITY = 0;
35     public static final byte NETWORK_CONSUMER_PRIORITY = -5;
36     public static final byte LOW_PRIORITY = -10;
37     
38     
39     protected ConsumerId consumerId;
40     protected ActiveMQDestination destination;
41     protected int prefetchSize;
42     protected int maximumPendingMessageLimit;
43     protected boolean browser;
44     protected boolean dispatchAsync;
45     protected String JavaDoc selector;
46     protected String JavaDoc subscriptionName;
47     protected boolean noLocal;
48     protected boolean exclusive;
49     protected boolean retroactive;
50     protected byte priority;
51     protected BrokerId[] brokerPath;
52     protected boolean optimizedAcknowledge;
53     protected transient int currentPrefetchSize;//used by the broker
54
protected boolean noRangeAcks; // if true, the consumer will not send range acks.
55

56     protected BooleanExpression additionalPredicate;
57     protected transient boolean networkSubscription; //this subscription originated from a network connection
58

59     public ConsumerInfo() {
60     }
61     
62     public ConsumerInfo(ConsumerId consumerId) {
63         this.consumerId=consumerId;
64     }
65     
66     public ConsumerInfo(SessionInfo sessionInfo, long consumerId) {
67         this.consumerId = new ConsumerId(sessionInfo.getSessionId(), consumerId);
68     }
69
70     public ConsumerInfo copy() {
71         ConsumerInfo info = new ConsumerInfo();
72         copy(info);
73         return info;
74     }
75
76     public void copy(ConsumerInfo info) {
77         super.copy(info);
78         info.consumerId = consumerId;
79         info.destination = destination;
80         info.prefetchSize = prefetchSize;
81         info.maximumPendingMessageLimit = maximumPendingMessageLimit;
82         info.browser = browser;
83         info.dispatchAsync = dispatchAsync;
84         info.selector = selector;
85         info.subscriptionName=subscriptionName;
86         info.noLocal = noLocal;
87         info.exclusive = exclusive;
88         info.retroactive = retroactive;
89         info.priority = priority;
90         info.brokerPath=brokerPath;
91     }
92     
93     public boolean isDurable() {
94         return subscriptionName!=null;
95     }
96  
97     public byte getDataStructureType() {
98         return DATA_STRUCTURE_TYPE;
99     }
100     
101     /**
102      * Is used to uniquely identify the consumer to the broker.
103      *
104      * @openwire:property version=1 cache=true
105      */

106     public ConsumerId getConsumerId() {
107         return consumerId;
108     }
109     public void setConsumerId(ConsumerId consumerId) {
110         this.consumerId = consumerId;
111     }
112
113     /**
114      * Is this consumer a queue browser?
115      *
116      * @openwire:property version=1
117      */

118     public boolean isBrowser() {
119         return browser;
120     }
121     public void setBrowser(boolean browser) {
122         this.browser = browser;
123     }
124        
125     /**
126      * The destination that the consumer is interested in receiving messages from.
127      * This destination could be a composite destination.
128      *
129      * @openwire:property version=1 cache=true
130      */

131     public ActiveMQDestination getDestination() {
132         return destination;
133     }
134     public void setDestination(ActiveMQDestination destination) {
135         this.destination = destination;
136     }
137     
138     /**
139      * How many messages a broker will send to the client without receiving an ack before
140      * he stops dispatching messages to the client.
141      *
142      * @openwire:property version=1
143      */

144     public int getPrefetchSize() {
145         return prefetchSize;
146     }
147
148     public void setPrefetchSize(int prefetchSize) {
149         this.prefetchSize = prefetchSize;
150         this.currentPrefetchSize = prefetchSize;
151     }
152
153     /**
154      * How many messages a broker will keep around, above the prefetch limit, for non-durable
155      * topics before starting to discard older messages.
156      *
157      * @openwire:property version=1
158      */

159     public int getMaximumPendingMessageLimit() {
160         return maximumPendingMessageLimit;
161     }
162
163     public void setMaximumPendingMessageLimit(int maximumPendingMessageLimit) {
164         this.maximumPendingMessageLimit = maximumPendingMessageLimit;
165     }
166
167     /**
168      * Should the broker dispatch a message to the consumer async? If he does it async, then
169      * he uses a more SEDA style of processing while if it is not done async, then he broker
170      * use a STP style of processing. STP is more appropriate in high bandwidth situations or when
171      * being used by and in vm transport.
172      *
173      * @openwire:property version=1
174      */

175     public boolean isDispatchAsync() {
176         return dispatchAsync;
177     }
178     public void setDispatchAsync(boolean dispatchAsync) {
179         this.dispatchAsync = dispatchAsync;
180     }
181
182     /**
183      * The JMS selector used to filter out messages that this consumer
184      * is interested in.
185      *
186      * @openwire:property version=1
187      */

188     public String JavaDoc getSelector() {
189         return selector;
190     }
191     public void setSelector(String JavaDoc selector) {
192         this.selector = selector;
193     }
194
195     /**
196      * Used to identify the name of a durable subscription.
197      *
198      * @openwire:property version=1
199      */

200     public String JavaDoc getSubscriptionName() {
201         return subscriptionName;
202     }
203     public void setSubscriptionName(String JavaDoc durableSubscriptionId) {
204         this.subscriptionName = durableSubscriptionId;
205     }
206     
207     /**
208      * @deprecated
209      * @return @see getSubscriptionName
210      */

211     public String JavaDoc getSubcriptionName() {
212         return subscriptionName;
213     }
214     
215     /**
216      * @deprecated
217      * @see setSubscriptionName
218      * @param durableSubscriptionId
219      */

220     public void setSubcriptionName(String JavaDoc durableSubscriptionId) {
221         this.subscriptionName = durableSubscriptionId;
222     }
223     
224     /**
225      * Set noLocal to true to avoid receiving messages that were published locally on the same connection.
226      *
227      * @openwire:property version=1
228      */

229     public boolean isNoLocal() {
230         return noLocal;
231     }
232     public void setNoLocal(boolean noLocal) {
233         this.noLocal = noLocal;
234     }
235
236     /**
237      * An exclusive consumer locks out other consumers from being able to receive messages
238      * from the destination. If there are multiple exclusive consumers for a destination, the first one
239      * created will be the exclusive consumer of the destination.
240      *
241      * @openwire:property version=1
242      */

243     public boolean isExclusive() {
244         return exclusive;
245     }
246     public void setExclusive(boolean exclusive) {
247         this.exclusive = exclusive;
248     }
249
250     /**
251      * A retroactive consumer only has meaning for Topics. It allows a consumer
252      * to retroactively see messages sent prior to the consumer being created. If the
253      * consumer is not durable, it will be delivered the last message published to the topic.
254      * If the consumer is durable then it will receive all persistent messages that are
255      * still stored in persistent storage for that topic.
256      *
257      * @openwire:property version=1
258      */

259     public boolean isRetroactive() {
260         return retroactive;
261     }
262     public void setRetroactive(boolean retroactive) {
263         this.retroactive = retroactive;
264     }
265
266     public RemoveInfo createRemoveCommand() {
267         RemoveInfo command = new RemoveInfo(getConsumerId());
268         command.setResponseRequired(isResponseRequired());
269         return command;
270     }
271
272     /**
273      * The broker will avoid dispatching to a lower priority consumer if there are other higher priority
274      * consumers available to dispatch to. This allows letting the broker to have an affinity to
275      * higher priority consumers. Default priority is 0.
276      *
277      * @openwire:property version=1
278      */

279     public byte getPriority() {
280         return priority;
281     }
282     public void setPriority(byte priority) {
283         this.priority = priority;
284     }
285
286     /**
287      * The route of brokers the command has moved through.
288      *
289      * @openwire:property version=1 cache=true
290      */

291     public BrokerId[] getBrokerPath() {
292         return brokerPath;
293     }
294     public void setBrokerPath(BrokerId[] brokerPath) {
295         this.brokerPath = brokerPath;
296     }
297
298     /**
299      * A transient additional predicate that can be used it inject additional predicates
300      * into the selector on the fly. Handy if if say a Security Broker interceptor wants to
301      * filter out messages based on security level of the consumer.
302      *
303      * @openwire:property version=1
304      */

305     public BooleanExpression getAdditionalPredicate() {
306         return additionalPredicate;
307     }
308     public void setAdditionalPredicate(BooleanExpression additionalPredicate) {
309         this.additionalPredicate = additionalPredicate;
310     }
311
312     public Response visit(CommandVisitor visitor) throws Exception JavaDoc {
313         return visitor.processAddConsumer( this );
314     }
315
316     /**
317      * @openwire:property version=1
318      * @return Returns the networkSubscription.
319      */

320     public boolean isNetworkSubscription(){
321         return networkSubscription;
322     }
323
324     /**
325      * @param networkSubscription The networkSubscription to set.
326      */

327     public void setNetworkSubscription(boolean networkSubscription){
328         this.networkSubscription=networkSubscription;
329     }
330
331     /**
332      * @openwire:property version=1
333      * @return Returns the optimizedAcknowledge.
334      */

335     public boolean isOptimizedAcknowledge(){
336         return optimizedAcknowledge;
337     }
338
339     /**
340      * @param optimizedAcknowledge The optimizedAcknowledge to set.
341      */

342     public void setOptimizedAcknowledge(boolean optimizedAcknowledge){
343         this.optimizedAcknowledge=optimizedAcknowledge;
344     }
345
346     /**
347      * @return Returns the currentPrefetchSize.
348      */

349     public int getCurrentPrefetchSize(){
350         return currentPrefetchSize;
351     }
352
353     /**
354      * @param currentPrefetchSize The currentPrefetchSize to set.
355      */

356     public void setCurrentPrefetchSize(int currentPrefetchSize){
357         this.currentPrefetchSize=currentPrefetchSize;
358     }
359
360     /**
361      * The broker may be able to optimize it's processing or provides better
362      * QOS if it knows the consumer will not be sending ranged acks.
363      *
364      * @return true if the consumer will not send range acks.
365      * @openwire:property version=1
366      */

367     public boolean isNoRangeAcks() {
368         return noRangeAcks;
369     }
370
371     public void setNoRangeAcks(boolean noRangeAcks) {
372         this.noRangeAcks = noRangeAcks;
373     }
374
375 }
376
Popular Tags