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.jms.JMSException; 020 import javax.management.ObjectName; 021 022 import org.apache.activemq.broker.ConnectionContext; 023 import org.apache.activemq.broker.region.Destination; 024 import org.apache.activemq.broker.region.DestinationFactory; 025 import org.apache.activemq.broker.region.DestinationStatistics; 026 import org.apache.activemq.broker.region.Subscription; 027 import org.apache.activemq.broker.region.TopicRegion; 028 import org.apache.activemq.command.ActiveMQDestination; 029 import org.apache.activemq.command.ConsumerInfo; 030 import org.apache.activemq.thread.TaskRunnerFactory; 031 import org.apache.activemq.usage.SystemUsage; 032 033 public class ManagedTopicRegion extends TopicRegion { 034 035 private final ManagedRegionBroker regionBroker; 036 037 public ManagedTopicRegion(ManagedRegionBroker broker, DestinationStatistics destinationStatistics, SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory, 038 DestinationFactory destinationFactory) { 039 super(broker, destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory); 040 regionBroker = broker; 041 } 042 043 protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws JMSException { 044 Subscription sub = super.createSubscription(context, info); 045 ObjectName name = regionBroker.registerSubscription(context, sub); 046 sub.setObjectName(name); 047 return sub; 048 } 049 050 protected void destroySubscription(Subscription sub) { 051 regionBroker.unregisterSubscription(sub); 052 super.destroySubscription(sub); 053 } 054 055 protected Destination createDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { 056 Destination rc = super.createDestination(context, destination); 057 regionBroker.register(destination, rc); 058 return rc; 059 } 060 061 public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception { 062 super.removeDestination(context, destination, timeout); 063 regionBroker.unregister(destination); 064 } 065 066 }