1 18 package org.apache.activemq.broker.region.policy; 19 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 import org.apache.activemq.broker.region.MessageReference; 24 import org.apache.activemq.broker.region.Subscription; 25 import org.apache.activemq.filter.MessageEvaluationContext; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 37 public class RoundRobinDispatchPolicy implements DispatchPolicy { 38 static final Log log=LogFactory.getLog(RoundRobinDispatchPolicy.class); 39 40 48 public boolean dispatch(MessageReference node, MessageEvaluationContext msgContext, List consumers) throws Exception { 49 50 synchronized(consumers) { 54 int count = 0; 55 56 Subscription firstMatchingConsumer = null; 57 for (Iterator iter = consumers.iterator(); iter.hasNext();) { 58 Subscription sub = (Subscription) iter.next(); 59 60 if (!sub.matches(node, msgContext)) 62 continue; 63 64 if (firstMatchingConsumer == null) { 65 firstMatchingConsumer = sub; 66 } 67 68 sub.add(node); 69 count++; 70 } 71 72 if (firstMatchingConsumer != null) { 73 try { 75 consumers.remove(firstMatchingConsumer); 76 consumers.add(firstMatchingConsumer); 77 } catch (Throwable bestEffort) { } 78 } 79 return count > 0; 80 } 81 } 82 83 84 } 85 | Popular Tags |