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 java.io.IOException;
   20   import org.apache.activemq.broker.BrokerService;
   21   import org.apache.activemq.broker.ConnectionContext;
   22   import org.apache.activemq.broker.region.cursors.VMPendingMessageCursor;
   23   import org.apache.activemq.command.ActiveMQDestination;
   24   import org.apache.activemq.command.ActiveMQTempDestination;
   25   import org.apache.activemq.store.MessageStore;
   26   import org.apache.activemq.thread.TaskRunnerFactory;
   27   import org.apache.commons.logging.Log;
   28   import org.apache.commons.logging.LogFactory;
   29   
   30   /**
   31    * The Queue is a List of MessageEntry objects that are dispatched to matching
   32    * subscriptions.
   33    * 
   34    * @version $Revision: 1.28 $
   35    */
   36   public class TempQueue extends Queue{
   37       private static final Log LOG = LogFactory.getLog(TempQueue.class);
   38       private final ActiveMQTempDestination tempDest;
   39      
   40       
   41       /**
   42        * @param brokerService
   43        * @param destination
   44        * @param store
   45        * @param parentStats
   46        * @param taskFactory
   47        * @throws Exception
   48        */
   49       public TempQueue(BrokerService brokerService,
   50               ActiveMQDestination destination, MessageStore store,
   51               DestinationStatistics parentStats, TaskRunnerFactory taskFactory)
   52               throws Exception {
   53           super(brokerService, destination, store, parentStats, taskFactory);
   54           this.tempDest = (ActiveMQTempDestination) destination;
   55       }
   56       
   57       @Override
   58       public void initialize() throws Exception {
   59           this.messages=new VMPendingMessageCursor();
   60           this.messages.setMemoryUsageHighWaterMark(getCursorMemoryHighWaterMark());
   61           this.systemUsage = brokerService.getSystemUsage();
   62           memoryUsage.setParent(systemUsage.getMemoryUsage());           
   63           this.taskRunner = taskFactory.createTaskRunner(this, "TempQueue:  " + destination.getPhysicalName());
   64       }
   65       
   66       @Override
   67       public void addSubscription(ConnectionContext context, Subscription sub) throws Exception {
   68           // Only consumers on the same connection can consume from
   69           // the temporary destination
   70           // However, we could have failed over - and we do this
   71           // check client side anyways ....
   72           if (!context.isFaultTolerant()
   73                   && (!context.isNetworkConnection() && !tempDest
   74                           .getConnectionId().equals(
   75                                   sub.getConsumerInfo().getConsumerId()
   76                                           .getConnectionId()))) {
   77   
   78               tempDest.setConnectionId(sub.getConsumerInfo().getConsumerId().getConnectionId());
   79               LOG.debug(" changed ownership of " + this + " to "+ tempDest.getConnectionId());
   80           }
   81           super.addSubscription(context, sub);
   82       }
   83       
   84       @Override
   85       public void dispose(ConnectionContext context) throws IOException {
   86           try {
   87              purge();
   88           } catch (Exception e) {
   89             LOG.warn("Caught an exception purging Queue: " + destination);
   90           }
   91           super.dispose(context);
   92       }
   93   }

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