KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > client > SingleHostProxyManager


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.client;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import org.omg.CORBA.ORB JavaDoc;
14 import org.omg.CORBA.Object JavaDoc;
15
16 /**
17  * A ProxyManager that for non-clustered environments. This is mostly for educational purposes and
18  * to be used as a base for a version that supports clustering.
19  * There is no real benefit in using a Jackass Client Library in a non-clustered environtment.
20  * @author Guido Urdaneta
21  * @see ProxyManager
22  */

23 final class SingleHostProxyManager implements ProxyManager
24 {
25     private static final Log LOG = LogFactory.getLog(SingleHostProxyManager.class);
26
27     private Map JavaDoc proxyMap;
28     private SolverManager solverMgr;
29
30     /**
31      * Creates a SingleHostProxyManager
32      * @param orb the ORB to use to convert string (corbaloc) references to SolverManagers.
33      */

34     public SingleHostProxyManager(ORB JavaDoc orb)
35     {
36         proxyMap = new HashMap JavaDoc();
37         solverMgr = new SingleHostSolverManager(orb);
38         if (LOG.isDebugEnabled()) LOG.debug("Initialized SolverMgr: " + solverMgr);
39     }
40
41     public Object JavaDoc getProxy(String JavaDoc componentID)
42     {
43         if (LOG.isDebugEnabled()) LOG.debug("Searching proxy cache");
44         Object JavaDoc[] proxies = (Object JavaDoc[]) proxyMap.get(componentID);
45         if (proxies == null)
46         {
47             if (LOG.isDebugEnabled()) LOG.debug("component is not in cache, forwarding to SolverManager");
48             proxies = solverMgr.solve(componentID);
49             proxyMap.put(componentID, proxies);
50             if (LOG.isDebugEnabled()) LOG.debug("Proxies successfully obtained. Added to cache proxies " + proxies);
51         }
52
53         return proxies[0];
54     }
55
56     /**
57      * Detects if a component is faulted. This implementation always returns true.
58      * @param componentID the ID of the component to probe.
59      * @return always true.
60      * @see ProxyManager#isComponentFaulted
61      */

62     public boolean isComponentFaulted(String JavaDoc componentID)
63     {
64         if (LOG.isWarnEnabled()) LOG.warn("Component is faulted");
65         return true;
66     }
67 }
68
Popular Tags