1 5 package ve.luz.ica.jackass.solver; 6 7 import java.util.Map ; 8 import java.util.HashMap ; 9 import java.util.Iterator ; 10 11 import org.omg.CORBA.Object ; 12 13 23 public final class SingleHostComponentProxyManager implements ComponentProxyManager 24 { 25 private static final String NULL_ARGS = "Null Arguments"; 26 private static final NullPointerException NULL_ARGS_EXCEPTION = new NullPointerException (NULL_ARGS); 27 private Map componentMap; 29 32 public SingleHostComponentProxyManager() 33 { 34 this.componentMap = new HashMap (); 35 } 36 37 public synchronized Object [] getProxies(String componentID) 38 { 39 if (componentID == null) 40 { 41 throw NULL_ARGS_EXCEPTION; 42 } 43 NodeProxyMap map = (NodeProxyMap) componentMap.get(componentID); 44 if (map == null) 45 { 46 return null; 47 } 48 return map.getProxies(); 49 } 50 51 public synchronized Object getProxy(String componentID, String node) 52 { 53 if (componentID == null) 54 { 55 throw NULL_ARGS_EXCEPTION; 56 } 57 NodeProxyMap proxyMap = (NodeProxyMap) componentMap.get(componentID); 58 if (proxyMap == null) 59 { 60 return null; 61 } 62 return proxyMap.getProxy(node); 63 } 64 65 public void addProxyToComponent(String componentID, String node, Object proxy) 66 { 67 if (componentID == null || node == null || proxy == null) 68 { 69 throw NULL_ARGS_EXCEPTION; 70 } 71 72 NodeProxyMap proxyMap = (NodeProxyMap) this.componentMap.get(componentID); 73 if (proxyMap == null) 74 { 75 proxyMap = new NodeProxyMap(); 76 this.componentMap.put(componentID, proxyMap); 77 } 78 proxyMap.add(node, proxy); 79 } 80 81 public synchronized void removeNode(String node) 82 { 83 if (node == null) 84 { 85 throw NULL_ARGS_EXCEPTION; 86 } 87 88 for (Iterator i = componentMap.values().iterator(); i.hasNext();) 89 { 90 NodeProxyMap proxyMap = (NodeProxyMap) i.next(); 91 proxyMap.remove(node); 92 } 93 } 94 95 public synchronized void removeNodeComponent(String componentID, String node) 96 { 97 if (componentID == null || node == null) 98 { 99 throw NULL_ARGS_EXCEPTION; 100 } 101 102 NodeProxyMap proxyMap = (NodeProxyMap) componentMap.get(componentID); 103 if (proxyMap != null) 104 { 105 proxyMap.remove(node); 106 } 107 } 108 109 public synchronized void removeComponent(String componentID) 110 { 111 if (componentID == null) 112 { 113 throw NULL_ARGS_EXCEPTION; 114 } 115 116 componentMap.remove(componentID); 117 } 118 119 public synchronized void removeApplication(String appName) 120 { 121 for (Iterator i = componentMap.keySet().iterator(); i.hasNext();) 122 { 123 String componentID = (String ) i.next(); 124 String compAppName = componentID.substring(0, componentID.indexOf(COMPONENT_ID_SEPARATOR)); 125 if (compAppName.equals(appName)) 126 { 127 i.remove(); 128 } 129 } 130 } 131 } 132 | Popular Tags |