tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1608094 - in /tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb: core/ivm/EjbHomeProxyHandler.java core/ivm/EjbObjectProxyHandler.java threads/task/CUTask.java
Date Sat, 05 Jul 2014 18:15:12 GMT
Author: rmannibucau
Date: Sat Jul  5 18:15:12 2014
New Revision: 1608094

URL: http://svn.apache.org/r1608094
Log:
sharing push/pop context for tasks in another thread instead of having it 3 times (main goal
of important concurrency utilities)

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java?rev=1608094&r1=1608093&r2=1608094&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbHomeProxyHandler.java
Sat Jul  5 18:15:12 2014
@@ -37,6 +37,7 @@ import org.apache.openejb.core.stateless
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ApplicationServer;
 import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.threads.task.CUCallable;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.proxy.LocalBeanProxyFactory;
@@ -323,44 +324,17 @@ public abstract class EjbHomeProxyHandle
             final ThreadContext currentCtx = ThreadContext.getThreadContext();
             final AsynchronousPool asynchronousPool = beanContext.getModuleContext().getAppContext().getAsynchronousPool();
 
-            return asynchronousPool.invoke(new Callable<Object>() {
+            return asynchronousPool.invoke(new CUCallable<Object>(new Callable<Object>()
{
                 @Override
                 public Object call() throws Exception {
-                    final Object threadState;
-                    if (associate) {
-                        //noinspection unchecked
-                        securityService.associate(securityState);
-                        threadState = null;
-                    } else {
-                        threadState = securityService.currentState();
-                        securityService.setState(securityState);
-                    }
-
-                    final ThreadContext oldCtx; // ensure context is the same as for the
caller
-                    if (currentCtx != null) {
-                        oldCtx = ThreadContext.enter(new ThreadContext(currentCtx));
-                    } else {
-                        oldCtx = null;
-                    }
                     try {
                         return homeMethodInvoke(interfce, method, args);
                     } catch (final ApplicationException ae) {
-
                         logger.error("EjbHomeProxyHandler: Asynchronous call to '" + interfce.getSimpleName()
+ "' on '" + method.getName() + "' failed", ae);
-
                         throw ae;
-                    } finally {
-                        if (oldCtx != null) {
-                            ThreadContext.exit(oldCtx);
-                        }
-                        if (!associate) {
-                            securityService.setState(threadState);
-                        } else {
-                            securityService.disassociate();
-                        }
                     }
                 }
-            }, method.getReturnType() == Void.TYPE);
+            }), method.getReturnType() == Void.TYPE);
         } else {
             return homeMethodInvoke(interfce, method, args);
         }

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java?rev=1608094&r1=1608093&r2=1608094&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
Sat Jul  5 18:15:12 2014
@@ -31,6 +31,7 @@ import org.apache.openejb.core.ThreadCon
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ApplicationServer;
 import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.threads.task.CUCallable;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
@@ -260,45 +261,17 @@ public abstract class EjbObjectProxyHand
             final ThreadContext threadContext = ThreadContext.getThreadContext();
             final AsynchronousPool asynchronousPool = beanContext.getModuleContext().getAppContext().getAsynchronousPool();
 
-            return asynchronousPool.invoke(new Callable<Object>() {
+            return asynchronousPool.invoke(new CUCallable<Object>(new Callable<Object>()
{
                 @Override
                 public Object call() throws Exception {
-                    final Object threadState;
-                    if (associate) {
-                        //noinspection unchecked
-                        securityService.associate(securityState);
-                        threadState = null;
-                    } else {
-                        threadState = securityService.currentState();
-                        securityService.setState(securityState);
-                    }
-
-                    final ThreadContext oldCtx; // ensure context is the same as for the
caller
-                    if (threadContext != null) {
-                        oldCtx = ThreadContext.enter(new ThreadContext(threadContext));
-                    } else {
-                        oldCtx = null;
-                    }
-
                     try {
                         return synchronizedBusinessMethod(interfce, method, args);
                     } catch (final ApplicationException ae) {
-
                         logger.error("EjbObjectProxyHandler: Asynchronous call to '" + interfce.getSimpleName()
+ "' on '" + method.getName() + "' failed", ae);
-
                         throw ae;
-                    } finally {
-                        if (oldCtx != null) {
-                            ThreadContext.exit(oldCtx);
-                        }
-                        if (!associate) {
-                            securityService.setState(threadState);
-                        } else {
-                            securityService.disassociate();
-                        }
                     }
                 }
-            }, method.getReturnType() == Void.TYPE);
+            }), method.getReturnType() == Void.TYPE);
         } else {
             return synchronizedBusinessMethod(interfce, method, args);
         }

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java?rev=1608094&r1=1608093&r2=1608094&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
Sat Jul  5 18:15:12 2014
@@ -139,7 +139,9 @@ public abstract class CUTask<T> extends 
             final ThreadContext oldCtx;
             if (threadContext != null) {
                 final ThreadContext newContext = new ThreadContext(threadContext);
-                newContext.set(AbstractSecurityService.ProvidedSecurityContext.class, new
AbstractSecurityService.ProvidedSecurityContext(securityContext));
+                if (securityContext != null) {
+                    newContext.set(AbstractSecurityService.ProvidedSecurityContext.class,
new AbstractSecurityService.ProvidedSecurityContext(securityContext));
+                }
                 oldCtx = ThreadContext.enter(newContext);
             } else {
                 oldCtx = null;



Mime
View raw message