You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2012/08/20 02:18:49 UTC

Fwd: svn commit: r1374882 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/org/apache/openejb/async/

Dont we loose the conf by app in the app?

- Romain
---------- Message transféré ----------
De : <db...@apache.org>
Date : 20 août 2012 02:13
Objet : svn commit: r1374882 - in /openejb/trunk/openejb:
container/openejb-core/src/main/java/org/apache/openejb/
container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/
container/openejb-core/src/main/java/org/apache/openejb/async/ contain...
À : <co...@openejb.apache.org>

Author: dblevins
Date: Mon Aug 20 00:12:51 2012
New Revision: 1374882

URL: http://svn.apache.org/viewvc?rev=1374882&view=rev
Log:
OPENEJB-1895 - Refactored @Asynchronous support
TOMEE-382 - configuration for asynch task pool

Added:

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
Modified:

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/AppContext.java

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java

openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/InheritedAppExceptionTest.java

openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/AuthorBean.java

openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/BookBean.java

openejb/trunk/openejb/container/openejb-junit/src/main/java/org/apache/openejb/junit/LocalClientRunner.java

openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/BasicClusterableRequestHandlerTest.java

openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/DeploymentIndexTest.java

Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/AppContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/AppContext.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/AppContext.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/AppContext.java
Mon Aug 20 00:12:51 2012
@@ -16,9 +16,9 @@
  */
 package org.apache.openejb;

+import org.apache.openejb.async.AsynchronousPool;
 import org.apache.openejb.core.WebContext;
 import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.util.DaemonThreadFactory;
 import org.apache.webbeans.config.WebBeansContext;

 import javax.enterprise.inject.spi.BeanManager;
