KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > jmx > SubscriptionView


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.broker.jmx;
19
20 import org.apache.activemq.broker.region.Subscription;
21 import org.apache.activemq.command.ActiveMQDestination;
22 import org.apache.activemq.command.ConsumerInfo;
23
24 import javax.jms.InvalidSelectorException JavaDoc;
25
26
27
28 /**
29  * @version $Revision: 1.5 $
30  */

31 public class SubscriptionView implements SubscriptionViewMBean {
32     
33     
34     protected final Subscription subscription;
35     protected final String JavaDoc clientId;
36     
37     
38     /**
39      * Constructor
40      * @param subs
41      */

42     public SubscriptionView(String JavaDoc clientId,Subscription subs){
43         this.clientId = clientId;
44         this.subscription = subs;
45     }
46     
47     /**
48      * @return the clientId
49      */

50     public String JavaDoc getClientId(){
51         return clientId;
52     }
53     
54     /**
55      * @return the id of the Connection the Subscription is on
56      */

57     public String JavaDoc getConnectionId(){
58         ConsumerInfo info = getConsumerInfo();
59         if (info != null){
60             return info.getConsumerId().getConnectionId();
61         }
62         return "NOTSET";
63     }
64
65     /**
66      * @return the id of the Session the subscription is on
67      */

68     public long getSessionId(){
69         ConsumerInfo info = getConsumerInfo();
70         if (info != null){
71             return info.getConsumerId().getSessionId();
72         }
73         return 0;
74     }
75
76     /**
77      * @return the id of the Subscription
78      */

79     public long getSubcriptionId(){
80         ConsumerInfo info = getConsumerInfo();
81         if (info != null){
82             return info.getConsumerId().getValue();
83         }
84         return 0;
85     }
86
87     /**
88      * @return the destination name
89      */

90     public String JavaDoc getDestinationName(){
91         ConsumerInfo info = getConsumerInfo();
92         if (info != null){
93             ActiveMQDestination dest = info.getDestination();
94             return dest.getPhysicalName();
95         }
96         return "NOTSET";
97     }
98
99     public String JavaDoc getSelector() {
100         if (subscription != null) {
101             return subscription.getSelector();
102         }
103         return null;
104     }
105
106     public void setSelector(String JavaDoc selector) throws InvalidSelectorException JavaDoc, UnsupportedOperationException JavaDoc {
107         if (subscription != null) {
108             subscription.setSelector(selector);
109         }
110         else {
111             throw new UnsupportedOperationException JavaDoc("No subscription object");
112         }
113     }
114
115     /**
116      * @return true if the destination is a Queue
117      */

118     public boolean isDestinationQueue(){
119         ConsumerInfo info = getConsumerInfo();
120         if (info != null){
121             ActiveMQDestination dest = info.getDestination();
122             return dest.isQueue();
123         }
124         return false;
125     }
126
127     /**
128      * @return true of the destination is a Topic
129      */

130     public boolean isDestinationTopic(){
131         ConsumerInfo info = getConsumerInfo();
132         if (info != null){
133             ActiveMQDestination dest = info.getDestination();
134             return dest.isTopic();
135         }
136         return false;
137     }
138
139     /**
140      * @return true if the destination is temporary
141      */

142     public boolean isDestinationTemporary(){
143         ConsumerInfo info = getConsumerInfo();
144         if (info != null){
145             ActiveMQDestination dest = info.getDestination();
146             return dest.isTemporary();
147         }
148         return false;
149     }
150     
151     /**
152      * @return true if the subscriber is active
153      */

154     public boolean isActive(){
155         return true;
156     }
157
158     /**
159      * The subscription should release as may references as it can to help the garbage collector
160      * reclaim memory.
161      */

162     public void gc(){
163         if (subscription != null){
164         subscription.gc();
165         }
166     }
167     
168     /**
169      * @return whether or not the subscriber is retroactive or not
170      */

171     public boolean isRetroactive() {
172         ConsumerInfo info = getConsumerInfo();
173         return info != null ? info.isRetroactive() : false;
174     }
175     
176     /**
177      * @return whether or not the subscriber is an exclusive consumer
178      */

179     public boolean isExclusive() {
180         ConsumerInfo info = getConsumerInfo();
181         return info != null ? info.isExclusive() : false;
182     }
183     
184     
185     /**
186      * @return whether or not the subscriber is durable (persistent)
187      */

188     public boolean isDurable() {
189         ConsumerInfo info = getConsumerInfo();
190         return info != null ? info.isDurable() : false;
191     }
192     
193     /**
194      * @return whether or not the subscriber ignores local messages
195      */

196     public boolean isNoLocal() {
197         ConsumerInfo info = getConsumerInfo();
198         return info != null ? info.isNoLocal() : false;
199     }
200     
201     
202     /**
203      * @return the maximum number of pending messages allowed in addition to the prefetch size. If enabled
204      * to a non-zero value then this will perform eviction of messages for slow consumers on non-durable topics.
205      */

206     public int getMaximumPendingMessageLimit() {
207         ConsumerInfo info = getConsumerInfo();
208         return info != null ? info.getMaximumPendingMessageLimit() : 0;
209     }
210     
211     /**
212      * @return the consumer priority
213      */

214     public byte getPriority() {
215         ConsumerInfo info = getConsumerInfo();
216         return info != null ? info.getPriority() : 0;
217     }
218     
219     /**
220      * @return the name of the consumer which is only used for durable consumers.
221      */

222     public String JavaDoc getSubcriptionName() {
223         ConsumerInfo info = getConsumerInfo();
224         return info != null ? info.getSubscriptionName() : null;
225     }
226     
227     /**
228      * @return number of messages pending delivery
229      */

230     public int getPendingQueueSize(){
231         return subscription != null ? subscription.getPendingQueueSize() : 0;
232     }
233     
234     /**
235      * @return number of messages dispatched
236      */

237     public int getDispatchedQueueSize(){
238         return subscription != null ? subscription.getDispatchedQueueSize() : 0;
239     }
240         
241     /**
242      * @return number of messages that matched the subscription
243      */

244     public long getDispachedCounter() {
245         return subscription != null ? subscription.getDispatchedCounter() : 0;
246     }
247
248     /**
249      * @return number of messages that matched the subscription
250      */

251     public long getEnqueueCounter() {
252         return subscription != null ? subscription.getEnqueueCounter() : 0;
253     }
254
255     /**
256      * @return number of messages queued by the client
257      */

258     public long getDequeueCounter() {
259         return subscription != null ? subscription.getDequeueCounter() : 0;
260     }
261
262     protected ConsumerInfo getConsumerInfo(){
263         return subscription != null ? subscription.getConsumerInfo() : null;
264     }
265     
266     /**
267      *@return pretty print
268      */

269     public String JavaDoc toString(){
270         return "SubscriptionView: " + getClientId() + ":" + getConnectionId();
271     }
272
273     /**
274      */

275     public int getPrefetchSize() {
276         return subscription != null ? subscription.getPrefetchSize() : 0;
277     }
278
279 }
280
Popular Tags