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.command.RemoveSubscriptionInfo;
025 import org.apache.activemq.command.SubscriptionInfo;
026
027 /**
028 *
029 *
030 */
031 public class InactiveDurableSubscriptionView extends DurableSubscriptionView implements DurableSubscriptionViewMBean {
032 protected SubscriptionInfo subscriptionInfo;
033
034 /**
035 * Constructor
036 *
037 * @param broker
038 * @param clientId
039 * @param sub
040 */
041 public InactiveDurableSubscriptionView(ManagedRegionBroker broker, String clientId, SubscriptionInfo sub) {
042 super(broker,clientId, null);
043 this.broker = broker;
044 this.subscriptionInfo = sub;
045 }
046
047 /**
048 * @return the id of the Subscription
049 */
050 public long getSubcriptionId() {
051 return -1;
052 }
053
054 /**
055 * @return the destination name
056 */
057 public String getDestinationName() {
058 return subscriptionInfo.getDestination().getPhysicalName();
059
060 }
061
062 /**
063 * @return true if the destination is a Queue
064 */
065 public boolean isDestinationQueue() {
066 return false;
067 }
068
069 /**
070 * @return true of the destination is a Topic
071 */
072 public boolean isDestinationTopic() {
073 return true;
074 }
075
076 /**
077 * @return true if the destination is temporary
078 */
079 public boolean isDestinationTemporary() {
080 return false;
081 }
082
083 /**
084 * @return name of the durable consumer
085 */
086 public String getSubscriptionName() {
087 return subscriptionInfo.getSubscriptionName();
088 }
089
090 /**
091 * @return true if the subscriber is active
092 */
093 public boolean isActive() {
094 return false;
095 }
096
097 /**
098 * Browse messages for this durable subscriber
099 *
100 * @return messages
101 * @throws OpenDataException
102 */
103 public CompositeData[] browse() throws OpenDataException {
104 return broker.browse(this);
105 }
106
107 /**
108 * Browse messages for this durable subscriber
109 *
110 * @return messages
111 * @throws OpenDataException
112 */
113 public TabularData browseAsTable() throws OpenDataException {
114 return broker.browseAsTable(this);
115 }
116
117 /**
118 * Destroys the durable subscription so that messages will no longer be
119 * stored for this subscription
120 */
121 public void destroy() throws Exception {
122 RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
123 info.setClientId(clientId);
124 info.setSubscriptionName(subscriptionInfo.getSubscriptionName());
125 ConnectionContext context = new ConnectionContext();
126 context.setBroker(broker);
127 context.setClientId(clientId);
128 broker.removeSubscription(context, info);
129 }
130
131 public String toString() {
132 return "InactiveDurableSubscriptionView: " + getClientId() + ":" + getSubscriptionName();
133 }
134 }