[jboss-cvs] JBossAS SVN: r106978 - in projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3: session and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 21 09:46:27 EDT 2010


Author: jaikiran
Date: 2010-07-21 09:46:26 -0400 (Wed, 21 Jul 2010)
New Revision: 106978

Modified:
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/remoting/IsLocalInterceptor.java
   projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/session/SessionContainer.java
Log:
EJBTHREE-2120 Optionally skip marshalling/unmarshalling of params and return objects for remote business interfaces

Modified: projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/remoting/IsLocalInterceptor.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2010-07-21 13:36:40 UTC (rev 106977)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/remoting/IsLocalInterceptor.java	2010-07-21 13:46:26 UTC (rev 106978)
@@ -21,11 +21,9 @@
  */
 package org.jboss.ejb3.remoting;
 
-import java.io.Serializable;
-import java.util.Map;
-
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aop.util.PayloadKey;
 import org.jboss.ejb3.Container;
 import org.jboss.ejb3.Ejb3Registry;
@@ -33,6 +31,9 @@
 import org.jboss.logging.Logger;
 import org.jboss.serial.io.MarshalledObjectForLocalCalls;
 
+import java.io.IOException;
+import java.io.Serializable;
+
 /**
  * Routes the call to the local container, bypassing further client-side
  * interceptors and any remoting layer, if this interceptor was created 
@@ -53,6 +54,8 @@
 
    public static final String IS_LOCAL = "IS_LOCAL";
    public static final String IS_LOCAL_EXCEPTION = "IS_LOCAL_EXCEPTION";
+
+   private static boolean passByRef = Boolean.getBoolean(IsLocalInterceptor.class.getName() + ".passByRef");
    
    private static final long stamp = System.currentTimeMillis();
    private long marshalledStamp = stamp;
@@ -76,35 +79,41 @@
    
    protected Object invokeLocal(Invocation invocation, Container container) throws Throwable
    {
-      Invocation copy = (Invocation) new MarshalledObjectForLocalCalls(invocation).get();
+      Invocation copy = marshallOrPass(invocation, Invocation.class);
       copy.getMetaData().addMetaData(IS_LOCAL, IS_LOCAL, Boolean.TRUE, PayloadKey.AS_IS);
-      org.jboss.aop.joinpoint.InvocationResponse response = null;
-
-      // Invoke upon the container
-      SessionContainer sc = (SessionContainer) container;
-      response = sc.dynamicInvoke(copy);
-      
-      Map contextInfo = response.getContextInfo();
-      if (contextInfo != null)
+      try
       {
-         MarshalledObjectForLocalCalls wrappedException = (MarshalledObjectForLocalCalls) response.getContextInfo().get(IS_LOCAL_EXCEPTION);
-         if (wrappedException != null)
-         {
-            throw (Throwable) wrappedException.get();
-         }
+         // Invoke upon the container
+         SessionContainer sc = (SessionContainer) container;
+         InvocationResponse response = sc.dynamicInvoke(copy);
+         // it could really have been a copy
+         invocation.setResponseContextInfo(response.getContextInfo());
+         return marshallOrPass(response.getResponse(), Object.class);
       }
-      invocation.setResponseContextInfo(response.getContextInfo());
-      MarshalledObjectForLocalCalls wrapped = (MarshalledObjectForLocalCalls) response.getResponse();
-      Object rtn = null;
-      if (wrapped != null)
+      // TODO: Either Throwable (as it used to be) or Exception (which is better)
+      catch(Throwable t)
       {
-         rtn = wrapped.get();
+         throw marshallOrPass(t, Throwable.class);
       }
-      return rtn;
+      finally
+      {
+         copy.getMetaData().removeMetaData(IS_LOCAL, IS_LOCAL);
+      }
    }
 
    protected boolean isLocal()
    {
       return stamp == marshalledStamp;
    }
+
+   /**
+    * Marshall the obj or pass by ref, based on passByRef.
+    */
+   private static <T> T marshallOrPass(T obj, Class<T> type) throws IOException, ClassNotFoundException
+   {
+      if(passByRef)
+         return obj;
+      else
+         return type.cast(new MarshalledObjectForLocalCalls(obj).get());
+   }
 }

Modified: projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/session/SessionContainer.java
===================================================================
--- projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2010-07-21 13:36:40 UTC (rev 106977)
+++ projects/ejb3/branches/jboss-ejb3-core-1.3/src/main/java/org/jboss/ejb3/session/SessionContainer.java	2010-07-21 13:46:26 UTC (rev 106978)
@@ -583,29 +583,13 @@
 
    public static InvocationResponse marshallException(Invocation invocation, Throwable exception, Map responseContext) throws Throwable
    {
-      if (invocation.getMetaData(IsLocalInterceptor.IS_LOCAL,IsLocalInterceptor.IS_LOCAL) == null) throw exception;
-
-      InvocationResponse response = new InvocationResponse();
-      response.setContextInfo(responseContext);
-
-      response.addAttachment(IsLocalInterceptor.IS_LOCAL_EXCEPTION, new MarshalledObjectForLocalCalls(exception));
-
-      return response;
+      throw exception;
    }
 
    public static InvocationResponse marshallResponse(Invocation invocation, Object rtn, Map responseContext)
            throws java.io.IOException
    {
-      InvocationResponse response;
-      // marshall return value
-      if (rtn != null && invocation.getMetaData(IsLocalInterceptor.IS_LOCAL, IsLocalInterceptor.IS_LOCAL) != null)
-      {
-         response = new InvocationResponse(new MarshalledObjectForLocalCalls(rtn));
-      }
-      else
-      {
-         response = new InvocationResponse(rtn);
-      }
+      InvocationResponse response = new InvocationResponse(rtn);
       response.setContextInfo(responseContext);
       return response;
    }



More information about the jboss-cvs-commits mailing list