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.region;
018
019import javax.jms.JMSException;
020
021import org.apache.activemq.broker.ConnectionContext;
022import org.apache.activemq.command.ActiveMQDestination;
023import org.apache.activemq.command.ConsumerInfo;
024import org.apache.activemq.command.MessageDispatchNotification;
025import org.apache.activemq.thread.TaskRunnerFactory;
026import org.apache.activemq.usage.SystemUsage;
027
028/**
029 * 
030 */
031public class TempQueueRegion extends AbstractTempRegion {
032
033    public TempQueueRegion(RegionBroker broker, DestinationStatistics destinationStatistics, SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory,
034                           DestinationFactory destinationFactory) {
035        super(broker, destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory);
036    }
037
038    protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws JMSException {
039        if (info.isBrowser()) {
040            return new QueueBrowserSubscription(broker,usageManager,context, info);
041        } else {
042            return new QueueSubscription(broker,usageManager,context, info);
043        }
044    }
045
046    public String toString() {
047        return "TempQueueRegion: destinations=" + destinations.size() + ", subscriptions=" + subscriptions.size() + ", memory=" + usageManager.getMemoryUsage().getPercentUsage() + "%";
048    }
049
050    public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
051
052        // Force a timeout value so that we don't get an error that
053        // there is still an active sub. Temp destination may be removed
054        // while a network sub is still active which is valid.
055        if (timeout == 0) {
056            timeout = 1;
057        }
058
059        super.removeDestination(context, destination, timeout);
060    }
061    
062    /*
063     * For a Queue, dispatch order is imperative to match acks, so the dispatch is deferred till 
064     * the notification to ensure that the subscription chosen by the master is used.
065     * 
066     * (non-Javadoc)
067     * @see org.apache.activemq.broker.region.AbstractRegion#processDispatchNotification(org.apache.activemq.command.MessageDispatchNotification)
068     */
069    public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
070        processDispatchNotificationViaDestination(messageDispatchNotification);
071    }
072}