@@ -29,17 +29,10 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;

 /**
  * @version $Rev$ $Date$
-*/
+ */
 public class AppContext extends DeploymentContext {
     private final SystemInstance systemInstance;
     private final ClassLoader classLoader;
@@ -51,23 +44,17 @@ public class AppContext extends Deployme
     private final Collection<Injection> injections = new
HashSet<Injection>();
     private final Map<String, Object> bindings = new HashMap<String,
Object>();

-    private BlockingQueue<Runnable> blockingQueue;
-    private ExecutorService asynchPool;
-
     // TODO perhaps to be deleted
     private final List<BeanContext> beanContexts = new
ArrayList<BeanContext>();
     private final List<WebContext> webContexts = new
ArrayList<WebContext>();

-    public AppContext(String id, SystemInstance systemInstance,
ClassLoader classLoader, Context globalJndiContext, Context appJndiContext,
boolean standaloneModule, int corePoolSize, int maxPoolSize, int keepAlive)
{
+    public AppContext(String id, SystemInstance systemInstance,
ClassLoader classLoader, Context globalJndiContext, Context appJndiContext,
boolean standaloneModule) {
         super(id, systemInstance.getOptions());
         this.classLoader = classLoader;
         this.systemInstance = systemInstance;
         this.globalJndiContext = globalJndiContext;
         this.appJndiContext = appJndiContext;
         this.standaloneModule = standaloneModule;
-        this.blockingQueue = new LinkedBlockingQueue<Runnable>();
-
-        this.asynchPool = new ThreadPoolExecutor(corePoolSize,
maxPoolSize, keepAlive, TimeUnit.SECONDS, blockingQueue, new
DaemonThreadFactory("@Asynch", id));
     }

     public Collection<Injection> getInjections() {
@@ -137,15 +124,7 @@ public class AppContext extends Deployme
         return standaloneModule;
     }

-    /**
-     *  Asynchronous Invocation Thread Pool Methods
-     */
-    public Future<Object> submitTask(Callable<Object> callable){
-        return asynchPool.submit(callable);
+    public AsynchronousPool getAsynchronousPool() {
+        return get(AsynchronousPool.class);
     }
-
-    public boolean removeTask(Runnable task) {
-        return blockingQueue.remove(task);
-    }
-
 }

Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
Mon Aug 20 00:12:51 2012
@@ -40,8 +40,8 @@ import org.apache.openejb.assembler.clas
 import
org.apache.openejb.assembler.classic.event.AssemblerBeforeApplicationDestroyed;
 import org.apache.openejb.assembler.classic.event.AssemblerCreated;
 import org.apache.openejb.assembler.classic.event.AssemblerDestroyed;
-import org.apache.openejb.assembler.classic.util.ServiceInfos;
 import org.apache.openejb.assembler.monitoring.JMXContainer;
+import org.apache.openejb.async.AsynchronousPool;
 import org.apache.openejb.cdi.CdiAppContextsService;
 import org.apache.openejb.cdi.CdiBuilder;
 import org.apache.openejb.cdi.CdiResourceInjectionService;
@@ -180,15 +180,6 @@ public class Assembler extends Assembler

     public static final String OPENEJB_JPA_DEPLOY_TIME_ENHANCEMENT_PROP =
"openejb.jpa.deploy-time-enhancement";

-    public static final String DEFAULT_ASYNCHRONOUS_POOL_ID =
"asynchronous-pool";
-    public static final String ASYNCHRONOUS_POOL_CORE_SIZE =
DEFAULT_ASYNCHRONOUS_POOL_ID + ".core-size";
-    public static final String ASYNCHRONOUS_POOL_MAX_SIZE =
DEFAULT_ASYNCHRONOUS_POOL_ID + ".max-size";
-    public static final String ASYNCHRONOUS_POOL_KEEP_ALIVE =
DEFAULT_ASYNCHRONOUS_POOL_ID + ".keep-alive";
-
-    private static final int DEFAULT_CORE_POOL_SIZE = 10;
-    private static final int DEFAULT_MAX_POOL_SIZE = 20;
-    private static final int DEFAULT_KEEP_ALIVE = 60;
-
     private static final String GLOBAL_UNIQUE_ID = "global";

     Messages messages = new
Messages(Assembler.class.getPackage().getName());
@@ -587,37 +578,15 @@ public class Assembler extends Assembler
                 classLoader =
ClassLoaderUtil.createClassLoader(appInfo.path, new
URL[]{generatedJar.toURI().toURL()}, classLoader);
             }

-
-            // async pool config
-            int corePoolSize = DEFAULT_CORE_POOL_SIZE;
-            int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
-            int keepAlive = DEFAULT_KEEP_ALIVE;
-            ServiceInfo appConfig = ServiceInfos.find(appInfo.services,
appInfo.appId);
-            if (appConfig != null) {
-                corePoolSize =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_CORE_SIZE,
Integer.toString(corePoolSize)).trim());
-                maxPoolSize =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_MAX_SIZE,
Integer.toString(maxPoolSize)).trim());
-                keepAlive =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_KEEP_ALIVE,
Integer.toString(keepAlive)).trim());
-            } else {
-                appConfig = ServiceInfos.find(appInfo.services,
DEFAULT_ASYNCHRONOUS_POOL_ID);
-                if (appConfig != null) {
-                    int l = DEFAULT_ASYNCHRONOUS_POOL_ID.length() + 1;
-                    corePoolSize =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_CORE_SIZE.substring(l),
Integer.toString(corePoolSize)).trim());
-                    maxPoolSize =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_MAX_SIZE.substring(l),
Integer.toString(maxPoolSize)).trim());
-                    keepAlive =
Integer.parseInt(appConfig.properties.getProperty(ASYNCHRONOUS_POOL_KEEP_ALIVE.substring(l),
Integer.toString(keepAlive)).trim());
-                }
-            }
-
-            corePoolSize =
SystemInstance.get().getOptions().get(ASYNCHRONOUS_POOL_CORE_SIZE,
corePoolSize);
-            maxPoolSize =
SystemInstance.get().getOptions().get(ASYNCHRONOUS_POOL_MAX_SIZE,
maxPoolSize);
-            keepAlive =
SystemInstance.get().getOptions().get(ASYNCHRONOUS_POOL_KEEP_ALIVE,
keepAlive);
-
-            final AppContext appContext = new AppContext(appInfo.appId,
SystemInstance.get(), classLoader, globalJndiContext, appJndiContext,
appInfo.standaloneModule, corePoolSize, maxPoolSize, keepAlive);
+            final AppContext appContext = new AppContext(appInfo.appId,
SystemInstance.get(), classLoader, globalJndiContext, appJndiContext,
appInfo.standaloneModule);
             appContext.getInjections().addAll(injections);
             appContext.getBindings().putAll(globalBindings);
             appContext.getBindings().putAll(appBindings);

             containerSystem.addAppContext(appContext);

+            appContext.set(AsynchronousPool.class,
AsynchronousPool.create(appContext));
+
             final Context containerSystemContext =
