1 17 package org.apache.servicemix.jbi.framework; 18 19 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap; 20 21 import org.apache.servicemix.jbi.container.SubscriptionSpec; 22 import org.apache.servicemix.jbi.messaging.MessageExchangeImpl; 23 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint; 24 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 36 public class SubscriptionRegistry { 37 38 private Map subscriptions = new ConcurrentHashMap(); 39 private Registry registry; 40 41 public SubscriptionRegistry(Registry registry) { 42 this.registry = registry; 43 } 44 45 49 public void registerSubscription(SubscriptionSpec subscription, InternalEndpoint endpoint) { 50 subscriptions.put(subscription, endpoint); 51 } 52 53 57 public InternalEndpoint deregisterSubscription(SubscriptionSpec subscription) { 58 return (InternalEndpoint) subscriptions.remove(subscription); 59 } 60 61 62 66 public List getMatchingSubscriptionEndpoints(MessageExchangeImpl exchange) { 67 List result = null; 68 for (Iterator iter = subscriptions.entrySet().iterator(); iter.hasNext();) { 69 Map.Entry entry = (Map.Entry) iter.next(); 70 71 SubscriptionSpec subscription = (SubscriptionSpec) entry.getKey(); 72 if (subscription.matches(registry,exchange)) { 73 if (result == null) { 74 result = new ArrayList (); 75 } 76 InternalEndpoint endpoint = (InternalEndpoint) entry.getValue(); 77 result.add(endpoint); 78 } 79 } 80 return result; 81 } 82 83 } 84 | Popular Tags |