dain        2006/02/01 06:50:09

  Modified:    modules/core/src/java/org/openejb/server/ejbd
                        CallContext.java ClientObjectFactory.java
                        EJBInvocationStream.java EJBObjectInputStream.java
                        EjbDaemon.java EjbRequestHandler.java
                        EjbServer.java EjbServerGBean.java
                        JndiRequestHandler.java
  Added:       modules/core/src/java/org/openejb/server/ejbd
                        EjbInvocationStream.java
  Log:

  Major refactor
  Split container into an object to represent a deployed ejb and a set of 
shared containers which process invocations
  Introduced interface between CMP container and CMP engine
  
  Revision  Changes    Path
  1.3       +5 -17     
openejb/modules/core/src/java/org/openejb/server/ejbd/CallContext.java
  
  Index: CallContext.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/CallContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CallContext.java  10 Mar 2004 09:20:20 -0000      1.2
  +++ CallContext.java  1 Feb 2006 11:50:09 -0000       1.3
  @@ -44,7 +44,7 @@
    */
   package org.openejb.server.ejbd;
   
  -import org.openejb.EJBContainer;
  +import org.openejb.EjbDeployment;
   import org.openejb.client.EJBRequest;
   import org.openejb.util.FastThreadLocal;
   
  @@ -62,7 +62,7 @@
       /**
        * The container of the bean executed
        */
  -    protected EJBContainer container;
  +    protected EjbDeployment container;
   
       /**
        * The EJBRequest object from the client
  @@ -85,26 +85,20 @@
       
       /**
        * Returns the EJBContainer assigned to this CallContext
  -     * 
  -     * @return 
        */
  -    public EJBContainer getContainer() {
  +    public EjbDeployment getContainer() {
           return container;
       }
       
       /**
        * Sets the EJBContainer assigned to this CallContext
  -     * 
  -     * @param info
        */
  -    public void setContainer(EJBContainer container) {
  +    public void setContainer(EjbDeployment container) {
           this.container = container;
       }
       
       /**
        * Returns the EJBRequest this thread is satisfying.
  -     * 
  -     * @return 
        */
       public EJBRequest getEJBRequest(){
           return request;
  @@ -112,8 +106,6 @@
       
       /**
        * Sets the EJBRequest this thread is satisfying.
  -     * 
  -     * @param request
        */
       public void setEJBRequest(EJBRequest request){
           this.request = request;
  @@ -122,8 +114,6 @@
       /**
        * Sets the CallContext assigned to the current thread with the 
CallContext
        * instance passed in
  -     * 
  -     * @param ctx
        */
       public static void setCallContext(CallContext ctx) {
           if ( ctx == null ) {
  @@ -136,8 +126,6 @@
       
       /**
        * Gets the CallContext assigned to the current thread
  -     * 
  -     * @return 
        */
       public static CallContext getCallContext( ) {
           CallContext ctx = (CallContext)threads.get();
  
  
  
  1.9       +6 -6      
openejb/modules/core/src/java/org/openejb/server/ejbd/ClientObjectFactory.java
  
  Index: ClientObjectFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/ClientObjectFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ClientObjectFactory.java  21 Dec 2005 14:21:53 -0000      1.8
  +++ ClientObjectFactory.java  1 Feb 2006 11:50:09 -0000       1.9
  @@ -46,7 +46,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.openejb.ContainerIndex;
  +import org.openejb.DeploymentIndex;
   import org.openejb.client.EJBHomeHandle;
   import org.openejb.client.EJBHomeHandler;
   import org.openejb.client.EJBMetaDataImpl;
  @@ -62,7 +62,7 @@
    * 
    */
   class ClientObjectFactory implements org.openejb.spi.ApplicationServer {
  -    private final ContainerIndex containerIndex;
  +    private final DeploymentIndex deploymentIndex;
       private static Log log = LogFactory.getLog(ClientObjectFactory.class);
        private static final int PORT;
        private static final String IP;
  @@ -86,8 +86,8 @@
   
       protected ServerMetaData[] servers;
   
  -    public ClientObjectFactory(ContainerIndex containerIndex) throws 
Exception {
  -        this.containerIndex = containerIndex;
  +    public ClientObjectFactory(DeploymentIndex deploymentIndex) throws 
Exception {
  +        this.deploymentIndex = deploymentIndex;
           servers = new ServerMetaData[] {new ServerMetaData("BOOT", 
ClientObjectFactory.IP, ClientObjectFactory.PORT)};
       }
   
  @@ -172,7 +172,7 @@
       }
   
       private int getContainerId(ProxyInfo info) {
  -        return containerIndex.getContainerIndex(info.getContainerID());
  +        return deploymentIndex.getDeploymentIndex(info.getContainerID());
       }
   
       /**
  
  
  
  1.7       +18 -8     
openejb/modules/core/src/java/org/openejb/server/ejbd/EJBInvocationStream.java
  
  Index: EJBInvocationStream.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EJBInvocationStream.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EJBInvocationStream.java  21 Jun 2005 21:16:59 -0000      1.6
  +++ EJBInvocationStream.java  1 Feb 2006 11:50:09 -0000       1.7
  @@ -54,32 +54,42 @@
   import org.apache.geronimo.transaction.context.TransactionContext;

   import org.openejb.EJBInstanceContext;

   import org.openejb.EJBInterfaceType;

  -import org.openejb.EJBInvocation;

  -import org.openejb.EJBInvocationImpl;

  +import org.openejb.EjbInvocation;

  +import org.openejb.EjbInvocationImpl;

  +import org.openejb.ExtendedEjbDeployment;

   import org.openejb.corba.ORBRef;

   import org.openejb.client.EJBRequest;

   

  -public class EJBInvocationStream extends EJBRequest implements EJBInvocation 
{

  +public class EjbInvocationStream extends EJBRequest implements EjbInvocation 
{

  +    // The container that we are invoking, this is set in the container 
before sending the invocation to the interceptor stack

  +    private transient ExtendedEjbDeployment ejbDeployment;

   

       private ObjectInput in;

   

  -    private final EJBInvocation invocationState = new EJBInvocationImpl();

  +    private final EjbInvocation invocationState = new EjbInvocationImpl();

       private EJBInterfaceType interfaceType;

   

       private int methodIndex = -1;

   

  -    public EJBInvocationStream() {

  +    public EjbInvocationStream() {

           super();

       }

   

  -    public EJBInvocationStream(ORBRef orbRef) {

  +    public EjbInvocationStream(ORBRef orbRef) {

           super(orbRef);

       }

   

  -    public EJBInvocationStream(int requestMethod) {

  +    public EjbInvocationStream(int requestMethod) {

           super(requestMethod);

       }

   

  +    public ExtendedEjbDeployment getEjbDeployment() {

  +        return ejbDeployment;

  +    }

  +

  +    public void setEjbDeployment(ExtendedEjbDeployment ejbDeployment) {

  +        this.ejbDeployment = ejbDeployment;

  +    }

   

       public Object[] getArguments() {

           return getMethodParameters();

  
  
  
  1.5       +3 -1      
openejb/modules/core/src/java/org/openejb/server/ejbd/EJBObjectInputStream.java
  
  Index: EJBObjectInputStream.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EJBObjectInputStream.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EJBObjectInputStream.java 5 Feb 2005 04:23:48 -0000       1.4
  +++ EJBObjectInputStream.java 1 Feb 2006 11:50:09 -0000       1.5
  @@ -50,6 +50,8 @@
   import java.io.ObjectStreamClass;

   

   import org.apache.geronimo.kernel.ClassLoading;

  +import org.apache.geronimo.kernel.ClassLoading;

  +import org.apache.geronimo.kernel.ClassLoading;

   

   public class EJBObjectInputStream extends ObjectInputStream {

   

  
  
  
  1.9       +7 -7      
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbDaemon.java
  
  Index: EjbDaemon.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbDaemon.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EjbDaemon.java    4 Dec 2005 02:37:53 -0000       1.8
  +++ EjbDaemon.java    1 Feb 2006 11:50:09 -0000       1.9
  @@ -60,7 +60,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import org.openejb.ContainerIndex;
  +import org.openejb.DeploymentIndex;
   import org.openejb.client.RequestMethods;
   import org.openejb.client.ResponseCodes;
   import org.openejb.client.ProtocolMetaData;
  @@ -90,15 +90,15 @@
       private final AuthRequestHandler authHandler;
   
       private EjbDaemon() throws Exception {
  -        this(ContainerIndex.getInstance(), null);
  +        this(DeploymentIndex.getInstance(), null);
       }
   
  -    public EjbDaemon(ContainerIndex containerIndex, Collection orbRefs) 
throws Exception {
  -        clientObjectFactory = new ClientObjectFactory(containerIndex);
  +    public EjbDaemon(DeploymentIndex deploymentIndex, Collection orbRefs) 
throws Exception {
  +        clientObjectFactory = new ClientObjectFactory(deploymentIndex);
   
           // Request Handlers
  -        ejbHandler = new EjbRequestHandler(containerIndex, orbRefs);
  -        jndiHandler = new JndiRequestHandler(containerIndex);
  +        ejbHandler = new EjbRequestHandler(deploymentIndex, orbRefs);
  +        jndiHandler = new JndiRequestHandler(deploymentIndex);
           authHandler = new AuthRequestHandler();
       }
   
  
  
  
  1.25      +21 -20    
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbRequestHandler.java
  
  Index: EjbRequestHandler.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbRequestHandler.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- EjbRequestHandler.java    21 Dec 2005 14:21:53 -0000      1.24
  +++ EjbRequestHandler.java    1 Feb 2006 11:50:09 -0000       1.25
  @@ -60,9 +60,10 @@
   import org.apache.geronimo.core.service.InvocationResult;
   import org.apache.geronimo.security.ContextManager;
   import org.apache.geronimo.security.IdentificationPrincipal;
  -import org.openejb.ContainerIndex;
  -import org.openejb.EJBContainer;
  +import org.openejb.DeploymentIndex;
  +import org.openejb.RpcEjbDeployment;
   import org.openejb.InvalidateReferenceException;
  +import org.openejb.EjbDeployment;
   import org.openejb.corba.ORBRef;
   import org.openejb.client.EJBRequest;
   import org.openejb.client.EJBResponse;
  @@ -76,17 +77,17 @@
   class EjbRequestHandler implements ResponseCodes, RequestMethods {
   
       private static final Log log = 
LogFactory.getLog(EjbRequestHandler.class);
  -    private final ContainerIndex containerIndex;
  +    private final DeploymentIndex deploymentIndex;
       private final Collection orbRefs;
   
   
  -    EjbRequestHandler(ContainerIndex containerIndex, Collection orbRefs) {
  +    EjbRequestHandler(DeploymentIndex deploymentIndex, Collection orbRefs) {
           this.orbRefs = orbRefs;
   
  -        if (containerIndex == null) {
  -            containerIndex = ContainerIndex.getInstance();
  +        if (deploymentIndex == null) {
  +            deploymentIndex = DeploymentIndex.getInstance();
           }
  -        this.containerIndex = containerIndex;
  +        this.deploymentIndex = deploymentIndex;
       }
   
   
  @@ -101,7 +102,7 @@
                   orbRef = (ORBRef) iterator.next();
               }
           }
  -        EJBInvocationStream req = new EJBInvocationStream(orbRef);
  +        EjbInvocationStream req = new EjbInvocationStream(orbRef);
   
           EJBResponse res = new EJBResponse();
   
  @@ -135,7 +136,7 @@
           }
   
           CallContext call = null;
  -        EJBContainer container = null;
  +        RpcEjbDeployment container = null;
           ClassLoader oldClassLoader = 
Thread.currentThread().getContextClassLoader();
           try {
               try {
  @@ -163,7 +164,7 @@
                   ContextManager.setCurrentCaller(subject);
                   ContextManager.setNextCaller(subject);
   
  -                log.debug("setting cl=" + cl + " for " + 
container.getContainerID());
  +                log.debug("setting cl=" + cl + " for " + 
container.getContainerId());
               } catch (RemoteException e) {
                   replyWithFatalError
                           (out, e, "No such deployment");
  @@ -287,7 +288,7 @@
       private Object invoke(EJBRequest req, EJBResponse res) throws Throwable {
   
           CallContext call = CallContext.getCallContext();
  -        EJBContainer container = call.getContainer();
  +        EjbDeployment container = call.getContainer();
   
           // Prepare yourself ...
           // for you are about to enter ...
  @@ -295,7 +296,7 @@
   
           InvocationResult result = null;
           try {
  -            result = container.invoke((EJBInvocationStream) req);
  +            result = container.invoke((EjbInvocationStream) req);
           } catch (Throwable t) {
               RemoteException re;
               if (t instanceof RemoteException) {
  @@ -531,16 +532,16 @@
       }
   
   
  -    private EJBContainer getContainer(EJBRequest req) throws RemoteException 
{
  +    private RpcEjbDeployment getContainer(EJBRequest req) throws 
RemoteException {
   
  -        EJBContainer container = null;
  +        RpcEjbDeployment container = null;
   
           if (req.getContainerCode() > 0) {
  -            container = containerIndex.getContainer(req.getContainerCode());
  +            container = 
deploymentIndex.getDeployment(req.getContainerCode());
               if (container == null) {
                   throw new RemoteException("The deployement with this ID is 
null");
               }
  -            req.setContainerID((String) container.getContainerID());
  +            req.setContainerID((String) container.getContainerId());
               return container;
           }
   
  @@ -549,7 +550,7 @@
           }
   
   
  -        int idCode = containerIndex.getContainerIndex(req.getContainerID());
  +        int idCode = 
deploymentIndex.getDeploymentIndex(req.getContainerID());
   
           if (idCode == -1) {
               throw new RemoteException("No such deployment id and code: id=" 
+ req.getContainerID() + ": code=" + req.getContainerCode());
  @@ -557,11 +558,11 @@
   
           req.setContainerCode(idCode);
   
  -        if (req.getContainerCode() < 0 || req.getContainerCode() >= 
containerIndex.length()) {
  +        if (req.getContainerCode() < 0 || req.getContainerCode() >= 
deploymentIndex.length()) {
               throw new RemoteException("Invalid deployment id and code: id=" 
+ req.getContainerID() + ": code=" + req.getContainerCode());
           }
   
  -        container = containerIndex.getContainer(req.getContainerCode());
  +        container = deploymentIndex.getDeployment(req.getContainerCode());
           if (container == null) {
               throw new RemoteException("The deployement with this ID is 
null");
           }
  
  
  
  1.9       +4 -4      
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbServer.java
  
  Index: EjbServer.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbServer.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EjbServer.java    17 Sep 2005 22:18:19 -0000      1.8
  +++ EjbServer.java    1 Feb 2006 11:50:09 -0000       1.9
  @@ -52,7 +52,7 @@
   
   import org.activeio.xnet.ServerService;
   import org.activeio.xnet.ServiceException;
  -import org.openejb.ContainerIndex;
  +import org.openejb.DeploymentIndex;
   import org.openejb.OpenEJB;
   import org.openejb.client.EJBObjectProxyHandle;
   import org.openejb.server.ServerFederation;
  @@ -75,8 +75,8 @@
           ejbDaemon = EjbDaemon.getEjbDaemon();
       }
   
  -    public EjbServer(ContainerIndex containerIndex, Collection orbRefs) 
throws Exception {
  -        ejbDaemon = new EjbDaemon(containerIndex, orbRefs);
  +    public EjbServer(DeploymentIndex deploymentIndex, Collection orbRefs) 
throws Exception {
  +        ejbDaemon = new EjbDaemon(deploymentIndex, orbRefs);
       }
   
       public void init(Properties props) throws Exception {
  
  
  
  1.8       +5 -5      
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbServerGBean.java
  
  Index: EjbServerGBean.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbServerGBean.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EjbServerGBean.java       1 Dec 2005 08:34:52 -0000       1.7
  +++ EjbServerGBean.java       1 Feb 2006 11:50:09 -0000       1.8
  @@ -54,7 +54,7 @@
   import org.apache.geronimo.kernel.GBeanNotFoundException;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.jmx.JMXUtil;
  -import org.openejb.ContainerIndex;
  +import org.openejb.DeploymentIndex;
   import org.openejb.corba.ORBRef;
   import org.activeio.xnet.SocketService;
   
  @@ -66,10 +66,10 @@
           GBeanInfoBuilder infoFactory = 
GBeanInfoBuilder.createStatic(EjbServerGBean.class, EjbServer.class);
   
           infoFactory.addInterface(SocketService.class);
  -        infoFactory.addReference("ContainerIndex", ContainerIndex.class, 
NameFactory.GERONIMO_SERVICE);
  +        infoFactory.addReference("DeploymentIndex", DeploymentIndex.class, 
NameFactory.GERONIMO_SERVICE);
           infoFactory.addReference("ORBRefs", ORBRef.class, 
NameFactory.CORBA_SERVICE);
   
  -        infoFactory.setConstructor(new String[]{"ContainerIndex", 
"ORBRefs"});
  +        infoFactory.setConstructor(new String[]{"DeploymentIndex", 
"ORBRefs"});
   
           GBEAN_INFO = infoFactory.getBeanInfo();
       }
  @@ -89,7 +89,7 @@
           ObjectName gbeanName = 
JMXUtil.getObjectName("openejb:type=EjbServer,name="+name);
   
           GBeanData gbean = new GBeanData(gbeanName, 
EjbServerGBean.GBEAN_INFO);
  -        gbean.setReferencePattern("ContainerIndex", containerIndex);
  +        gbean.setReferencePattern("DeploymentIndex", containerIndex);
   
           return gbean;
       }
  
  
  
  1.14      +9 -9      
openejb/modules/core/src/java/org/openejb/server/ejbd/JndiRequestHandler.java
  
  Index: JndiRequestHandler.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/JndiRequestHandler.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JndiRequestHandler.java   27 Jul 2005 06:39:02 -0000      1.13
  +++ JndiRequestHandler.java   1 Feb 2006 11:50:09 -0000       1.14
  @@ -53,8 +53,8 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.kernel.KernelRegistry;
  -import org.openejb.ContainerIndex;
  -import org.openejb.EJBContainer;
  +import org.openejb.DeploymentIndex;
  +import org.openejb.RpcEjbDeployment;
   import org.openejb.client.EJBMetaDataImpl;
   import org.openejb.client.JNDIRequest;
   import org.openejb.client.JNDIResponse;
  @@ -66,11 +66,11 @@
    */
   class JndiRequestHandler implements ResponseCodes, RequestMethods {
   
  -    private final ContainerIndex containerIndex;
  +    private final DeploymentIndex deploymentIndex;
       private static final Log log = 
LogFactory.getLog(JndiRequestHandler.class);
   
  -    JndiRequestHandler(ContainerIndex containerIndex) throws NamingException 
{
  -        this.containerIndex = containerIndex;
  +    JndiRequestHandler(DeploymentIndex deploymentIndex) throws 
NamingException {
  +        this.deploymentIndex = deploymentIndex;
       }
   
       public void processRequest(ObjectInputStream in, ObjectOutputStream out) 
{
  @@ -165,13 +165,13 @@
                   throw (Exception)new NamingException("Unable to retrieve 
context for module: "+req.getClientModuleID()).initCause(e);
               }
           } else {
  -            int index = containerIndex.getContainerIndexByJndiName(name);
  +            int index = deploymentIndex.getDeploymentIndexByJndiName(name);
               if (index <= 0) {
                   // name not found... check if an object name was sent 
directly
  -                index = containerIndex.getContainerIndex(name);
  +                index = deploymentIndex.getDeploymentIndex(name);
               }
               if (index > 0) {
  -                EJBContainer deployment = containerIndex.getContainer(index);
  +                RpcEjbDeployment deployment = 
deploymentIndex.getDeployment(index);
                   ProxyInfo info = deployment.getProxyInfo();
   
                   res.setResponseCode(JNDI_EJBHOME);
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbInvocationStream.java
  
  Index: EjbInvocationStream.java
  ===================================================================
  /**

   * Redistribution and use of this software and associated documentation

   * ("Software"), with or without modification, are permitted provided

   * that the following conditions are met:

   *

   * 1. Redistributions of source code must retain copyright

   *    statements and notices.  Redistributions must also contain a

   *    copy of this document.

   *

   * 2. Redistributions in binary form must reproduce the

   *    above copyright notice, this list of conditions and the

   *    following disclaimer in the documentation and/or other

   *    materials provided with the distribution.

   *

   * 3. The name "OpenEJB" must not be used to endorse or promote

   *    products derived from this Software without prior written

   *    permission of The OpenEJB Group.  For written permission,

   *    please contact [EMAIL PROTECTED]

   *

   * 4. Products derived from this Software may not be called "OpenEJB"

   *    nor may "OpenEJB" appear in their names without prior written

   *    permission of The OpenEJB Group. OpenEJB is a registered

   *    trademark of The OpenEJB Group.

   *

   * 5. Due credit should be given to the OpenEJB Project

   *    (http://openejb.org/).

   *

   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS

   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT

   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL

   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,

   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,

   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)

   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED

   * OF THE POSSIBILITY OF SUCH DAMAGE.

   *

   * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.

   *

   * $Id: EjbInvocationStream.java,v 1.1 2006/02/01 11:50:09 dain Exp $

   */

  package org.openejb.server.ejbd;

  

  import java.io.IOException;

  import java.io.ObjectInput;

  import java.lang.reflect.Method;

  

  import org.apache.geronimo.core.service.InvocationKey;

  import org.apache.geronimo.core.service.InvocationResult;

  import org.apache.geronimo.core.service.SimpleInvocationResult;

  import org.apache.geronimo.transaction.context.TransactionContext;

  import org.openejb.EJBInstanceContext;

  import org.openejb.EJBInterfaceType;

  import org.openejb.EjbInvocation;

  import org.openejb.EjbInvocationImpl;

  import org.openejb.ExtendedEjbDeployment;

  import org.openejb.corba.ORBRef;

  import org.openejb.client.EJBRequest;

  

  public class EjbInvocationStream extends EJBRequest implements EjbInvocation {

      // The container that we are invoking, this is set in the container 
before sending the invocation to the interceptor stack

      private transient ExtendedEjbDeployment ejbDeployment;

  

      private ObjectInput in;

  

      private final EjbInvocation invocationState = new EjbInvocationImpl();

      private EJBInterfaceType interfaceType;

  

      private int methodIndex = -1;

  

      public EjbInvocationStream() {

          super();

      }

  

      public EjbInvocationStream(ORBRef orbRef) {

          super(orbRef);

      }

  

      public EjbInvocationStream(int requestMethod) {

          super(requestMethod);

      }

  

      public ExtendedEjbDeployment getEjbDeployment() {

          return ejbDeployment;

      }

  

      public void setEjbDeployment(ExtendedEjbDeployment ejbDeployment) {

          this.ejbDeployment = ejbDeployment;

      }

  

      public Object[] getArguments() {

          return getMethodParameters();

      }

  

      public Object getId() {

          return getPrimaryKey();

      }

  

      public int getMethodIndex() {

          return methodIndex;

      }

  

      public EJBInterfaceType getType() {

          return interfaceType;

      }

  

      public Class getMethodClass() {

          checkState();

          return super.getMethodClass();

      }

  

      public Method getMethodInstance() {

          checkState();

          return super.getMethodInstance();

      }

  

      public String getMethodName() {

          checkState();

          return super.getMethodName();

      }

  

      public Object[] getMethodParameters() {

          checkState();

          return super.getMethodParameters();

      }

  

      public Class[] getMethodParamTypes() {

          checkState();

          return super.getMethodParamTypes();

      }

  

      public Object getPrimaryKey() {

          checkState();

          return super.getPrimaryKey();

      }

  

      public void readExternal(ObjectInput in)

      throws IOException, ClassNotFoundException {

          clearState();

  

          this.in = in;

  

          readRequestMethod(in);

  

          readContainerId(in);

  

          readClientIdentity(in);

  

          switch (super.getRequestMethod()){

              case EJB_HOME_METHOD:

              case EJB_HOME_CREATE:

              case EJB_HOME_FIND:

              case EJB_HOME_GET_EJB_META_DATA:

              case EJB_HOME_GET_HOME_HANDLE:

              case EJB_HOME_REMOVE_BY_HANDLE:

              case EJB_HOME_REMOVE_BY_PKEY:

                  interfaceType = EJBInterfaceType.HOME; break;

              default:

                  interfaceType = EJBInterfaceType.REMOTE;

          }

  //        finishReadExternal();

     }

  

      private void checkState(){

          if (super.getMethodInstance() == null){

              try {

                  finishReadExternal();

              } catch (IOException e) {

                  IllegalStateException ise = new 
IllegalStateException("Invalid EJBRequest stream.");

                  ise.initCause(e);

                  throw ise;

              } catch (ClassNotFoundException e) {

  //                IllegalAccessError iae = new IllegalAccessError("Class only 
accessible from classloader of an EJBContainer.");

                  RuntimeException iae = new RuntimeException(e);

  //                iae.initCause(e);

                  throw iae;

              }

          }

      }

  

      private void finishReadExternal()

      throws IOException, ClassNotFoundException {

          readPrimaryKey(in);

  

          readMethod(in);

  

          readMethodParameters(in);

  

          loadMethodInstance();

      }

  

      public Object get(InvocationKey arg0) {

          return invocationState.get(arg0);

      }

  

      public void put(InvocationKey arg0, Object arg1) {

          invocationState.put(arg0, arg1);

      }

  

      public void setEJBInstanceContext(EJBInstanceContext instanceContext) {

          invocationState.setEJBInstanceContext(instanceContext);

      }

  

      public void setTransactionContext(TransactionContext transactionContext) {

          invocationState.setTransactionContext(transactionContext);

      }

  

      public EJBInstanceContext getEJBInstanceContext() {

          return invocationState.getEJBInstanceContext();

      }

  

      public TransactionContext getTransactionContext() {

          return invocationState.getTransactionContext();

      }

  

      public void setMethodIndex(int methodIndex) {

          this.methodIndex = methodIndex;

      }

  

      public InvocationResult createResult(Object object) {

          return new SimpleInvocationResult(true, object);

      }

  

      public InvocationResult createExceptionResult(Exception exception) {

          return new SimpleInvocationResult(false, exception);

      }

  

  }

  
  
  

Reply via email to