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 */ 017package org.apache.activemq.broker.jmx; 018 019import javax.management.openmbean.CompositeData; 020import javax.management.openmbean.OpenDataException; 021import javax.management.openmbean.TabularData; 022 023import org.apache.activemq.broker.BrokerService; 024import org.apache.activemq.broker.ConnectionContext; 025import org.apache.activemq.broker.region.Subscription; 026import org.apache.activemq.command.ConsumerInfo; 027import org.apache.activemq.command.RemoveSubscriptionInfo; 028import org.apache.activemq.command.SubscriptionInfo; 029 030/** 031 * 032 * 033 */ 034public class InactiveDurableSubscriptionView extends DurableSubscriptionView implements DurableSubscriptionViewMBean { 035 protected SubscriptionInfo subscriptionInfo; 036 037 /** 038 * Constructor 039 * 040 * @param broker 041 * @param clientId 042 * @param userName 043 * @param subInfo 044 */ 045 public InactiveDurableSubscriptionView(ManagedRegionBroker broker, BrokerService brokerService, String clientId, SubscriptionInfo subInfo, Subscription subscription) { 046 super(broker, brokerService, clientId, null, subscription); 047 this.broker = broker; 048 this.subscriptionInfo = subInfo; 049 } 050 051 /** 052 * @return the id of the Subscription 053 */ 054 @Override 055 public long getSubscriptionId() { 056 return -1; 057 } 058 059 /** 060 * @return the destination name 061 */ 062 @Override 063 public String getDestinationName() { 064 return subscriptionInfo.getDestination().getPhysicalName(); 065 } 066 067 /** 068 * @return true if the destination is a Queue 069 */ 070 @Override 071 public boolean isDestinationQueue() { 072 return false; 073 } 074 075 /** 076 * @return true of the destination is a Topic 077 */ 078 @Override 079 public boolean isDestinationTopic() { 080 return true; 081 } 082 083 /** 084 * @return true if the destination is temporary 085 */ 086 @Override 087 public boolean isDestinationTemporary() { 088 return false; 089 } 090 091 /** 092 * @return name of the durable consumer 093 */ 094 @Override 095 public String getSubscriptionName() { 096 return subscriptionInfo.getSubscriptionName(); 097 } 098 099 /** 100 * @return true if the subscriber is active 101 */ 102 @Override 103 public boolean isActive() { 104 return false; 105 } 106 107 @Override 108 protected ConsumerInfo getConsumerInfo() { 109 // when inactive, consumer info is stale 110 return null; 111 } 112 113 /** 114 * Browse messages for this durable subscriber 115 * 116 * @return messages 117 * @throws OpenDataException 118 */ 119 @Override 120 public CompositeData[] browse() throws OpenDataException { 121 return broker.browse(this); 122 } 123 124 /** 125 * Browse messages for this durable subscriber 126 * 127 * @return messages 128 * @throws OpenDataException 129 */ 130 @Override 131 public TabularData browseAsTable() throws OpenDataException { 132 return broker.browseAsTable(this); 133 } 134 135 /** 136 * Destroys the durable subscription so that messages will no longer be 137 * stored for this subscription 138 */ 139 @Override 140 public void destroy() throws Exception { 141 RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); 142 info.setClientId(clientId); 143 info.setSubscriptionName(subscriptionInfo.getSubscriptionName()); 144 ConnectionContext context = new ConnectionContext(); 145 context.setBroker(broker); 146 context.setClientId(clientId); 147 brokerService.getBroker().removeSubscription(context, info); 148 } 149 150 @Override 151 public String toString() { 152 return "InactiveDurableSubscriptionView: " + getClientId() + ":" + getSubscriptionName(); 153 } 154 155 @Override 156 public String getSelector() { 157 return subscriptionInfo.getSelector(); 158 } 159 160 @Override 161 public void removeMessage(@MBeanInfo("messageId") String messageId) throws Exception { 162 broker.remove(this, messageId); 163 } 164 165}