KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > proxy > ProxyServantLocator


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.daemon.proxy;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.apache.commons.pool.ObjectPool;
10
11 import org.omg.CORBA.CompletionStatus JavaDoc;
12 import org.omg.CORBA.INTERNAL JavaDoc;
13 import org.omg.PortableServer.ForwardRequest JavaDoc;
14 import org.omg.PortableServer.POA JavaDoc;
15 import org.omg.PortableServer.Servant JavaDoc;
16 import org.omg.PortableServer.ServantLocatorPackage.CookieHolder JavaDoc;
17
18 import ve.luz.ica.jackass.component.ComponentInfo;
19 import ve.luz.ica.jackass.component.ComponentInfoManager;
20
21 /**
22  * ServantLocator to be used with the static proxy invocation mechanism.
23  * It holds a reference to the {@link ComponentInfoManager}, so when a
24  * request arrives to this object, it retrives, from the component manager,
25  * a remote reference {@link org.omg.CORBA.Object} to the real object and
26  * the corresponding skeleton {@link Class}. Later a proxy servant is
27  * instanciated, and returned.
28  * @author Carlos Arévalo, Nelson Arapé
29  */

30 public class ProxyServantLocator
31         extends org.omg.CORBA.LocalObject JavaDoc
32         implements org.omg.PortableServer.ServantLocator JavaDoc
33 {
34     private static final int ERR_MINOR_CODE = 0;
35     private static final Log LOG = LogFactory.getLog(ProxyServantLocator.class);
36
37     private ComponentInfoManager manager;
38
39     /**
40      * Constructor for ProxyServantLocator.
41      * @param manager the component manager that holds the oid
42      * {@link ComponentInfo} asociation
43      * @throws NullPointerException when manager is null
44      */

45     public ProxyServantLocator(ComponentInfoManager manager) throws NullPointerException JavaDoc
46     {
47         if (manager == null)
48         {
49             throw new NullPointerException JavaDoc("manager == null");
50         }
51
52         this.manager = manager;
53     }
54
55     /**
56      * Retrives a Servant from the {@link ComponentInfoManager} for
57      * the oid. A pool is used for scallability.
58      * @see org.omg.PortableServer.ServantLocatorOperations#preinvoke(byte[],
59      * org.omg.PortableServer.POA, java.lang.String,
60      * org.omg.PortableServer.ServantLocatorPackage.CookieHolder)
61      */

62     public Servant JavaDoc preinvoke(byte[] oid, POA JavaDoc adapter, String JavaDoc operation, CookieHolder JavaDoc theCookie) throws ForwardRequest JavaDoc
63     {
64         Servant JavaDoc servant;
65         try
66         {
67             ComponentInfo info = manager.getComponentInfo(oid);
68             ObjectPool servantPool = info.getProxyServantPool();
69             servant = (Servant JavaDoc) servantPool.borrowObject();
70         }
71         catch (Exception JavaDoc e)
72         {
73             if (LOG.isErrorEnabled())
74             {
75                 LOG.error(e.getMessage(), e);
76             }
77
78             throw new INTERNAL JavaDoc(e.getMessage(), ERR_MINOR_CODE, CompletionStatus.COMPLETED_NO);
79         }
80         return servant;
81     }
82
83     /**
84      * Return the servant for the oid to the servant pool.
85      * @see org.omg.PortableServer.ServantLocatorOperations#postinvoke(byte[],
86      * org.omg.PortableServer.POA, java.lang.String, java.lang.Object,
87      * org.omg.PortableServer.Servant)
88      */

89     public void postinvoke(byte[] oid, POA JavaDoc adapter, String JavaDoc operation, Object JavaDoc theCookie, Servant JavaDoc theServant)
90     {
91         try
92         {
93             ComponentInfo info = manager.getComponentInfo(oid);
94             ObjectPool servantPool = info.getProxyServantPool();
95             servantPool.returnObject(theServant);
96         }
97         catch (Exception JavaDoc e)
98         {
99             if (LOG.isErrorEnabled())
100             {
101                 LOG.error(e.getMessage(), e);
102             }
103
104             throw new INTERNAL JavaDoc(e.getMessage(), ERR_MINOR_CODE, CompletionStatus.COMPLETED_MAYBE);
105         }
106     }
107 }
108
Popular Tags