Home » activemq-parent-5.3.1-source-release » org.apache » activemq » broker » region » cursors » [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.cursors;
   18   
   19   import java.io.IOException;
   20   import org.apache.activemq.broker.region.Subscription;
   21   import org.apache.activemq.broker.region.Topic;
   22   import org.apache.activemq.command.Message;
   23   import org.apache.activemq.command.MessageId;
   24   import org.apache.activemq.filter.MessageEvaluationContext;
   25   import org.apache.activemq.filter.NonCachedMessageEvaluationContext;
   26   import org.apache.activemq.store.TopicMessageStore;
   27   import org.apache.commons.logging.Log;
   28   import org.apache.commons.logging.LogFactory;
   29   
   30   /**
   31    * perist pendingCount messages pendingCount message (messages awaiting disptach
   32    * to a consumer) cursor
   33    * 
   34    * @version $Revision: 902999 $
   35    */
   36   class TopicStorePrefetch extends AbstractStoreCursor {
   37       private static final Log LOG = LogFactory.getLog(TopicStorePrefetch.class);
   38       private final TopicMessageStore store;
   39       private final String clientId;
   40       private final String subscriberName;
   41       private final Subscription subscription;
   42       
   43       /**
   44        * @param topic
   45        * @param clientId
   46        * @param subscriberName
   47        */
   48       public TopicStorePrefetch(Subscription subscription,Topic topic, String clientId, String subscriberName) {
   49           super(topic);
   50           this.subscription=subscription;
   51           this.store = (TopicMessageStore)topic.getMessageStore();
   52           this.clientId = clientId;
   53           this.subscriberName = subscriberName;
   54           this.maxProducersToAudit=32;
   55           this.maxAuditDepth=10000;
   56       }
   57   
   58       public boolean recoverMessageReference(MessageId messageReference) throws Exception {
   59           // shouldn't get called
   60           throw new RuntimeException("Not supported");
   61       }
   62       
   63           
   64       @Override
   65       public synchronized boolean recoverMessage(Message message, boolean cached) throws Exception {
   66           MessageEvaluationContext messageEvaluationContext = new NonCachedMessageEvaluationContext();
   67           messageEvaluationContext.setMessageReference(message);
   68           if (this.subscription.matches(message, messageEvaluationContext)) {
   69               return super.recoverMessage(message, cached);
   70           }
   71           return false;
   72           
   73       }
   74   
   75      
   76       @Override
   77       protected synchronized int getStoreSize() {
   78           try {
   79               return store.getMessageCount(clientId, subscriberName);
   80           } catch (IOException e) {
   81               LOG.error(this + " Failed to get the outstanding message count from the store", e);
   82               throw new RuntimeException(e);
   83           }
   84       }
   85       
   86       @Override
   87       protected synchronized boolean isStoreEmpty() {
   88           try {
   89               return this.store.isEmpty();
   90               
   91           } catch (Exception e) {
   92               LOG.error("Failed to get message count", e);
   93               throw new RuntimeException(e);
   94           }
   95       }
   96   
   97               
   98       @Override
   99       protected void resetBatch() {
  100           this.store.resetBatching(clientId, subscriberName);
  101       }
  102       
  103       @Override
  104       protected void doFillBatch() throws Exception {
  105           this.store.recoverNextMessages(clientId, subscriberName,
  106                   maxBatchSize, this);
  107       }
  108   
  109       @Override
  110       public String toString() {
  111           return "TopicStorePrefetch" + System.identityHashCode(this) + "(" + clientId + "," + subscriberName + ")";
  112       }
  113   }

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