containerSystem.getJNDIContext();

             if (!SystemInstance.get().hasProperty("openejb.geronimo")) {

Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java?rev=1374882&view=auto
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
(added)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
Mon Aug 20 00:12:51 2012
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.async;
+
+import org.apache.openejb.AppContext;
+import org.apache.openejb.core.ThreadContext;
+import org.apache.openejb.loader.Options;
+import org.apache.openejb.util.DaemonThreadFactory;
+import org.apache.openejb.util.Duration;
+
+import javax.ejb.EJBException;
+import javax.ejb.NoSuchEJBException;
+import java.rmi.NoSuchObjectException;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AsynchronousPool {
+
+    private final BlockingQueue<Runnable> blockingQueue;
+    private final ExecutorService executor;
+
+    public AsynchronousPool(String id, int corePoolSize, int
maximumPoolSize, Duration keepAliveTime) {
+        this.blockingQueue = new LinkedBlockingQueue<Runnable>();
+        this.executor = new ThreadPoolExecutor(
+                corePoolSize,
+                maximumPoolSize,
+                keepAliveTime.getTime(),
+                keepAliveTime.getUnit(), blockingQueue, new
DaemonThreadFactory("@Asynchronous", id));
+    }
+
+    public static AsynchronousPool create(AppContext appContext) {
+        final Options options = appContext.getOptions();
+
+        final String id = appContext.getId();
+        final int corePoolSize =
options.get("AsynchronousPool.CorePoolSize", 10);
+        final int maximumPoolSize =
options.get("AsynchronousPool.MaximumPoolSize", 20);
+        final Duration keepAliveTime =
options.get("AsynchronousPool.KeepAliveTime", new Duration(60,
TimeUnit.SECONDS));
+
+        return new AsynchronousPool(id, corePoolSize, maximumPoolSize,
keepAliveTime);
+    }
+
+    public Object invoke(Callable<Object> callable, boolean isVoid) throws
Throwable {
+        final AtomicBoolean asynchronousCancelled = new
AtomicBoolean(false);
+
+        try {
+
+            final Future<Object> future = executor.submit(new
AsynchronousCall(callable, asynchronousCancelled));
+
+            if (isVoid) return null;
+
+            return new FutureAdapter<Object>(future,
asynchronousCancelled);
+        } catch (RejectedExecutionException e) {
+            throw new EJBException("fail to allocate internal resource to
execute the target task", e);
+        }
+    }
+
+    private class AsynchronousCall implements Callable<Object> {
+
+        private final Callable<Object> callable;
+
+        private final AtomicBoolean asynchronousCancelled;
+
+        private AsynchronousCall(Callable<Object> callable, AtomicBoolean
asynchronousCancelled) {
+            this.callable = callable;
+            this.asynchronousCancelled = asynchronousCancelled;
+        }
+
+        @Override
+        public Object call() throws Exception {
+            try {
+
 ThreadContext.initAsynchronousCancelled(asynchronousCancelled);
+
+                final Object value = callable.call();
+
+                if (value instanceof Future<?>) {
+                    // This is the Future object returned by the bean code
+                    final Future<?> future = (Future<?>) value;
+
+                    return future.get();
+
+                } else {
+
+                    return null;
+                }
+            } finally {
+                ThreadContext.removeAsynchronousCancelled();
+            }
+        }
+    }
+
+    private class FutureAdapter<T> implements Future<T> {
+
+        private final Future<T> target;
+
+        private final AtomicBoolean asynchronousCancelled;
+
+        private volatile boolean canceled;
+
+        public FutureAdapter(Future<T> target, AtomicBoolean
asynchronousCancelled) {
+            this.target = target;
+            this.asynchronousCancelled = asynchronousCancelled;
+        }
+
+        @Override
+        public boolean cancel(boolean mayInterruptIfRunning) {
+            /*In EJB 3.1 spec 3.4.8.1.1
+             *a. If a client calls cancel on its Future object, the
container will attempt to cancel the associated asynchronous invocation
only if that invocation has not already been dispatched.
+             *  There is no guarantee that an asynchronous invocation can
be cancelled, regardless of how quickly cancel is called after the client
receives its Future object.
+             *  If the asynchronous invocation can not be cancelled, the
method must return false.
+             *  If the asynchronous invocation is successfully cancelled,
the method must return true.
+             *b. the meaning of parameter mayInterruptIfRunning is changed.
+             *  So, we should never call cancel(true), or the underlying
Future object will try to interrupt the target thread.
+            */
+            /**
+             * We use our own flag canceled to identify whether the task
is canceled successfully.
+             */
+            if (canceled) {
+                return true;
+            }
+            if (blockingQueue.remove((Runnable) target)) {
+                //We successfully remove the task from the queue
+                canceled = true;
+                return true;
+            } else {
+                //Not find the task in the queue, the status might be
ran/canceled or running
+                //Future.isDone() will return true when the task has been
ran or canceled,
+                //since we never call the Future.cancel method, the isDone
method will only return true when the task has ran
+                if (!target.isDone()) {
+                    //The task is in the running state
+                    asynchronousCancelled.set(mayInterruptIfRunning);
+                }
+                return false;
+            }
+        }
+
+        @Override
+        public T get() throws InterruptedException, ExecutionException {
+            if (canceled) {
+                throw new CancellationException();
+            }
+
+            T object = null;
+
+            try {
+                object = target.get();
+            } catch (Throwable e) {
+                handleException(e);
+            }
+
+            return object;
+        }
+
+        @Override
+        public T get(long timeout, TimeUnit unit) throws
InterruptedException, ExecutionException, TimeoutException {
+            if (canceled) {
+                throw new CancellationException();
+            }
+
+            T object = null;
+
+            try {
+                object = target.get(timeout, unit);
+            } catch (Throwable e) {
+                handleException(e);
+            }
+
+            return object;
+
+        }
+
+        private void handleException(Throwable e) throws
ExecutionException {
+
+            //unwarp the exception to find the root cause
+            while (e.getCause() != null) {
+                e = (Throwable) e.getCause();
+            }
+
+            /*
+             * StatefulContainer.obtainInstance(Object, ThreadContext,
Method)
+             * will return NoSuchObjectException instead of
NoSuchEJBException             *
+             * when it can't obtain an instance.   Actually, the async
client
+             * is expecting a NoSuchEJBException.  Wrap it here as a
workaround.
+             */
+            if (e instanceof NoSuchObjectException) {
+                e = new NoSuchEJBException(e.getMessage(), (Exception) e);
+            }
+
+            boolean isExceptionUnchecked = (e instanceof Error) || (e
instanceof RuntimeException);
+
+            // throw checked excpetion and EJBException directly.
+            if (!isExceptionUnchecked || e instanceof EJBException) {
+                throw new ExecutionException(e);
+            }
+
+            // wrap unchecked exception with EJBException before throwing.
+            throw (e instanceof Exception) ? new ExecutionException(new
EJBException((Exception) e))
+                    : new ExecutionException(new EJBException(new
Exception(e)));
+
+        }
+
+        @Override
+        public boolean isCancelled() {
+            return canceled;
+        }
+
+        @Override
+        public boolean isDone() {
+            if (canceled) {
+                return false;
+            }
+            return target.isDone();
+        }
+    }
+}

Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/EjbObjectProxyHandler.java
Mon Aug 20 00:12:51 2012
@@ -16,10 +16,11 @@
  */
 package org.apache.openejb.core.ivm;

-import org.apache.openejb.AppContext;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.InterfaceType;
+import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.async.AsynchronousPool;
 import org.apache.openejb.core.ServerFederation;
 import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.spi.ApplicationServer;
@@ -232,31 +233,24 @@ public abstract class EjbObjectProxyHand

     protected abstract Object remove(Class interfce, Method method,
Object[] args, Object proxy) throws Throwable;

-    protected Object businessMethod(Class<?> interfce, Method method,
Object[] args, Object proxy) throws Throwable {
-        BeanContext beanContext = getBeanContext();
+    protected Object businessMethod(final Class<?> interfce,final  Method
method,final  Object[] args, Object proxy) throws Throwable {
+        final BeanContext beanContext = getBeanContext();
+        final AsynchronousPool asynchronousPool =
beanContext.getModuleContext().getAppContext().getAsynchronousPool();
+
         if (beanContext.isAsynchronous(method)) {
-            return asynchronizedBusinessMethod(interfce, method, args,
proxy);
+            return asynchronousPool.invoke(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    return synchronizedBusinessMethod(interfce, method,
args);
+                }
+            }, method.getReturnType() == Void.TYPE
+            );
         } else {
-            return synchronizedBusinessMethod(interfce, method, args,
proxy);
-        }
-    }
-
-    protected Object asynchronizedBusinessMethod(Class<?> interfce, Method
method, Object[] args, Object proxy) throws Throwable {
-        BeanContext beanContext = getBeanContext();
-        AtomicBoolean asynchronousCancelled = new AtomicBoolean(false);
-        AsynchronousCall asynchronousCall = new AsynchronousCall(interfce,
method, args, asynchronousCancelled);
-        try {
-            Future<Object> retValue =
beanContext.getModuleContext().getAppContext().submitTask(asynchronousCall);
-            if (method.getReturnType() == Void.TYPE) {
-                return null;
-            }
-            return new FutureAdapter<Object>(retValue,
asynchronousCancelled, beanContext.getModuleContext().getAppContext());
-        } catch (RejectedExecutionException e) {
-            throw new EJBException("fail to allocate internal resource to
execute the target task", e);
+            return synchronizedBusinessMethod(interfce, method, args);
         }
     }

-    protected Object synchronizedBusinessMethod(Class<?> interfce, Method
method, Object[] args, Object proxy) throws Throwable {
+    protected Object synchronizedBusinessMethod(Class<?> interfce, Method
method, Object[] args) throws OpenEJBException {
         return container.invoke(deploymentID, interfaceType, interfce,
method, args, primaryKey);
     }

@@ -272,169 +266,5 @@ public abstract class EjbObjectProxyHand
         return homeHandler.createProxy(primaryKey, mainInterface);
     }

-    private class AsynchronousCall implements Callable<Object> {
-
-        private Class<?> interfce;

-        private Method method;
-
-        private Object[] args;
-
-        private AtomicBoolean asynchronousCancelled;
-
-        public AsynchronousCall(Class<?> interfce, Method method, Object[]
args, AtomicBoolean asynchronousCancelled) {
-            this.interfce = interfce;
-            this.method = method;
-            this.args = args;
-            this.asynchronousCancelled = asynchronousCancelled;
-        }
-
-        @Override
-        public Object call() throws Exception {
-            try {
-
 ThreadContext.initAsynchronousCancelled(asynchronousCancelled);
-                Object retValue = container.invoke(deploymentID,
interfaceType, interfce, method, args, primaryKey);
-                if (retValue == null) {
-                    return null;
-                } else if (retValue instanceof Future<?>) {
-                    //TODO do we need to strictly check AsyncResult  or
just Future ?
-                    Future<?> asyncResult = (Future<?>) retValue;
-                    return asyncResult.get();
-                } else {
-                    // The bean isn't returning the right result!
-                    // We should never arrive here !
-                    return null;
-                }
-            } finally {
-                ThreadContext.removeAsynchronousCancelled();
-            }
-        }
-    }
-
-    private class FutureAdapter<T> implements Future<T> {
-
-        private Future<T> target;
-
-        private AtomicBoolean asynchronousCancelled;
-
-        private AppContext appContext;
-
-        private volatile boolean canceled;
-
-        public FutureAdapter(Future<T> target, AtomicBoolean
asynchronousCancelled, AppContext appContext) {
-            this.target = target;
-            this.asynchronousCancelled = asynchronousCancelled;
-            this.appContext = appContext;
-        }
-
-        @Override
-        public boolean cancel(boolean mayInterruptIfRunning) {
-            /*In EJB 3.1 spec 3.4.8.1.1
-             *a. If a client calls cancel on its Future object, the
container will attempt to cancel the associated asynchronous invocation
only if that invocation has not already been dispatched.
-             *  There is no guarantee that an asynchronous invocation can
be cancelled, regardless of how quickly cancel is called after the client
receives its Future object.
-             *  If the asynchronous invocation can not be cancelled, the
method must return false.
-             *  If the asynchronous invocation is successfully cancelled,
the method must return true.
-             *b. the meaning of parameter mayInterruptIfRunning is changed.
-             *  So, we should never call cancel(true), or the underlying
Future object will try to interrupt the target thread.
-            */
-            /**
-             * We use our own flag canceled to identify whether the task
is canceled successfully.
-             */
-            if(canceled) {
-                return true;
-            }
-            if (appContext.removeTask((Runnable) target)) {
-                //We successfully remove the task from the queue
-                canceled = true;
-                return true;
-            } else {
-                //Not find the task in the queue, the status might be
ran/canceled or running
-                //Future.isDone() will return true when the task has been
ran or canceled,
-                //since we never call the Future.cancel method, the isDone
method will only return true when the task has ran
-                if (!target.isDone()) {
-                    //The task is in the running state
-                    asynchronousCancelled.set(mayInterruptIfRunning);
-                }
-                return false;
-            }
-        }
-
-        @Override
-        public T get() throws InterruptedException, ExecutionException {
-            if(canceled) {
-                throw new CancellationException();
-            }
-
-            T object = null;
-
-            try {
-                object = target.get();
-            } catch (Throwable e) {
-                handleException(e);
-            }
-
-            return object;
-        }
-
-        @Override
-        public T get(long timeout, TimeUnit unit) throws
InterruptedException, ExecutionException, TimeoutException {
-            if (canceled) {
-                throw new CancellationException();
-            }
-
-            T object = null;
-
-            try {
-                object = target.get(timeout, unit);
-            } catch (Throwable e) {
-                handleException(e);
-            }
-
-            return object;
-
-        }
-
-        private void handleException(Throwable e) throws
ExecutionException {
-
-            //unwarp the exception to find the root cause
-            while (e.getCause() != null) {
-                e = (Throwable) e.getCause();
-            }
-
-            /*
-             * StatefulContainer.obtainInstance(Object, ThreadContext,
Method)
-             * will return NoSuchObjectException instead of
NoSuchEJBException             *
-             * when it can't obtain an instance.   Actually, the async
client
-             * is expecting a NoSuchEJBException.  Wrap it here as a
workaround.
-             */
-            if (e instanceof NoSuchObjectException) {
-                e = new NoSuchEJBException(e.getMessage(), (Exception) e);
-            }
-
-            boolean isExceptionUnchecked = (e instanceof Error) || (e
instanceof RuntimeException);
-
-            // throw checked excpetion and EJBException directly.
-            if (!isExceptionUnchecked || e instanceof EJBException) {
-                throw new ExecutionException(e);
-            }
-
-            // wrap unchecked exception with EJBException before throwing.
-            throw (e instanceof Exception) ? new ExecutionException(new
EJBException((Exception) e))
-                    : new ExecutionException(new EJBException(new
Exception(e)));
-
-        }
-
-        @Override
-        public boolean isCancelled() {
-            return canceled;
-        }
-
-        @Override
-        public boolean isDone() {
-            if(canceled) {
-                return false;
-            }
-            return target.isDone();
-        }
-    }
 }

Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/InheritedAppExceptionTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/InheritedAppExceptionTest.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/InheritedAppExceptionTest.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/InheritedAppExceptionTest.java
Mon Aug 20 00:12:51 2012
@@ -20,7 +20,6 @@

 package org.apache.openejb.core;

-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Properties;

@@ -57,7 +56,7 @@ public class InheritedAppExceptionTest {
     @Test
     public void testRollback() throws Exception {
         SystemInstance.init(new Properties());
-        BeanContext cdi = new BeanContext("foo", null, new
ModuleContext("foo",null, "bar", new AppContext("foo",
SystemInstance.get(), null, null, null, false, 10, 20, 60), null),
Object.class, null, new HashMap<String, String>());
+        BeanContext cdi = new BeanContext("foo", null, new
ModuleContext("foo",null, "bar", new AppContext("foo",
SystemInstance.get(), null, null, null, false), null), Object.class, null,
new HashMap<String, String>());
         cdi.addApplicationException(AE1.class, true, true);
         cdi.addApplicationException(AE3.class, true, false);
         cdi.addApplicationException(AE6.class, false, true);

Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/AuthorBean.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/AuthorBean.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/AuthorBean.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/AuthorBean.java
Mon Aug 20 00:12:51 2012
@@ -29,7 +29,6 @@ import org.apache.openejb.loader.SystemI

 import javax.ejb.EntityBean;
 import javax.ejb.EntityContext;
-import java.util.Collections;
 import java.util.Set;
 import java.util.HashSet;

@@ -37,7 +36,7 @@ public class AuthorBean implements Entit
     public static Object deploymentInfo;
     static {
         try {
-            deploymentInfo = new BeanContext("author", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
Author.class.getClassLoader(), new IvmContext(), new IvmContext(), false,
10, 20, 60), new IvmContext()),
+            deploymentInfo = new BeanContext("author", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
Author.class.getClassLoader(), new IvmContext(), new IvmContext(), false),
new IvmContext()),
                     AuthorBean.class,
                     null,
                     null,

Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/BookBean.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/BookBean.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/BookBean.java
(original)
+++
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/cmp/jpa/BookBean.java
Mon Aug 20 00:12:51 2012
@@ -29,7 +29,6 @@ import org.apache.openejb.loader.SystemI

 import javax.ejb.EntityBean;
 import javax.ejb.EntityContext;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;

@@ -37,7 +36,7 @@ public class BookBean implements EntityB
     public static Object deploymentInfo;
     static {
         try {
-            deploymentInfo = new BeanContext("book", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
Book.class.getClassLoader(), new IvmContext(), new IvmContext(), false, 10,
20, 60), new IvmContext()),
+            deploymentInfo = new BeanContext("book", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
Book.class.getClassLoader(), new IvmContext(), new IvmContext(), false),
new IvmContext()),
                     BookBean.class,
                     null,
                     null,

Modified:
openejb/trunk/openejb/container/openejb-junit/src/main/java/org/apache/openejb/junit/LocalClientRunner.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-junit/src/main/java/org/apache/openejb/junit/LocalClientRunner.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/container/openejb-junit/src/main/java/org/apache/openejb/junit/LocalClientRunner.java
(original)
+++
openejb/trunk/openejb/container/openejb-junit/src/main/java/org/apache/openejb/junit/LocalClientRunner.java
Mon Aug 20 00:12:51 2012
@@ -107,7 +107,7 @@ public class LocalClientRunner extends B

     private BeanContext createDeployment(Class<?> testClass) {
         try {
-            return new BeanContext(null, new IvmContext(), new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
testClass.getClassLoader(), new IvmContext(), new IvmContext(), false, 10,
20, 60), new IvmContext()), testClass, null, null, null, null, null, null,
null, null, null, BeanType.MANAGED, false);
+            return new BeanContext(null, new IvmContext(), new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(),
testClass.getClassLoader(), new IvmContext(), new IvmContext(), false), new
IvmContext()), testClass, null, null, null, null, null, null, null, null,
null, BeanType.MANAGED, false);
         } catch (SystemException e) {
             throw new IllegalStateException(e);
         }

