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.ConnectionContext;
023import org.apache.activemq.broker.region.Destination;
024import org.apache.activemq.broker.region.DestinationFactory;
025import org.apache.activemq.broker.region.DestinationStatistics;
026import org.apache.activemq.broker.region.QueueRegion;
027import org.apache.activemq.broker.region.Subscription;
028import org.apache.activemq.command.ActiveMQDestination;
029import org.apache.activemq.command.ConsumerInfo;
030import org.apache.activemq.thread.TaskRunnerFactory;
031import org.apache.activemq.usage.SystemUsage;
032
033public class ManagedQueueRegion extends QueueRegion {
034
035    private final ManagedRegionBroker regionBroker;
036
037    public ManagedQueueRegion(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}