KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > solver > SingleHostComponentProxyManager


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.solver;
6
7 import java.util.Map JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 import org.omg.CORBA.Object JavaDoc;
12
13 /**
14  * An implementation of a ComponentProxyManager suitable to be used in
15  * environments in which there is a single node. This implementation
16  * actually has some provisions for multiple nodes, but it does not
17  * include any communication/synchronization/replication facilities
18  * to effectively support multilpe nodes.
19  * The provisions are in order to ease the creation of a multinode
20  * implementation.
21  * @author Guido Urdaneta, David Fernández
22  */

23 public final class SingleHostComponentProxyManager implements ComponentProxyManager
24 {
25     private static final String JavaDoc NULL_ARGS = "Null Arguments";
26     private static final NullPointerException JavaDoc NULL_ARGS_EXCEPTION = new NullPointerException JavaDoc(NULL_ARGS);
27     private Map JavaDoc componentMap;//Map<String cid, NodeProxyMap>
28

29     /**
30      * Creates a new SingleHostComponentProxyManager.
31      */

32     public SingleHostComponentProxyManager()
33     {
34         this.componentMap = new HashMap JavaDoc();
35     }
36
37     public synchronized Object JavaDoc[] getProxies(String JavaDoc 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 JavaDoc getProxy(String JavaDoc componentID, String JavaDoc 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 JavaDoc componentID, String JavaDoc node, Object JavaDoc 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 JavaDoc node)
82     {
83         if (node == null)
84         {
85             throw NULL_ARGS_EXCEPTION;
86         }
87
88         for (Iterator JavaDoc 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 JavaDoc componentID, String JavaDoc 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 JavaDoc 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 JavaDoc appName)
120     {
121         for (Iterator JavaDoc i = componentMap.keySet().iterator(); i.hasNext();)
122         {
123             String JavaDoc componentID = (String JavaDoc) i.next();
124             String JavaDoc 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