1 17 package org.apache.servicemix.common; 18 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 public class Registry { 25 26 protected BaseComponent component; 27 protected Map endpoints; 28 protected Map serviceUnits; 29 30 public Registry(BaseComponent component) { 31 this.component = component; 32 this.endpoints = new HashMap (); 33 this.serviceUnits = new HashMap (); 34 } 35 36 public Endpoint getEndpoint(String key) { 37 return (Endpoint) this.endpoints.get(key); 38 } 39 40 public ServiceUnit getServiceUnit(String name) { 41 return (ServiceUnit) this.serviceUnits.get(name); 42 } 43 44 public void registerEndpoint(Endpoint ep) { 45 String key = EndpointSupport.getKey(ep); 46 if (this.endpoints.put(key, ep) != null) { 47 throw new IllegalStateException ("An endpoint is already registered for key: " + key); 48 } 49 } 50 51 public void unregisterEndpoint(Endpoint ep) { 52 this.endpoints.remove(EndpointSupport.getKey(ep)); 53 } 54 55 public void registerServiceUnit(ServiceUnit su) { 56 this.serviceUnits.put(su.getName(), su); 57 Collection endpoints = (Collection ) su.getEndpoints(); 58 for (Iterator iter = endpoints.iterator(); iter.hasNext();) { 59 Endpoint ep = (Endpoint) iter.next(); 60 registerEndpoint(ep); 61 } 62 } 63 64 public void unregisterServiceUnit(ServiceUnit su) { 65 this.serviceUnits.remove(su.getName()); 66 Collection endpoints = (Collection ) su.getEndpoints(); 67 for (Iterator iter = endpoints.iterator(); iter.hasNext();) { 68 Endpoint ep = (Endpoint) iter.next(); 69 unregisterEndpoint(ep); 70 } 71 } 72 73 } 74 | Popular Tags |