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 javax.jms.InvalidSelectorException;
   21   import javax.jms.JMSException;
   22   import org.apache.activemq.broker.Broker;
   23   import org.apache.activemq.broker.ConnectionContext;
   24   import org.apache.activemq.broker.region.group.MessageGroupMap;
   25   import org.apache.activemq.command.ActiveMQMessage;
   26   import org.apache.activemq.command.ConsumerInfo;
   27   import org.apache.activemq.command.Message;
   28   import org.apache.activemq.command.MessageAck;
   29   import org.apache.activemq.usage.SystemUsage;
   30   import org.apache.commons.logging.Log;
   31   import org.apache.commons.logging.LogFactory;
   32   
   33   public class QueueSubscription extends PrefetchSubscription implements LockOwner {
   34   
   35       private static final Log LOG = LogFactory.getLog(QueueSubscription.class);
   36   
   37       public QueueSubscription(Broker broker, SystemUsage usageManager, ConnectionContext context, ConsumerInfo info) throws InvalidSelectorException {
   38           super(broker,usageManager, context, info);
   39       }
   40   
   41       /**
   42        * In the queue case, mark the node as dropped and then a gc cycle will
   43        * remove it from the queue.
   44        * 
   45        * @throws IOException
   46        */
   47       protected void acknowledge(final ConnectionContext context, final MessageAck ack, final MessageReference n) throws IOException {
   48           final Destination q = n.getRegionDestination();
   49           final QueueMessageReference node = (QueueMessageReference)n;
   50           final Queue queue = (Queue)q;
   51           
   52           if (n.isExpired()) {
   53               if (broker.isExpired(n)) {
   54                   queue.messageExpired(context, this, node);
   55               } else {
   56                   LOG.debug("ignoring ack " + ack + ", for already expired message: " + n);
   57               }
   58               return;
   59           }
   60           queue.removeMessage(context, this, node, ack);
   61       }
   62   
   63       protected boolean canDispatch(MessageReference n) throws IOException {
   64           boolean result = true;
   65           QueueMessageReference node = (QueueMessageReference)n;
   66           if (node.isAcked() || node.isDropped()) {
   67               result = false;
   68           }
   69           result = result && (isBrowser() || node.lock(this));
   70           return result;
   71       }
   72   
   73       /**
   74        * Assigns the message group to this subscription and set the flag on the
   75        * message that it is the first message to be dispatched.
   76        */
   77       protected void assignGroupToMe(MessageGroupMap messageGroupOwners, MessageReference n, String groupId) throws IOException {
   78           messageGroupOwners.put(groupId, info.getConsumerId());
   79           Message message = n.getMessage();
   80           if (message instanceof ActiveMQMessage) {
   81               ActiveMQMessage activeMessage = (ActiveMQMessage)message;
   82               try {
   83                   activeMessage.setBooleanProperty("JMSXGroupFirstForConsumer", true, false);
   84               } catch (JMSException e) {
   85                   LOG.warn("Failed to set boolean header: " + e, e);
   86               }
   87           }
   88       }
   89   
   90       public synchronized String toString() {
   91           return "QueueSubscription:" + " consumer=" + info.getConsumerId() + ", destinations=" + destinations.size() + ", dispatched=" + dispatched.size() + ", delivered="
   92                  + this.prefetchExtension + ", pending=" + getPendingQueueSize();
   93       }
   94   
   95       public int getLockPriority() {
   96           return info.getPriority();
   97       }
   98   
   99       public boolean isLockExclusive() {
  100           return info.isExclusive();
  101       }
  102   
  103       /**
  104        */
  105       public void destroy() {
  106       }
  107   
  108      
  109       protected boolean isDropped(MessageReference node) {
  110          boolean result = false;
  111          if(node instanceof IndirectMessageReference) {
  112              QueueMessageReference qmr = (QueueMessageReference) node;
  113              result = qmr.isDropped();
  114          }
  115          return result;
  116       }
  117   
  118   }

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