Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » broker » region » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.broker.region;
   18   
   19   import javax.jms.JMSException;
   20   
   21   import org.apache.activemq.broker.ConnectionContext;
   22   import org.apache.activemq.broker.region.policy.PolicyEntry;
   23   import org.apache.activemq.command.ActiveMQDestination;
   24   import org.apache.activemq.command.ConsumerInfo;
   25   import org.apache.activemq.thread.TaskRunnerFactory;
   26   import org.apache.activemq.usage.SystemUsage;
   27   import org.apache.commons.logging.Log;
   28   import org.apache.commons.logging.LogFactory;
   29   
   30   /**
   31    * @version $Revision: 1.7 $
   32    */
   33   public class TempTopicRegion extends AbstractTempRegion {
   34   
   35       private static final Log LOG = LogFactory.getLog(TempTopicRegion.class);
   36   
   37       public TempTopicRegion(RegionBroker broker, DestinationStatistics destinationStatistics, SystemUsage memoryManager, TaskRunnerFactory taskRunnerFactory,
   38                              DestinationFactory destinationFactory) {
   39           super(broker, destinationStatistics, memoryManager, taskRunnerFactory, destinationFactory);
   40           // We should allow the following to be configurable via a Destination
   41           // Policy
   42           // setAutoCreateDestinations(false);
   43       }
   44   
   45       protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws JMSException {
   46           if (info.isDurable()) {
   47               throw new JMSException("A durable subscription cannot be created for a temporary topic.");
   48           }
   49           try {
   50               TopicSubscription answer = new TopicSubscription(broker, context, info, usageManager);
   51               // lets configure the subscription depending on the destination
   52               ActiveMQDestination destination = info.getDestination();
   53               if (destination != null && broker.getDestinationPolicy() != null) {
   54                   PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination);
   55                   if (entry != null) {
   56                       entry.configure(broker, usageManager, answer);
   57                   }
   58               }
   59               answer.init();
   60               return answer;
   61           } catch (Exception e) {
   62               LOG.error("Failed to create TopicSubscription ", e);
   63               JMSException jmsEx = new JMSException("Couldn't create TopicSubscription");
   64               jmsEx.setLinkedException(e);
   65               throw jmsEx;
   66           }
   67       }
   68   
   69       public String toString() {
   70           return "TempTopicRegion: destinations=" + destinations.size() + ", subscriptions=" + subscriptions.size() + ", memory=" + usageManager.getMemoryUsage().getPercentUsage() + "%";
   71       }
   72   
   73       public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
   74   
   75           // Force a timeout value so that we don't get an error that
   76           // there is still an active sub. Temp destination may be removed
   77           // while a network sub is still active which is valid.
   78           if (timeout == 0) {
   79               timeout = 1;
   80           }
   81   
   82           super.removeDestination(context, destination, timeout);
   83       }
   84   
   85       
   86       protected Destination doCreateDestination(ConnectionContext context,
   87               ActiveMQDestination destination) throws Exception {
   88           return destinationFactory.createDestination(context, destination, destinationStatistics);
   89       }
   90   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » broker » region » [javadoc | source]