Modified:
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/BasicClusterableRequestHandlerTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/BasicClusterableRequestHandlerTest.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/BasicClusterableRequestHandlerTest.java
(original)
+++
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/BasicClusterableRequestHandlerTest.java
Mon Aug 20 00:12:51 2012
@@ -46,7 +46,7 @@ public class BasicClusterableRequestHand
         request = (ClusterableRequest) mock(ClusterableRequest.class);
         response = (ClusterableResponse) mock(ClusterableResponse.class);
         clusteredContainer = (ClusteredRPCContainer)
mock(ClusteredRPCContainer.class);
-        beanContext = new BeanContext("aDeploymentId", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null,
null, null, false, 10, 20, 60), null),
BasicClusterableRequestHandlerTest.class, null, null, null, null, null,
null, null, null, null, null, false);
+        beanContext = new BeanContext("aDeploymentId", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null,
null, null, false), null), BasicClusterableRequestHandlerTest.class, null,
null, null, null, null, null, null, null, null, null, false);
     }

     public void testNoOpWhenNotAClusteredContainer() throws Exception {

Modified:
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/DeploymentIndexTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/DeploymentIndexTest.java?rev=1374882&r1=1374881&r2=1374882&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/DeploymentIndexTest.java
(original)
+++
openejb/trunk/openejb/server/openejb-ejbd/src/test/java/org/apache/openejb/server/ejbd/DeploymentIndexTest.java
Mon Aug 20 00:12:51 2012
@@ -39,7 +39,7 @@ public class DeploymentIndexTest {
     @Before
     public void setUp() throws SystemException {
         method = Method.class.getMethods()[0];
-        beanContext = new BeanContext("aDeploymentId", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null,
null, null, false, 10, 20, 60), null), DeploymentIndexTest.class, null,
null, null, null, null, null, null, null, null, null, false);
+        beanContext = new BeanContext("aDeploymentId", null, new
ModuleContext("", null, "", new AppContext("", SystemInstance.get(), null,
null, null, false), null), DeploymentIndexTest.class, null, null, null,
null, null, null, null, null, null, null, false);
         deploymentIndex = new DeploymentIndex(new BeanContext[]
{beanContext, beanContext});
     }