001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.broker.jmx;
018    
019    import javax.management.openmbean.CompositeData;
020    import javax.management.openmbean.OpenDataException;
021    import javax.management.openmbean.TabularData;
022    
023    import org.apache.activemq.broker.ConnectionContext;
024    import org.apache.activemq.broker.region.Subscription;
025    import org.apache.activemq.command.ConsumerInfo;
026    import org.apache.activemq.command.RemoveSubscriptionInfo;
027    import org.apache.activemq.command.SubscriptionInfo;
028    
029    /**
030     *
031     *
032     */
033    public class InactiveDurableSubscriptionView extends DurableSubscriptionView implements DurableSubscriptionViewMBean {
034        protected SubscriptionInfo subscriptionInfo;
035    
036        /**
037         * Constructor
038         *
039         * @param broker
040         * @param clientId
041         * @param userName
042         * @param subInfo
043         */
044        public InactiveDurableSubscriptionView(ManagedRegionBroker broker, String clientId, SubscriptionInfo subInfo, Subscription subscription) {
045            super(broker, clientId, null, subscription);
046            this.broker = broker;
047            this.subscriptionInfo = subInfo;
048        }
049    
050        /**
051         * @return the id of the Subscription
052         */
053        public long getSubcriptionId() {
054            return -1;
055        }
056    
057        /**
058         * @return the destination name
059         */
060        public String getDestinationName() {
061            return subscriptionInfo.getDestination().getPhysicalName();
062    
063        }
064    
065        /**
066         * @return true if the destination is a Queue
067         */
068        public boolean isDestinationQueue() {
069            return false;
070        }
071    
072        /**
073         * @return true of the destination is a Topic
074         */
075        public boolean isDestinationTopic() {
076            return true;
077        }
078    
079        /**
080         * @return true if the destination is temporary
081         */
082        public boolean isDestinationTemporary() {
083            return false;
084        }
085    
086        /**
087         * @return name of the durable consumer
088         */
089        public String getSubscriptionName() {
090            return subscriptionInfo.getSubscriptionName();
091        }
092    
093        /**
094         * @return true if the subscriber is active
095         */
096        public boolean isActive() {
097            return false;
098        }
099    
100        @Override
101        protected ConsumerInfo getConsumerInfo() {
102            // when inactive, consumer info is stale
103            return null;
104        }
105    
106        /**
107         * Browse messages for this durable subscriber
108         *
109         * @return messages
110         * @throws OpenDataException
111         */
112        public CompositeData[] browse() throws OpenDataException {
113            return broker.browse(this);
114        }
115    
116        /**
117         * Browse messages for this durable subscriber
118         *
119         * @return messages
120         * @throws OpenDataException
121         */
122        public TabularData browseAsTable() throws OpenDataException {
123            return broker.browseAsTable(this);
124        }
125    
126        /**
127         * Destroys the durable subscription so that messages will no longer be
128         * stored for this subscription
129         */
130        public void destroy() throws Exception {
131            RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
132            info.setClientId(clientId);
133            info.setSubscriptionName(subscriptionInfo.getSubscriptionName());
134            ConnectionContext context = new ConnectionContext();
135            context.setBroker(broker);
136            context.setClientId(clientId);
137            broker.removeSubscription(context, info);
138        }
139    
140        public String toString() {
141            return "InactiveDurableSubscriptionView: " + getClientId() + ":" + getSubscriptionName();
142        }
143    
144        @Override
145        public String getSelector() {
146            return subscriptionInfo.getSelector();
147        }
148    }