KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > core > ivm > IntraVmServer


1 package org.openejb.core.ivm;
2
3 import javax.ejb.EJBHome JavaDoc;
4 import javax.ejb.EJBMetaData JavaDoc;
5 import javax.ejb.EJBObject JavaDoc;
6 import javax.ejb.Handle JavaDoc;
7 import javax.ejb.HomeHandle JavaDoc;
8
9 import org.openejb.ProxyInfo;
10 import org.openejb.core.entity.EntityEjbHomeHandler;
11 import org.openejb.core.stateful.StatefulEjbHomeHandler;
12 import org.openejb.core.stateless.StatelessEjbHomeHandler;
13 import org.openejb.util.proxy.ProxyManager;
14
15 /**
16  * <h2><b>REMOTE to LOCAL SERIALIZATION</b></h2> <p>
17  *
18  * <i>Definition:</i><p>
19  * This is a serialization that initiates in a remote client vm
20  * and finishes in same vm as OpenEJB and the Application Server.
21  * <p>
22  * <i>Circumstances:</i><p>
23  * When a remote ApplicationServer-specific implementation of a
24  * javax.ejb.* interface is serialized outside the scope of the
25  * remote client vm and deserializes in the Application Server
26  * and OpenEJB IntraVM Server's vm.
27  * <p>
28  * These serializations happen, for example, when javax.ejb.*
29  * objects are used as parameters to an EJBObject method either
30  * directly or nested in another object.
31  * <p>
32  * <i>Action:</i><p>
33  * No special action is required by the OpenEJB specification.
34  * <p>
35  * <i>Notes on Optimization:</i><p>
36  * For optimization purposes, the ApplicationServer can replace
37  * its javax.ejb.* interface implementations with those created
38  * by the IntraVM Server via the IntraVM's own implementation
39  * of the org.openejb.spi.ApplicationServer interface.
40  * <p>
41  * The Application Server may wish to this by implementing the
42  * serialization readResolve method in it's javax.ejb.*
43  * implementations. Then, when these implementations are
44  * deserialized, certain checks can be made to determine if they
45  * in the same VM as the Application Server and OpenEJB IntraVM
46  * Server. If they are, it can replace itself with the
47  * equivalent IntraVM Server implementation. An easy way for an
48  * implementation to determine which VM it is in is to simply
49  * set a system variable that is only present in the Application
50  * Server's VM.
51  * <p>
52  * This is identical to how the IntraVM Server replaces its
53  * javax.ejb.* interface implementations with those created by
54  * the ApplicationServer when objects are leaving the local VM.
55  * <p>
56  *
57  * @author <a HREF="mailto=david.blevins@visi.com">David Blevins</a>
58  * @version $Revision: 1096 $ $Date: 2004-03-26 13:41:16 -0800 (Fri, 26 Mar 2004) $
59  */

60 public class IntraVmServer implements org.openejb.spi.ApplicationServer{
61     
62     
63     public EJBMetaData JavaDoc getEJBMetaData(ProxyInfo pi) {
64         org.openejb.DeploymentInfo di = pi.getDeploymentInfo();
65         IntraVmMetaData metaData = new IntraVmMetaData(di.getHomeInterface(), di.getRemoteInterface(),di.getComponentType());
66         
67         metaData.setEJBHome( getEJBHome(pi) );
68         return metaData;
69     }
70     
71     
72     public Handle JavaDoc getHandle(ProxyInfo pi) {
73         return new IntraVmHandle(getEJBObject(pi));
74     }
75     
76     public HomeHandle JavaDoc getHomeHandle(ProxyInfo pi) {
77         return new IntraVmHandle(getEJBHome(pi));
78     }
79     
80     public EJBObject JavaDoc getEJBObject(ProxyInfo pi) {
81         EjbHomeProxyHandler handler = null;
82         return (EJBObject JavaDoc)getEjbHomeHandler(pi).createProxy(pi);
83     }
84     
85     
86     public EJBHome JavaDoc getEJBHome(ProxyInfo pi) {
87         
88         if (pi.getDeploymentInfo() instanceof org.openejb.core.DeploymentInfo) {
89             org.openejb.core.DeploymentInfo coreDeployment = (org.openejb.core.DeploymentInfo) pi.getDeploymentInfo();
90             return coreDeployment.getEJBHome();
91         
92         } else {
93             try{
94                 Class JavaDoc[] interfaces = new Class JavaDoc[]{ pi.getDeploymentInfo().getHomeInterface(), org.openejb.core.ivm.IntraVmProxy.class };
95                 return (javax.ejb.EJBHome JavaDoc)ProxyManager.newProxyInstance( interfaces , getEjbHomeHandler(pi) );
96             }catch(Exception JavaDoc e){
97                 throw new RuntimeException JavaDoc("Can't create EJBHome stub" + e.getMessage());
98             }
99         }
100     }
101
102     private EjbHomeProxyHandler getEjbHomeHandler(ProxyInfo pi){
103         
104         switch (pi.getDeploymentInfo().getComponentType()) {
105             
106             case org.openejb.DeploymentInfo.BMP_ENTITY:
107             case org.openejb.DeploymentInfo.CMP_ENTITY:
108                 return new EntityEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID());
109             
110             case org.openejb.DeploymentInfo.STATEFUL:
111                 return new StatefulEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID());
112             
113             case org.openejb.DeploymentInfo.STATELESS:
114                 return new StatelessEjbHomeHandler(pi.getBeanContainer(),pi.getPrimaryKey(),pi.getDeploymentInfo().getDeploymentID());
115             default:
116                 throw new RuntimeException JavaDoc("Unknown EJB type: "+pi.getDeploymentInfo());
117         }
118     }
119 }
120
Popular Tags