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 org.apache.activemq.command.ConsumerId;
   20   import org.apache.activemq.command.Message;
   21   import org.apache.activemq.command.MessageId;
   22   
   23   /**
   24    * Keeps track of a message that is flowing through the Broker. This object may
   25    * hold a hard reference to the message or only hold the id of the message if
   26    * the message has been persisted on in a MessageStore.
   27    * 
   28    * @version $Revision: 1.15 $
   29    */
   30   public class IndirectMessageReference implements QueueMessageReference {
   31   
   32       /** The subscription that has locked the message */
   33       private LockOwner lockOwner;
   34       /** Has the message been dropped? */
   35       private boolean dropped;
   36       /** Has the message been acked? */
   37       private boolean acked;
   38       /** Direct reference to the message */
   39       private final Message message;
   40       
   41       /**
   42        * @param message
   43        */
   44       public IndirectMessageReference(final Message message) {
   45           this.message = message;
   46           message.getMessageId();
   47           message.getGroupID();
   48           message.getGroupSequence();
   49       }
   50   
   51       public Message getMessageHardRef() {
   52           return message;
   53       }
   54   
   55       public int getReferenceCount() {
   56           return message.getReferenceCount();
   57       }
   58   
   59       public int incrementReferenceCount() {
   60           return message.incrementReferenceCount();
   61       }
   62   
   63       public int decrementReferenceCount() {
   64           return message.decrementReferenceCount();
   65       }
   66   
   67       public Message getMessage() {
   68           return message;
   69       }
   70   
   71       public String toString() {
   72           return "Message " + message.getMessageId() + " dropped=" + dropped + " acked=" + acked + " locked=" + (lockOwner != null);
   73       }
   74   
   75       public void incrementRedeliveryCounter() {
   76           message.incrementRedeliveryCounter();
   77       }
   78   
   79       public synchronized boolean isDropped() {
   80           return dropped;
   81       }
   82   
   83       public synchronized void drop() {
   84           dropped = true;
   85           lockOwner = null;
   86           message.decrementReferenceCount();
   87       }
   88   
   89       public boolean lock(LockOwner subscription) {
   90           synchronized (this) {
   91               if (dropped || lockOwner != null) {
   92                   return false;
   93               }
   94               lockOwner = subscription;
   95               return true;
   96           }
   97       }
   98   
   99       public synchronized boolean unlock() {
  100           boolean result = lockOwner != null;
  101           lockOwner = null;
  102           return result;
  103       }
  104   
  105       public synchronized LockOwner getLockOwner() {
  106           return lockOwner;
  107       }
  108   
  109       public int getRedeliveryCounter() {
  110           return message.getRedeliveryCounter();
  111       }
  112   
  113       public MessageId getMessageId() {
  114           return message.getMessageId();
  115       }
  116   
  117       public Destination getRegionDestination() {
  118           return message.getRegionDestination();
  119       }
  120   
  121       public boolean isPersistent() {
  122           return message.isPersistent();
  123       }
  124   
  125       public synchronized boolean isLocked() {
  126           return lockOwner != null;
  127       }
  128   
  129       public synchronized boolean isAcked() {
  130           return acked;
  131       }
  132   
  133       public synchronized void setAcked(boolean b) {
  134           acked = b;
  135       }
  136   
  137       public String getGroupID() {
  138           return message.getGroupID();
  139       }
  140   
  141       public int getGroupSequence() {
  142           return message.getGroupSequence();
  143       }
  144   
  145       public ConsumerId getTargetConsumerId() {
  146           return message.getTargetConsumerId();
  147       }
  148   
  149       public long getExpiration() {
  150           return message.getExpiration();
  151       }
  152   
  153       public boolean isExpired() {
  154           return message.isExpired();
  155       }
  156   
  157       public synchronized int getSize() {
  158          return message.getSize();
  159       }
  160   
  161       public boolean isAdvisory() {
  162          return message.isAdvisory();
  163       }
  164   }

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