KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.management.openmbean.CompositeData JavaDoc;
21 import javax.management.openmbean.OpenDataException JavaDoc;
22 import javax.management.openmbean.TabularData JavaDoc;
23
24 import org.apache.activemq.broker.ConnectionContext;
25 import org.apache.activemq.broker.region.Subscription;
26 import org.apache.activemq.command.RemoveSubscriptionInfo;
27 /**
28  * @version $Revision: 1.5 $
29  */

30 public class DurableSubscriptionView extends SubscriptionView implements DurableSubscriptionViewMBean {
31     
32     protected ManagedRegionBroker broker;
33     protected String JavaDoc subscriptionName;
34     /**
35      * Constructor
36      * @param clientId
37      * @param sub
38      */

39     public DurableSubscriptionView(ManagedRegionBroker broker,String JavaDoc clientId,Subscription sub){
40         super(clientId,sub);
41         this.broker = broker;
42         this.subscriptionName = sub.getConsumerInfo().getSubscriptionName();
43     }
44     
45     /**
46      * @return name of the durable consumer
47      */

48     public String JavaDoc getSubscriptionName(){
49         return subscriptionName;
50     }
51
52     /**
53      * Browse messages for this durable subscriber
54      *
55      * @return messages
56      * @throws OpenDataException
57      */

58     public CompositeData JavaDoc[] browse() throws OpenDataException JavaDoc{
59         return broker.browse(this);
60     }
61
62     /**
63      * Browse messages for this durable subscriber
64      *
65      * @return messages
66      * @throws OpenDataException
67      */

68     public TabularData JavaDoc browseAsTable() throws OpenDataException JavaDoc{
69         return broker.browseAsTable(this);
70     }
71     
72     /**
73      * Destroys the durable subscription so that messages will no longer be stored for this subscription
74      */

75     public void destroy() throws Exception JavaDoc {
76         RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
77         info.setClientId(clientId);
78         info.setSubcriptionName(subscriptionName);
79         ConnectionContext context = new ConnectionContext();
80         context.setBroker(broker);
81         context.setClientId(clientId);
82         broker.removeSubscription(context, info);
83     }
84     
85     public String JavaDoc toString(){
86         return "InactiveDurableSubscriptionView: " + getClientId() + ":" + getSubscriptionName();
87     }
88 }
89
Popular Tags