1 18 package org.apache.activemq.broker.region.virtual; 19 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 23 import org.apache.activemq.broker.ProducerBrokerExchange; 24 import org.apache.activemq.broker.region.Destination; 25 import org.apache.activemq.broker.region.DestinationFilter; 26 import org.apache.activemq.command.ActiveMQDestination; 27 import org.apache.activemq.command.Message; 28 import org.apache.activemq.filter.MessageEvaluationContext; 29 30 36 public class CompositeDestinationInterceptor extends DestinationFilter { 37 38 private Collection forwardDestinations; 39 private boolean forwardOnly; 40 private boolean copyMessage; 41 42 public CompositeDestinationInterceptor(Destination next, Collection forwardDestinations, boolean forwardOnly, boolean copyMessage) { 43 super(next); 44 this.forwardDestinations = forwardDestinations; 45 this.forwardOnly = forwardOnly; 46 this.copyMessage = copyMessage; 47 } 48 49 public void send(ProducerBrokerExchange context, Message message) throws Exception { 50 MessageEvaluationContext messageContext = null; 51 52 for (Iterator iter = forwardDestinations.iterator(); iter.hasNext();) { 53 ActiveMQDestination destination = null; 54 Object value = iter.next(); 55 56 if (value instanceof FilteredDestination) { 57 FilteredDestination filteredDestination = (FilteredDestination) value; 58 if (messageContext == null) { 59 messageContext = new MessageEvaluationContext(); 60 messageContext.setMessageReference(message); 61 } 62 messageContext.setDestination(filteredDestination.getDestination()); 63 if (filteredDestination.matches(messageContext)) { 64 destination = filteredDestination.getDestination(); 65 } 66 } 67 else if (value instanceof ActiveMQDestination) { 68 destination = (ActiveMQDestination) value; 69 } 70 if (destination == null) { 71 continue; 72 } 73 74 if (copyMessage) { 75 message = message.copy(); 76 message.setDestination(destination); 77 } 78 79 send(context, message, destination); 80 } 81 if (!forwardOnly) { 82 super.send(context, message); 83 } 84 } 85 } 86 | Popular Tags |