KickJava   Java API By Example, From Geeks To Geeks.

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


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.command.RemoveSubscriptionInfo;
26 import org.apache.activemq.command.SubscriptionInfo;
27
28 /**
29  * TODO why does this class not inherit from DurableSubscriptionView?
30  *
31  * @version $Revision: 1.5 $
32  */

33 public class InactiveDurableSubscriptionView extends SubscriptionView implements DurableSubscriptionViewMBean {
34     protected ManagedRegionBroker broker;
35     protected SubscriptionInfo subscriptionInfo;
36     
37     
38     /**
39      * Constructor
40      * @param broker
41      * @param clientId
42      * @param sub
43      */

44     public InactiveDurableSubscriptionView(ManagedRegionBroker broker,String JavaDoc clientId,SubscriptionInfo sub){
45         super(clientId,null);
46         this.broker = broker;
47         this.subscriptionInfo = sub;
48     }
49     
50     
51
52     
53     /**
54      * @return the id of the Subscription
55      */

56     public long getSubcriptionId(){
57         return -1;
58     }
59
60     /**
61      * @return the destination name
62      */

63     public String JavaDoc getDestinationName(){
64         return subscriptionInfo.getDestination().getPhysicalName();
65        
66     }
67
68     /**
69      * @return true if the destination is a Queue
70      */

71     public boolean isDestinationQueue(){
72         return false;
73     }
74
75     /**
76      * @return true of the destination is a Topic
77      */

78     public boolean isDestinationTopic(){
79         return true;
80     }
81
82     /**
83      * @return true if the destination is temporary
84      */

85     public boolean isDestinationTemporary(){
86         return false;
87     }
88     /**
89      * @return name of the durable consumer
90      */

91     public String JavaDoc getSubscriptionName(){
92         return subscriptionInfo.getSubcriptionName();
93     }
94     
95     /**
96      * @return true if the subscriber is active
97      */

98     public boolean isActive(){
99         return false;
100     }
101
102     /**
103      * Browse messages for this durable subscriber
104      *
105      * @return messages
106      * @throws OpenDataException
107      */

108     public CompositeData JavaDoc[] browse() throws OpenDataException JavaDoc{
109         return broker.browse(this);
110     }
111
112     /**
113      * Browse messages for this durable subscriber
114      *
115      * @return messages
116      * @throws OpenDataException
117      */

118     public TabularData JavaDoc browseAsTable() throws OpenDataException JavaDoc{
119         return broker.browseAsTable(this);
120     }
121     
122     /**
123      * Destroys the durable subscription so that messages will no longer be stored for this subscription
124      */

125     public void destroy() throws Exception JavaDoc {
126         RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
127         info.setClientId(clientId);
128         info.setSubcriptionName(subscriptionInfo.getSubcriptionName());
129         ConnectionContext context = new ConnectionContext();
130         context.setBroker(broker);
131         context.setClientId(clientId);
132         broker.removeSubscription(context, info);
133     }
134     
135     public String JavaDoc toString(){
136         return "InactiveDurableSubscriptionView: " + getClientId() + ":" + getSubscriptionName();
137     }
138 }
139
Popular Tags