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