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