Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » broker » region » policy » [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.policy;
   18   
   19   import java.util.Iterator;
   20   import java.util.List;
   21   import org.apache.activemq.broker.region.MessageReference;
   22   import org.apache.activemq.broker.region.Subscription;
   23   import org.apache.activemq.filter.MessageEvaluationContext;
   24   
   25   /**
   26    * Dispatch policy that causes every subscription to see messages in the same
   27    * order.
   28    * 
   29    * @org.apache.xbean.XBean
   30    * @version $Revision$
   31    */
   32   public class StrictOrderDispatchPolicy implements DispatchPolicy {
   33   
   34       /**
   35        * @param node
   36        * @param msgContext
   37        * @param consumers
   38        * @return true if dispatched
   39        * @throws Exception
   40        * @see org.apache.activemq.broker.region.policy.DispatchPolicy#dispatch(org.apache.activemq.broker.region.MessageReference,
   41        *      org.apache.activemq.filter.MessageEvaluationContext, java.util.List)
   42        */
   43       public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception {
   44           // Big synch here so that only 1 message gets dispatched at a time.
   45           // Ensures
   46           // Everyone sees the same order.
   47           synchronized (consumers) {
   48               int count = 0;
   49               for (Iterator iter = consumers.iterator(); iter.hasNext();) {
   50                   Subscription sub = (Subscription)iter.next();
   51   
   52                   // Only dispatch to interested subscriptions
   53                   if (!sub.matches(node, msgContext)) {
   54                       continue;
   55                   }
   56   
   57                   sub.add(node);
   58                   count++;
   59               }
   60               return count > 0;
   61           }
   62       }
   63   
   64   }

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