KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > framework > SubscriptionRegistry


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.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 JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 /**
31  * Maintains a registry of the applicable subscriptions currently active for the
32  * current components
33  *
34  * @version $Revision: 426415 $
35  */

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     /**
46      * @param subscription
47      * @param endpoint
48      */

49     public void registerSubscription(SubscriptionSpec subscription, InternalEndpoint endpoint) {
50         subscriptions.put(subscription, endpoint);
51     }
52
53     /**
54      * @param subscription
55      * @return the ServiceEndpoint
56      */

57     public InternalEndpoint deregisterSubscription(SubscriptionSpec subscription) {
58         return (InternalEndpoint) subscriptions.remove(subscription);
59     }
60     
61     
62     /**
63      * @param exchange
64      * @return a List of matching endpoints - can return null if no matches
65      */

66     public List JavaDoc getMatchingSubscriptionEndpoints(MessageExchangeImpl exchange) {
67         List JavaDoc result = null;
68         for (Iterator JavaDoc 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 JavaDoc();
75                 }
76                 InternalEndpoint endpoint = (InternalEndpoint) entry.getValue();
77                 result.add(endpoint);
78             }
79         }
80         return result;
81     }
82
83 }
84
Popular Tags