You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2013/11/21 11:22:10 UTC

svn commit: r1544088 [1/2] - in /tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb: ./ async/ config/ core/ core/cmp/ core/entity/ core/ivm/ core/managed/ core/security/ core/singleton/ core/stateless/ util/

Author: andygumbrecht
Date: Thu Nov 21 10:22:09 2013
New Revision: 1544088

URL: http://svn.apache.org/r1544088
Log:
Cleanup and finals in preparation and research on https://issues.apache.org/jira/browse/OPENEJB-2046
Various tweaks.

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/InterfaceType.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/OpenEjb2Conversion.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContainer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
    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/core/managed/ManagedContainer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/AbstractSecurityService.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/security/SecurityServiceImpl.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/EjbWsContext.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainerFactory.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessEjbHomeHandler.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessEjbObjectHandler.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/LogCategory.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/InterfaceType.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/InterfaceType.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/InterfaceType.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/InterfaceType.java Thu Nov 21 10:22:09 2013
@@ -36,7 +36,7 @@ public enum InterfaceType {
 
     private final String specName;
 
-    InterfaceType(String name) {
+    InterfaceType(final String name) {
         this.specName = name;
     }
 

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/async/AsynchronousPool.java Thu Nov 21 10:22:09 2013
@@ -54,17 +54,15 @@ public class AsynchronousPool {
     }
 
     public static AsynchronousPool create(final AppContext appContext) {
-
-        final ExecutorBuilder builder = new ExecutorBuilder()
-                .prefix("AsynchronousPool")
-                .size(3)
-                .threadFactory(new DaemonThreadFactory("@Asynchronous", appContext.getId()));
-
         final Options options = appContext.getOptions();
-        final AsynchronousPool asynchronousPool = new AsynchronousPool(
-                builder.build(options),
-                options.get("AsynchronousPool.ShutdownWaitDuration", new Duration(1, TimeUnit.MINUTES)));
-        return asynchronousPool;
+        final ExecutorBuilder builder = new ExecutorBuilder()
+                                            .prefix("AsynchronousPool")
+                                            .size(options.get("AsynchronousPool.Size", 5))
+                                            .threadFactory(new DaemonThreadFactory("@Asynchronous", appContext.getId()));
+
+        return new AsynchronousPool(
+                                       builder.build(options),
+                                       options.get("AsynchronousPool.ShutdownWaitDuration", new Duration(1, TimeUnit.MINUTES)));
     }
 
     public Object invoke(final Callable<Object> callable, final boolean isVoid) throws Throwable {
@@ -74,7 +72,9 @@ public class AsynchronousPool {
 
             final Future<Object> future = executor.submit(new AsynchronousCall(callable, asynchronousCancelled));
 
-            if (isVoid) return null;
+            if (isVoid) {
+                return null;
+            }
 
             return new FutureAdapter<Object>(future, asynchronousCancelled);
         } catch (RejectedExecutionException e) {
@@ -232,7 +232,7 @@ public class AsynchronousPool {
 
             // wrap unchecked exception with EJBException before throwing.
             throw e instanceof Exception ? new ExecutionException(new EJBException((Exception) e))
-                    : new ExecutionException(new EJBException(new Exception(e)));
+                      : new ExecutionException(new EJBException(new Exception(e)));
 
         }
 

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/OpenEjb2Conversion.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/OpenEjb2Conversion.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/OpenEjb2Conversion.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/OpenEjb2Conversion.java Thu Nov 21 10:22:09 2013
@@ -430,7 +430,8 @@ public class OpenEjb2Conversion implemen
                         // todo warn no such entity in ejb-jar.xml
                         continue;
                     }
-                    left = leftEntityData.relations.get(leftRole.getCmrField().getCmrFieldName());
+                    final EjbRelationshipRoleType.CmrField lcf = leftRole.getCmrField();
+                    left = (null != lcf ? leftEntityData.relations.get(lcf.getCmrFieldName()) : null);
                 }
 
                 if (left != null) {
@@ -453,12 +454,12 @@ public class OpenEjb2Conversion implemen
                     // if there wasn't a left cmr field, find the field for the right, so we can add the join table to it
                     if (left == null) {
 
-                        if (rightRole.getCmrField() == null) {
+                        final EjbRelationshipRoleType.CmrField rcf = rightRole.getCmrField();
+
+                        if (rcf == null) {
                             // todo warn no cmr field declared for either role
                             continue;
-                        }
-
-                        if (rightRole.getRelationshipRoleSource() != null) {
+                        } else if (rightRole.getRelationshipRoleSource() != null) {
                             final String rightEjbName = rightRole.getRelationshipRoleSource().getEjbName();
                             final EntityData rightEntityData = entities.get(moduleId + "#" + rightEjbName);
 
@@ -467,7 +468,7 @@ public class OpenEjb2Conversion implemen
                                 continue;
                             }
 
-                            final RelationField right = rightEntityData.relations.get(rightRole.getCmrField().getCmrFieldName());
+                            final RelationField right = rightEntityData.relations.get(rcf.getCmrFieldName());
                             right.setJoinTable(joinTable);
                         }
 

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java Thu Nov 21 10:22:09 2013
@@ -27,17 +27,17 @@ import java.util.concurrent.CopyOnWriteA
 import java.util.concurrent.atomic.AtomicBoolean;
 
 public class ThreadContext {
+
     private static final Logger log = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");
     private static final ThreadLocal<ThreadContext> threadStorage = new ThreadLocal<ThreadContext>();
     private static final List<ThreadContextListener> listeners = new CopyOnWriteArrayList<ThreadContextListener>();
     private static final ThreadLocal<AtomicBoolean> asynchronousCancelled = new ThreadLocal<AtomicBoolean>();
 
     public static ThreadContext getThreadContext() {
-        ThreadContext threadContext = threadStorage.get();
-        return threadContext;
+        return threadStorage.get();
     }
 
-    public static ThreadContext enter(ThreadContext newContext) {
+    public static ThreadContext enter(final ThreadContext newContext) {
         if (newContext == null) {
             throw new NullPointerException("newContext is null");
         }
@@ -47,11 +47,11 @@ public class ThreadContext {
         Thread.currentThread().setContextClassLoader(newContext.beanContext.getClassLoader());
 
         // update thread local
-        ThreadContext oldContext = threadStorage.get();
+        final ThreadContext oldContext = threadStorage.get();
         threadStorage.set(newContext);
 
         // notify listeners
-        for (ThreadContextListener listener : listeners) {
+        for (final ThreadContextListener listener : listeners) {
             try {
                 listener.contextEntered(oldContext, newContext);
             } catch (Throwable e) {
@@ -63,8 +63,8 @@ public class ThreadContext {
         return oldContext;
     }
 
-    public static void exit(ThreadContext oldContext) {
-        ThreadContext exitingContext = threadStorage.get();
+    public static void exit(final ThreadContext oldContext) {
+        final ThreadContext exitingContext = threadStorage.get();
         if (exitingContext == null) {
             throw new IllegalStateException("No existing context");
         }
@@ -77,7 +77,7 @@ public class ThreadContext {
         threadStorage.set(oldContext);
 
         // notify listeners
-        for (ThreadContextListener listener : listeners) {
+        for (final ThreadContextListener listener : listeners) {
             try {
                 listener.contextExited(exitingContext, oldContext);
             } catch (Throwable e) {
@@ -86,7 +86,7 @@ public class ThreadContext {
         }
     }
 
-    public static void initAsynchronousCancelled(AtomicBoolean initializeValue) {
+    public static void initAsynchronousCancelled(final AtomicBoolean initializeValue) {
         asynchronousCancelled.set(initializeValue);
     }
 
@@ -98,11 +98,11 @@ public class ThreadContext {
         asynchronousCancelled.remove();
     }
 
-    public static void addThreadContextListener(ThreadContextListener listener) {
+    public static void addThreadContextListener(final ThreadContextListener listener) {
         listeners.add(listener);
     }
 
-    public static void removeThreadContextListener(ThreadContextListener listener) {
+    public static void removeThreadContextListener(final ThreadContextListener listener) {
         listeners.remove(listener);
     }
 
@@ -120,11 +120,11 @@ public class ThreadContext {
      */
     private boolean discardInstance;
 
-    public ThreadContext(BeanContext beanContext, Object primaryKey) {
+    public ThreadContext(final BeanContext beanContext, final Object primaryKey) {
         this(beanContext, primaryKey, null);
     }
 
-    public ThreadContext(BeanContext beanContext, Object primaryKey, Operation operation) {
+    public ThreadContext(final BeanContext beanContext, final Object primaryKey, final Operation operation) {
         if (beanContext == null) {
             throw new NullPointerException("deploymentInfo is null");
         }
@@ -133,7 +133,7 @@ public class ThreadContext {
         this.currentOperation = operation;
     }
 
-    public ThreadContext(ThreadContext that) {
+    public ThreadContext(final ThreadContext that) {
         this.beanContext = that.beanContext;
         this.primaryKey = that.primaryKey;
         this.data.putAll(that.data);
@@ -152,7 +152,7 @@ public class ThreadContext {
         return currentOperation;
     }
 
-    public void setCurrentOperation(Operation operation) {
+    public void setCurrentOperation(final Operation operation) {
         currentOperation = operation;
     }
 
@@ -160,7 +160,7 @@ public class ThreadContext {
         return invokedInterface;
     }
 
-    public void setInvokedInterface(Class invokedInterface) {
+    public void setInvokedInterface(final Class invokedInterface) {
         this.invokedInterface = invokedInterface;
     }
 
@@ -168,7 +168,7 @@ public class ThreadContext {
         return transactionPolicy;
     }
 
-    public void setTransactionPolicy(TransactionPolicy transactionPolicy) {
+    public void setTransactionPolicy(final TransactionPolicy transactionPolicy) {
         this.transactionPolicy = transactionPolicy;
     }
 
@@ -176,22 +176,22 @@ public class ThreadContext {
         return null;
     }
 
-    public BaseContext.State[] setCurrentAllowedStates(BaseContext.State[] newAllowedStates) {
+    public BaseContext.State[] setCurrentAllowedStates(final BaseContext.State[] newAllowedStates) {
         return null;
     }
 
     @SuppressWarnings({"unchecked"})
-    public <T> T get(Class<T> type) {
-        return (T)data.get(type);
+    public <T> T get(final Class<T> type) {
+        return (T) data.get(type);
     }
 
     @SuppressWarnings({"unchecked"})
-    public <T> T set(Class<T> type, T value) {
+    public <T> T set(final Class<T> type, final T value) {
         return (T) data.put(type, value);
     }
 
-    @SuppressWarnings({ "unchecked" })
-    public <T> T remove(Class<T> type) {
+    @SuppressWarnings({"unchecked"})
+    public <T> T remove(final Class<T> type) {
         return (T) data.remove(type);
     }
 
@@ -199,21 +199,21 @@ public class ThreadContext {
         return discardInstance;
     }
 
-    public void setDiscardInstance(boolean discardInstance) {
+    public void setDiscardInstance(final boolean discardInstance) {
         this.discardInstance = discardInstance;
     }
 
     @Override
     public String toString() {
         return "ThreadContext{" +
-                "beanContext=" + beanContext.getId() +
-                ", primaryKey=" + primaryKey +
-                ", data=" + data.size() +
-                ", oldClassLoader=" + oldClassLoader +
-                ", currentOperation=" + currentOperation +
-                ", invokedInterface=" + invokedInterface +
-                ", transactionPolicy=" + transactionPolicy +
-                ", discardInstance=" + discardInstance +
-                '}';
+               "beanContext=" + beanContext.getId() +
+               ", primaryKey=" + primaryKey +
+               ", data=" + data.size() +
+               ", oldClassLoader=" + oldClassLoader +
+               ", currentOperation=" + currentOperation +
+               ", invokedInterface=" + invokedInterface +
+               ", transactionPolicy=" + transactionPolicy +
+               ", discardInstance=" + discardInstance +
+               '}';
     }
 }

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpContainer.java Thu Nov 21 10:22:09 2013
@@ -73,6 +73,7 @@ import static org.apache.openejb.core.tr
  * @org.apache.xbean.XBean element="cmpContainer"
  */
 public class CmpContainer implements RpcContainer {
+
     protected final Object containerID;
     protected final SecurityService securityService;
 
@@ -104,7 +105,10 @@ public class CmpContainer implements Rpc
         }
     };
 
-    public CmpContainer(Object id, TransactionManager transactionManager, SecurityService securityService, String cmpEngineFactory) throws OpenEJBException {
+    public CmpContainer(final Object id,
+                        final TransactionManager transactionManager,
+                        final SecurityService securityService,
+                        final String cmpEngineFactory) throws OpenEJBException {
         this.containerID = id;
         this.securityService = securityService;
         synchronizationRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
@@ -112,11 +116,13 @@ public class CmpContainer implements Rpc
 
         // create the cmp engine instance
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-        if (classLoader == null) classLoader = getClass().getClassLoader();
+        if (classLoader == null) {
+            classLoader = getClass().getClassLoader();
+        }
 
-        CmpEngineFactory factory;
+        final CmpEngineFactory factory;
         try {
-            Class<?> cmpEngineFactoryClass = classLoader.loadClass(cmpEngineFactory);
+            final Class<?> cmpEngineFactoryClass = classLoader.loadClass(cmpEngineFactory);
             factory = (CmpEngineFactory) cmpEngineFactoryClass.newInstance();
         } catch (Exception e) {
             throw new OpenEJBException("Unable to create cmp engine factory " + cmpEngineFactory, e);
@@ -127,19 +133,23 @@ public class CmpContainer implements Rpc
         cmpEngine = factory.create();
     }
 
+    @Override
     public Object getContainerID() {
         return containerID;
     }
 
+    @Override
     public ContainerType getContainerType() {
         return ContainerType.CMP_ENTITY;
     }
 
+    @Override
     public synchronized BeanContext[] getBeanContexts() {
         return deploymentsById.values().toArray(new BeanContext[deploymentsById.size()]);
     }
 
-    public synchronized BeanContext getBeanContext(Object deploymentID) {
+    @Override
+    public synchronized BeanContext getBeanContext(final Object deploymentID) {
         return deploymentsById.get(deploymentID);
     }
 
@@ -153,16 +163,17 @@ public class CmpContainer implements Rpc
         return beanContext;
     }
 
-    public void deploy(BeanContext beanContext) throws OpenEJBException {
+    @Override
+    public void deploy(final BeanContext beanContext) throws OpenEJBException {
         synchronized (this) {
-            Object deploymentId = beanContext.getDeploymentID();
+            final Object deploymentId = beanContext.getDeploymentID();
 
             cmpEngine.deploy(beanContext);
             beanContext.setContainerData(cmpEngine);
             beanContext.set(EJBContext.class, new EntityContext(securityService));
             // try to set deploymentInfo static field on bean implementation class
             try {
-                Field field = beanContext.getCmpImplClass().getField("deploymentInfo");
+                final Field field = beanContext.getCmpImplClass().getField("deploymentInfo");
                 field.set(null, beanContext);
             } catch (Exception e) {
                 // ignore
@@ -175,24 +186,27 @@ public class CmpContainer implements Rpc
         }
     }
 
+    @Override
     public void start(final BeanContext beanContext) throws OpenEJBException {
         final EjbTimerService timerService = beanContext.getEjbTimerService();
         if (timerService != null) {
             timerService.start();
         }
     }
-    
-    public void stop(BeanContext beanContext) throws OpenEJBException {
+
+    @Override
+    public void stop(final BeanContext beanContext) throws OpenEJBException {
         beanContext.stop();
     }
-    
-    public void undeploy(BeanContext beanContext) throws OpenEJBException {
+
+    @Override
+    public void undeploy(final BeanContext beanContext) throws OpenEJBException {
         synchronized (this) {
             deploymentsById.remove(beanContext.getDeploymentID());
             beansByClass.remove(beanContext.getCmpImplClass());
 
             try {
-                Field field = beanContext.getCmpImplClass().getField("deploymentInfo");
+                final Field field = beanContext.getCmpImplClass().getField("deploymentInfo");
                 field.set(null, null);
             } catch (Exception e) {
                 // ignore
@@ -203,38 +217,48 @@ public class CmpContainer implements Rpc
         }
     }
 
-    public Object getEjbInstance(BeanContext beanContext, Object primaryKey) {
-        ThreadContext callContext = new ThreadContext(beanContext, primaryKey);
+    public Object getEjbInstance(final BeanContext beanContext, final Object primaryKey) {
+        final ThreadContext callContext = new ThreadContext(beanContext, primaryKey);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
-            Object bean = cmpEngine.loadBean(callContext, primaryKey);
-            return bean;
+            return cmpEngine.loadBean(callContext, primaryKey);
         } finally {
             ThreadContext.exit(oldCallContext);
         }
     }
 
-    public Object invoke(Object deployID, InterfaceType type, Class callInterface, Method callMethod, Object[] args, Object primKey) throws OpenEJBException {
-        BeanContext beanContext = this.getBeanContext(deployID);
+    @Override
+    public Object invoke(final Object deployID,
+                         InterfaceType type,
+                         final Class callInterface,
+                         final Method callMethod,
+                         final Object[] args,
+                         final Object primKey) throws OpenEJBException {
+        final BeanContext beanContext = this.getBeanContext(deployID);
 
-        if (beanContext == null) throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='"+deployID+"'), Container(id='"+containerID+"')");
+        if (beanContext == null) {
+            throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
+        }
 
         // Use the backup way to determine call type if null was supplied.
-        if (type == null) type = beanContext.getInterfaceType(callInterface);
+        if (type == null) {
+            type = beanContext.getInterfaceType(callInterface);
+        }
 
-        ThreadContext callContext = new ThreadContext(beanContext, primKey);
+        final ThreadContext callContext = new ThreadContext(beanContext, primKey);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
 
-            boolean authorized = securityService.isCallerAuthorized(callMethod, type);
+            final boolean authorized = securityService.isCallerAuthorized(callMethod, type);
+
             if (!authorized) {
                 throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
             }
 
-            Class declaringClass = callMethod.getDeclaringClass();
-            String methodName = callMethod.getName();
+            final Class declaringClass = callMethod.getDeclaringClass();
+            final String methodName = callMethod.getName();
 
             if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
                 if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
@@ -258,49 +282,49 @@ public class CmpContainer implements Rpc
 
             // business method
             callContext.setCurrentOperation(Operation.BUSINESS);
-            Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
+            final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
 
             callContext.set(Method.class, runMethod);
 
-            Object retValue = businessMethod(callMethod, runMethod, args, callContext, type);
-
-            return retValue;
+            return businessMethod(callMethod, runMethod, args, callContext, type);
         } finally {
             ThreadContext.exit(oldCallContext);
         }
     }
 
-    private EntityBean createNewInstance(ThreadContext callContext) {
-        BeanContext beanContext = callContext.getBeanContext();
+    private EntityBean createNewInstance(final ThreadContext callContext) {
+        final BeanContext beanContext = callContext.getBeanContext();
         try {
-            EntityBean bean = (EntityBean) beanContext.getCmpImplClass().newInstance();
-            return bean;
+            return (EntityBean) beanContext.getCmpImplClass().newInstance();
         } catch (Exception e) {
             throw new EJBException("Unable to create new entity bean instance " + beanContext.getCmpImplClass(), e);
         }
     }
 
-    private ThreadContext createThreadContext(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private ThreadContext createThreadContext(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
-        KeyGenerator keyGenerator = beanContext.getKeyGenerator();
-        Object primaryKey = keyGenerator.getPrimaryKey(entityBean);
+        final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
+        final KeyGenerator keyGenerator = beanContext.getKeyGenerator();
+        final Object primaryKey = keyGenerator.getPrimaryKey(entityBean);
 
-        ThreadContext callContext = new ThreadContext(beanContext, primaryKey);
-        return callContext;
+        return new ThreadContext(beanContext, primaryKey);
     }
 
-    private void setEntityContext(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void setEntityContext(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
         // activating entity doen't have a primary key
-        BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
+        final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
 
-        ThreadContext callContext = new ThreadContext(beanContext, null);
+        final ThreadContext callContext = new ThreadContext(beanContext, null);
         callContext.setCurrentOperation(Operation.SET_CONTEXT);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.setEntityContext(new EntityContext(securityService));
         } catch (RemoteException e) {
@@ -310,13 +334,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void unsetEntityContext(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void unsetEntityContext(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.UNSET_CONTEXT);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.unsetEntityContext();
         } catch (RemoteException e) {
@@ -326,13 +352,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void ejbLoad(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void ejbLoad(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.LOAD);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.ejbLoad();
         } catch (RemoteException e) {
@@ -349,17 +377,20 @@ public class CmpContainer implements Rpc
                 registeredEntities = new LinkedHashSet<EntityBean>();
                 synchronizationRegistry.putResource(ENTITIES_TO_STORE, registeredEntities);
                 synchronizationRegistry.registerInterposedSynchronization(new Synchronization() {
+                    @Override
                     public void beforeCompletion() {
                         //noinspection unchecked
-                        Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
+                        final Set<EntityBean> registeredEntities = (LinkedHashSet<EntityBean>) synchronizationRegistry.getResource(ENTITIES_TO_STORE);
                         if (registeredEntities == null) {
                             return;
                         }
-                        for (EntityBean entityBean : registeredEntities) {
+                        for (final EntityBean entityBean : registeredEntities) {
                             ejbStore(entityBean);
                         }
                     }
-                    public void afterCompletion(int i) {
+
+                    @Override
+                    public void afterCompletion(final int i) {
                     }
                 });
             }
@@ -368,13 +399,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void ejbStore(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void ejbStore(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.STORE);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.ejbStore();
         } catch (RemoteException e) {
@@ -384,14 +417,18 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void ejbRemove(EntityBean entityBean) throws RemoveException {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
-        if (isDeleted(entityBean)) return;
+    private void ejbRemove(final EntityBean entityBean) throws RemoveException {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
+        if (isDeleted(entityBean)) {
+            return;
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.REMOVE);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.ejbRemove();
         } catch (RemoteException e) {
@@ -408,9 +445,9 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private boolean isDeleted(EntityBean entityBean) {
+    private boolean isDeleted(final EntityBean entityBean) {
         try {
-            return (Boolean)entityBean.getClass().getMethod("OpenEJB_isDeleted").invoke(entityBean);
+            return (Boolean) entityBean.getClass().getMethod("OpenEJB_isDeleted").invoke(entityBean);
         } catch (NoSuchMethodException e) {
             return false;
         } catch (Exception e) {
@@ -418,13 +455,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void ejbActivate(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void ejbActivate(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.ACTIVATE);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.ejbActivate();
         } catch (RemoteException e) {
@@ -434,13 +473,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void ejbPassivate(EntityBean entityBean) {
-        if (entityBean == null) throw new NullPointerException("entityBean is null");
+    private void ejbPassivate(final EntityBean entityBean) {
+        if (entityBean == null) {
+            throw new NullPointerException("entityBean is null");
+        }
 
-        ThreadContext callContext = createThreadContext(entityBean);
+        final ThreadContext callContext = createThreadContext(entityBean);
         callContext.setCurrentOperation(Operation.PASSIVATE);
 
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             entityBean.ejbPassivate();
         } catch (RemoteException e) {
@@ -450,12 +491,16 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private Object businessMethod(Method callMethod, Method runMethod, Object[] args, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private Object businessMethod(final Method callMethod,
+                                  final Method runMethod,
+                                  final Object[] args,
+                                  final ThreadContext callContext,
+                                  final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
-        EntityBean bean;
+        final EntityBean bean;
         Object returnValue = null;
 
         entrancyTracker.enter(beanContext, callContext.getPrimaryKey());
@@ -476,7 +521,7 @@ public class CmpContainer implements Rpc
                 e = ((InvocationTargetException) e).getTargetException();
             }
 
-            ExceptionType type = callContext.getBeanContext().getExceptionType(e);
+            final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
             if (type == ExceptionType.SYSTEM) {
                 /* System Exception ****************************/
                 handleSystemException(txPolicy, e, callContext);
@@ -492,12 +537,12 @@ public class CmpContainer implements Rpc
         return returnValue;
     }
 
-    private Object homeMethod(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private Object homeMethod(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
-        EntityBean bean;
+        final EntityBean bean;
         Object returnValue = null;
         try {
             /*
@@ -511,7 +556,7 @@ public class CmpContainer implements Rpc
             try {
                 callContext.setCurrentOperation(Operation.HOME);
 
-                Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
+                final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
 
                 try {
                     returnValue = runMethod.invoke(bean, args);
@@ -531,7 +576,7 @@ public class CmpContainer implements Rpc
                 e = ((InvocationTargetException) e).getTargetException();
             }
 
-            ExceptionType type = callContext.getBeanContext().getExceptionType(e);
+            final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
             if (type == ExceptionType.SYSTEM) {
                 /* System Exception ****************************/
                 handleSystemException(txPolicy, e, callContext);
@@ -547,12 +592,12 @@ public class CmpContainer implements Rpc
         return returnValue;
     }
 
-    private ProxyInfo createEJBObject(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private ProxyInfo createEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
-        EntityBean bean;
+        final EntityBean bean;
         Object primaryKey = null;
 
         try {
@@ -563,7 +608,7 @@ public class CmpContainer implements Rpc
             setEntityContext(bean);
 
             // Obtain the proper ejbCreate() method
-            Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);
+            final Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);
 
             // Set current operation for allowed operations
             callContext.setCurrentOperation(Operation.CREATE);
@@ -575,13 +620,13 @@ public class CmpContainer implements Rpc
             primaryKey = cmpEngine.createBean(bean, callContext);
 
             // determine post create callback method
-            Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);
+            final Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);
 
             // create a new context containing the pk for the post create call
-            ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
+            final ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
             postCreateContext.setCurrentOperation(Operation.POST_CREATE);
 
-            ThreadContext oldContext = ThreadContext.enter(postCreateContext);
+            final ThreadContext oldContext = ThreadContext.enter(postCreateContext);
             try {
                 // Invoke the ejbPostCreate method on the bean instance
                 ejbPostCreateMethod.invoke(bean, args);
@@ -603,7 +648,7 @@ public class CmpContainer implements Rpc
                 e = ((InvocationTargetException) e).getTargetException();
             }
 
-            ExceptionType type = callContext.getBeanContext().getExceptionType(e);
+            final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
             if (type == ExceptionType.SYSTEM) {
                 /* System Exception ****************************/
                 handleSystemException(txPolicy, e, callContext);
@@ -618,20 +663,20 @@ public class CmpContainer implements Rpc
         return new ProxyInfo(beanContext, primaryKey);
     }
 
-    private Object findByPrimaryKey(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private Object findByPrimaryKey(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
         try {
-            EntityBean bean = (EntityBean) cmpEngine.loadBean(callContext, args[0]);
+            final EntityBean bean = (EntityBean) cmpEngine.loadBean(callContext, args[0]);
             if (bean == null) {
                 throw new ObjectNotFoundException(beanContext.getDeploymentID() + " : " + args[0]);
             }
 
             // rebuild the primary key
-            KeyGenerator kg = beanContext.getKeyGenerator();
-            Object primaryKey = kg.getPrimaryKey(bean);
+            final KeyGenerator kg = beanContext.getKeyGenerator();
+            final Object primaryKey = kg.getPrimaryKey(bean);
 
             // create a new ProxyInfo based on the deployment info and primary key
             return new ProxyInfo(beanContext, primaryKey);
@@ -645,30 +690,30 @@ public class CmpContainer implements Rpc
         throw new AssertionError("Should not get here");
     }
 
-    private Object findEJBObject(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private Object findEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
         try {
-            List<Object> results = cmpEngine.queryBeans(callContext, callMethod, args);
+            final List<Object> results = cmpEngine.queryBeans(callContext, callMethod, args);
 
-            KeyGenerator kg = beanContext.getKeyGenerator();
+            final KeyGenerator kg = beanContext.getKeyGenerator();
 
             // The following block of code is responsible for returning ProxyInfo object(s) for each
             // matching entity bean found by the query.  If its a multi-value find operation a Vector
             // of ProxyInfo objects will be returned. If its a single-value find operation then a
             // single ProxyInfo object is returned.
             if (callMethod.getReturnType() == Collection.class || callMethod.getReturnType() == Enumeration.class) {
-                List<ProxyInfo> proxies = new ArrayList<ProxyInfo>();
-                for (Object value : results) {
-                    EntityBean bean = (EntityBean) value;
+                final List<ProxyInfo> proxies = new ArrayList<ProxyInfo>();
+                for (final Object value : results) {
+                    final EntityBean bean = (EntityBean) value;
 
                     if (value == null) {
                         proxies.add(null);
                     } else {
                         // get the primary key
-                        Object primaryKey = kg.getPrimaryKey(bean);
+                        final Object primaryKey = kg.getPrimaryKey(bean);
 
                         // create a new ProxyInfo based on the deployment info and primary key and add it to the vector
                         proxies.add(new ProxyInfo(beanContext, primaryKey));
@@ -681,15 +726,19 @@ public class CmpContainer implements Rpc
                 }
             } else {
                 if (results.size() != 1) {
-                    throw new ObjectNotFoundException("A Enteprise bean with deployment_id = " + beanContext.getDeploymentID() + " and primarykey = " + args[0] + " Does not exist");
+                    throw new ObjectNotFoundException("A Enteprise bean with deployment_id = " +
+                                                      beanContext.getDeploymentID() +
+                                                      " and primarykey = " +
+                                                      args[0] +
+                                                      " Does not exist");
                 }
 
                 // create a new ProxyInfo based on the deployment info and primary key
-                EntityBean bean = (EntityBean) results.get(0);
+                final EntityBean bean = (EntityBean) results.get(0);
                 if (bean == null) {
                     return null;
                 } else {
-                    Object primaryKey = kg.getPrimaryKey(bean);
+                    final Object primaryKey = kg.getPrimaryKey(bean);
                     return new ProxyInfo(beanContext, primaryKey);
                 }
             }
@@ -703,19 +752,19 @@ public class CmpContainer implements Rpc
         throw new AssertionError("Should not get here");
     }
 
-    public Object select(BeanContext beanContext, String methodSignature, String returnType, Object... args) throws FinderException {
-        String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
+    public Object select(final BeanContext beanContext, final String methodSignature, final String returnType, final Object... args) throws FinderException {
+        final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
 
         try {
             // execute the select query
-            Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);
+            final Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);
 
             //
             // process the results
             //
 
             // If we need to return a set...
-            Collection<Object> proxies;
+            final Collection<Object> proxies;
             if (returnType.equals("java.util.Set")) {
                 // we collect values into a LinkedHashSet to preserve ordering
                 proxies = new LinkedHashSet<Object>();
@@ -724,7 +773,7 @@ public class CmpContainer implements Rpc
                 proxies = new ArrayList<Object>();
             }
 
-            boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
+            final boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
             ProxyFactory proxyFactory = null;
             for (Object value : results) {
                 // if this is a single valued query and we already have results, throw FinderException
@@ -734,9 +783,9 @@ public class CmpContainer implements Rpc
 
                 // if we have an EntityBean, we need to proxy it
                 if (value instanceof EntityBean) {
-                    EntityBean entityBean = (EntityBean) value;
+                    final EntityBean entityBean = (EntityBean) value;
                     if (proxyFactory == null) {
-                        BeanContext result = getBeanContextByClass(entityBean.getClass());
+                        final BeanContext result = getBeanContextByClass(entityBean.getClass());
                         if (result != null) {
                             proxyFactory = new ProxyFactory(result);
                         }
@@ -764,28 +813,26 @@ public class CmpContainer implements Rpc
             }
 
             // return the single item.... multiple return values was handled in for loop above
-            Object returnValue = proxies.iterator().next();
-            return returnValue;
+            return proxies.iterator().next();
         } catch (RuntimeException e) {
             throw new EJBException(e);
         }
     }
 
-    public int update(BeanContext beanContext, String methodSignature, Object... args) throws FinderException {
-        String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
+    public int update(final BeanContext beanContext, final String methodSignature, final Object... args) throws FinderException {
+        final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;
 
         // exectue the update query
-        int result = cmpEngine.executeUpdateQuery(beanContext, signature, args);
-        return result;
+        return cmpEngine.executeUpdateQuery(beanContext, signature, args);
     }
 
-    private void removeEJBObject(Method callMethod, ThreadContext callContext, InterfaceType interfaceType) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    private void removeEJBObject(final Method callMethod, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
 
         try {
-            EntityBean entityBean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
+            final EntityBean entityBean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
             if (entityBean == null) {
                 throw new NoSuchObjectException(callContext.getBeanContext().getDeploymentID() + " " + callContext.getPrimaryKey());
             }
@@ -800,15 +847,15 @@ public class CmpContainer implements Rpc
         }
     }
 
-    private void cancelTimers(ThreadContext threadContext) {
-        BeanContext beanContext = threadContext.getBeanContext();
-        Object primaryKey = threadContext.getPrimaryKey();
+    private void cancelTimers(final ThreadContext threadContext) {
+        final BeanContext beanContext = threadContext.getBeanContext();
+        final Object primaryKey = threadContext.getPrimaryKey();
 
         // stop timers
         if (primaryKey != null && beanContext.getEjbTimerService() != null) {
-            EjbTimerService timerService = beanContext.getEjbTimerService();
+            final EjbTimerService timerService = beanContext.getEjbTimerService();
             if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
-                for (Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
+                for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
                     timer.cancel();
                 }
             }
@@ -816,31 +863,39 @@ public class CmpContainer implements Rpc
     }
 
     private class ContainerCmpCallback implements CmpCallback {
-        public void setEntityContext(EntityBean entity) {
+
+        @Override
+        public void setEntityContext(final EntityBean entity) {
             CmpContainer.this.setEntityContext(entity);
         }
 
-        public void unsetEntityContext(EntityBean entity) {
+        @Override
+        public void unsetEntityContext(final EntityBean entity) {
             CmpContainer.this.unsetEntityContext(entity);
         }
 
-        public void ejbActivate(EntityBean entity) {
+        @Override
+        public void ejbActivate(final EntityBean entity) {
             CmpContainer.this.ejbActivate(entity);
         }
 
-        public void ejbPassivate(EntityBean entity) {
+        @Override
+        public void ejbPassivate(final EntityBean entity) {
             CmpContainer.this.ejbPassivate(entity);
         }
 
-        public void ejbLoad(EntityBean entity) {
+        @Override
+        public void ejbLoad(final EntityBean entity) {
             CmpContainer.this.ejbLoad(entity);
         }
 
-        public void ejbStore(EntityBean entity) {
+        @Override
+        public void ejbStore(final EntityBean entity) {
             CmpContainer.this.ejbStore(entity);
         }
 
-        public void ejbRemove(EntityBean entity) throws RemoveException {
+        @Override
+        public void ejbRemove(final EntityBean entity) throws RemoveException {
             CmpContainer.this.ejbRemove(entity);
         }
     }

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContainer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContainer.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContainer.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContainer.java Thu Nov 21 10:22:09 2013
@@ -66,21 +66,21 @@ import static org.apache.openejb.core.tr
  */
 public class EntityContainer implements RpcContainer {
 
-    private EntityInstanceManager instanceManager;
+    private final EntityInstanceManager instanceManager;
 
-    private Map<String, BeanContext> deploymentRegistry  = new HashMap<String, BeanContext>();
+    private final Map<String, BeanContext> deploymentRegistry = new HashMap<String, BeanContext>();
 
     private Object containerID = null;
 
     public static Logger logger = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");
-    private SecurityService securityService;
+    private final SecurityService securityService;
 
     /**
      * Tracks entity instances that have been "entered" so we can throw reentrancy exceptions.
      */
     protected EntrancyTracker entrancyTracker;
 
-    public EntityContainer(Object id, SecurityService securityService, int poolSize) throws OpenEJBException {
+    public EntityContainer(final Object id, final SecurityService securityService, final int poolSize) throws OpenEJBException {
         this.containerID = id;
         this.securityService = securityService;
         entrancyTracker = new EntrancyTracker(SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
@@ -88,24 +88,29 @@ public class EntityContainer implements 
         instanceManager = new EntityInstanceManager(this, securityService, poolSize);
     }
 
+    @Override
     public synchronized BeanContext[] getBeanContexts() {
         return deploymentRegistry.values().toArray(new BeanContext[deploymentRegistry.size()]);
     }
 
-    public synchronized BeanContext getBeanContext(Object deploymentID) {
-        String id = (String) deploymentID;
+    @Override
+    public synchronized BeanContext getBeanContext(final Object deploymentID) {
+        final String id = (String) deploymentID;
         return deploymentRegistry.get(id);
     }
 
+    @Override
     public ContainerType getContainerType() {
         return ContainerType.BMP_ENTITY;
     }
 
+    @Override
     public Object getContainerID() {
         return containerID;
     }
 
-    public void deploy(BeanContext beanContext) throws OpenEJBException {
+    @Override
+    public void deploy(final BeanContext beanContext) throws OpenEJBException {
         synchronized (this) {
             deploymentRegistry.put((String) beanContext.getDeploymentID(), beanContext);
             beanContext.setContainer(this);
@@ -113,44 +118,60 @@ public class EntityContainer implements 
         instanceManager.deploy(beanContext);
     }
 
+    @Override
     public void start(final BeanContext info) throws OpenEJBException {
         final EjbTimerService timerService = info.getEjbTimerService();
         if (timerService != null) {
             timerService.start();
         }
     }
-    
-    public void stop(BeanContext info) throws OpenEJBException {
+
+    @Override
+    public void stop(final BeanContext info) throws OpenEJBException {
         info.stop();
     }
-    
-    public void undeploy(BeanContext info) throws OpenEJBException {
+
+    @Override
+    public void undeploy(final BeanContext info) throws OpenEJBException {
         instanceManager.undeploy(info);
 
         synchronized (this) {
-            String id = (String) info.getDeploymentID();
+            final String id = (String) info.getDeploymentID();
             deploymentRegistry.remove(id);
             info.setContainer(null);
         }
     }
 
-    public Object invoke(Object deployID, InterfaceType type, Class callInterface, Method callMethod, Object[] args, Object primKey) throws OpenEJBException {
-        BeanContext beanContext = this.getBeanContext(deployID);
+    @Override
+    public Object invoke(final Object deployID,
+                         InterfaceType type,
+                         final Class callInterface,
+                         final Method callMethod,
+                         final Object[] args,
+                         final Object primKey) throws OpenEJBException {
+        final BeanContext beanContext = this.getBeanContext(deployID);
 
-        if (beanContext == null) throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='"+deployID+"'), Container(id='"+containerID+"')");
+        if (beanContext == null) {
+            throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
+        }
 
         // Use the backup way to determine call type if null was supplied.
-        if (type == null) type = beanContext.getInterfaceType(callInterface);
+        if (type == null) {
+            type = beanContext.getInterfaceType(callInterface);
+        }
 
-        ThreadContext callContext = new ThreadContext(beanContext, primKey);
-        ThreadContext oldCallContext = ThreadContext.enter(callContext);
+        final ThreadContext callContext = new ThreadContext(beanContext, primKey);
+        final ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
-            boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);
-            if (!authorized)
+
+            final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);
+
+            if (!authorized) {
                 throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
+            }
 
-            Class declaringClass = callMethod.getDeclaringClass();
-            String methodName = callMethod.getName();
+            final Class declaringClass = callMethod.getDeclaringClass();
+            final String methodName = callMethod.getName();
 
             if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
                 if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
@@ -175,13 +196,11 @@ public class EntityContainer implements 
             }
 
             callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
-            Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
+            final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
 
             callContext.set(Method.class, runMethod);
 
-            Object retValue = invoke(type, callMethod, runMethod, args, callContext);
-
-            return retValue;
+            return invoke(type, callMethod, runMethod, args, callContext);
 
         } finally {
             ThreadContext.exit(oldCallContext);
@@ -196,9 +215,13 @@ public class EntityContainer implements 
         return instanceManager;
     }
 
-    protected Object invoke(InterfaceType type, Method callMethod, Method runMethod, Object[] args, ThreadContext callContext) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
+    protected Object invoke(final InterfaceType type,
+                            final Method callMethod,
+                            final Method runMethod,
+                            final Object[] args,
+                            final ThreadContext callContext) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
 
         EntityBean bean = null;
 
@@ -221,17 +244,17 @@ public class EntityContainer implements 
         return returnValue;
     }
 
-    public void ejbLoad_If_No_Transaction(ThreadContext callContext, EntityBean bean) throws Exception {
-        Operation orginalOperation = callContext.getCurrentOperation();
+    public void ejbLoad_If_No_Transaction(final ThreadContext callContext, final EntityBean bean) throws Exception {
+        final Operation orginalOperation = callContext.getCurrentOperation();
         if (orginalOperation == Operation.BUSINESS || orginalOperation == Operation.REMOVE) {
 
-            TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
+            final TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
             if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
                 return;
             }
 
-            BeanContext beanContext = callContext.getBeanContext();
-            TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
+            final BeanContext beanContext = callContext.getBeanContext();
+            final TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
             try {
                 // double check we don't have an active transaction
                 if (!txPolicy.isTransactionActive()) {
@@ -252,17 +275,17 @@ public class EntityContainer implements 
         }
     }
 
-    public void ejbStore_If_No_Transaction(ThreadContext callContext, EntityBean bean) throws Exception {
-        Operation currentOp = callContext.getCurrentOperation();
+    public void ejbStore_If_No_Transaction(final ThreadContext callContext, final EntityBean bean) throws Exception {
+        final Operation currentOp = callContext.getCurrentOperation();
         if (currentOp == Operation.BUSINESS) {
 
-            TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
+            final TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
             if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
                 return;
             }
 
-            BeanContext beanContext = callContext.getBeanContext();
-            TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
+            final BeanContext beanContext = callContext.getBeanContext();
+            final TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
             try {
                 // double check we don't have an active transaction
                 if (!txPolicy.isTransactionActive()) {
@@ -279,11 +302,11 @@ public class EntityContainer implements 
         }
     }
 
-    protected void didCreateBean(ThreadContext callContext, EntityBean bean) throws OpenEJBException {
+    protected void didCreateBean(final ThreadContext callContext, final EntityBean bean) throws OpenEJBException {
     }
 
-    protected ProxyInfo createEJBObject(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType type) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    protected ProxyInfo createEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
 
         callContext.setCurrentOperation(Operation.CREATE);
 
@@ -301,7 +324,7 @@ public class EntityContainer implements 
         * super classes afterInvoke( ) method will be executed committing the transaction if its a CMT.
         */
 
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
 
         EntityBean bean = null;
         Object primaryKey = null;
@@ -310,7 +333,7 @@ public class EntityContainer implements 
             bean = instanceManager.obtainInstance(callContext);
 
             // Obtain the proper ejbCreate() method
-            Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);
+            final Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);
 
             // invoke the ejbCreate which returns the primary key
             primaryKey = ejbCreateMethod.invoke(bean, args);
@@ -318,13 +341,13 @@ public class EntityContainer implements 
             didCreateBean(callContext, bean);
 
             // determine post create callback method
-            Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);
+            final Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);
 
             // create a new context containing the pk for the post create call
-            ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
+            final ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
             postCreateContext.setCurrentOperation(Operation.POST_CREATE);
 
-            ThreadContext oldContext = ThreadContext.enter(postCreateContext);
+            final ThreadContext oldContext = ThreadContext.enter(postCreateContext);
             try {
                 // Invoke the ejbPostCreate method on the bean instance
                 ejbPostCreateMethod.invoke(bean, args);
@@ -351,10 +374,10 @@ public class EntityContainer implements 
 
     }
 
-    protected Object findMethod(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType type) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    protected Object findMethod(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
         callContext.setCurrentOperation(Operation.FIND);
-        Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
+        final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
         Object returnValue = invoke(type, callMethod, runMethod, args, callContext);
 
         /*
@@ -362,58 +385,59 @@ public class EntityContainer implements 
         * The primary keys are converted to ProxyInfo objects.
         */
         if (returnValue instanceof Collection) {
-            Iterator keys = ((Collection) returnValue).iterator();
-            Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
+            final Iterator keys = ((Collection) returnValue).iterator();
+            final Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
             while (keys.hasNext()) {
-                Object primaryKey = keys.next();
+                final Object primaryKey = keys.next();
                 proxies.addElement(new ProxyInfo(beanContext, primaryKey));
             }
             returnValue = proxies;
         } else if (returnValue instanceof Enumeration) {
-            Enumeration keys = (Enumeration) returnValue;
-            Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
+            final Enumeration keys = (Enumeration) returnValue;
+            final Vector<ProxyInfo> proxies = new Vector<ProxyInfo>();
             while (keys.hasMoreElements()) {
-                Object primaryKey = keys.nextElement();
+                final Object primaryKey = keys.nextElement();
                 proxies.addElement(new ProxyInfo(beanContext, primaryKey));
             }
             returnValue = new ArrayEnumeration(proxies);
-        } else
+        } else {
             returnValue = new ProxyInfo(beanContext, returnValue);
+        }
 
         return returnValue;
     }
 
-    protected Object homeMethod(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType type) throws OpenEJBException {
-        BeanContext beanContext = callContext.getBeanContext();
+    protected Object homeMethod(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
+        final BeanContext beanContext = callContext.getBeanContext();
         callContext.setCurrentOperation(Operation.HOME);
-        Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
+        final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
         return invoke(type, callMethod, runMethod, args, callContext);
     }
 
-    protected void didRemove(EntityBean bean, ThreadContext threadContext) throws OpenEJBException {
+    protected void didRemove(final EntityBean bean, final ThreadContext threadContext) throws OpenEJBException {
         cancelTimers(threadContext);
     }
 
-    private void cancelTimers(ThreadContext threadContext) {
-        BeanContext beanContext = threadContext.getBeanContext();
-        Object primaryKey = threadContext.getPrimaryKey();
+    private void cancelTimers(final ThreadContext threadContext) {
+        final BeanContext beanContext = threadContext.getBeanContext();
+        final Object primaryKey = threadContext.getPrimaryKey();
 
         // if we have a real timerservice, stop all timers. Otherwise, ignore...
         if (primaryKey != null) {
-            EjbTimerService timerService = beanContext.getEjbTimerService();
+            final EjbTimerService timerService = beanContext.getEjbTimerService();
             if (timerService != null && timerService instanceof EjbTimerServiceImpl) {
-                for (Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
+                for (final Timer timer : beanContext.getEjbTimerService().getTimers(primaryKey)) {
                     timer.cancel();
                 }
             }
         }
     }
 
-    protected void removeEJBObject(Method callMethod, Object[] args, ThreadContext callContext, InterfaceType type) throws OpenEJBException {
+    protected void removeEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
         callContext.setCurrentOperation(Operation.REMOVE);
 
-        BeanContext beanContext = callContext.getBeanContext();
-        TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
+        final BeanContext beanContext = callContext.getBeanContext();
+        final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
 
         EntityBean bean = null;
         try {
@@ -431,8 +455,8 @@ public class EntityContainer implements 
         }
     }
 
-    private void handleException(TransactionPolicy txPolicy, Throwable e, ThreadContext callContext, EntityBean bean) throws OpenEJBException {
-        ExceptionType type;
+    private void handleException(final TransactionPolicy txPolicy, Throwable e, final ThreadContext callContext, final EntityBean bean) throws OpenEJBException {
+        final ExceptionType type;
         if (e instanceof InvocationTargetException) {
             e = ((InvocationTargetException) e).getTargetException();
             type = callContext.getBeanContext().getExceptionType(e);
@@ -452,7 +476,8 @@ public class EntityContainer implements 
                 try {
                     instanceManager.discardInstance(callContext, bean);
                 } catch (SystemException e1) {
-                    logger.error("The instance manager encountered an unkown system exception while trying to discard the entity instance with primary key " + callContext.getPrimaryKey());
+                    logger.error("The instance manager encountered an unkown system exception while trying to discard the entity instance with primary key " +
+                                 callContext.getPrimaryKey());
                 }
             }
             handleSystemException(txPolicy, e, callContext);

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java?rev=1544088&r1=1544087&r2=1544088&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/BaseEjbProxyHandler.java Thu Nov 21 10:22:09 2013
@@ -474,6 +474,7 @@ public abstract class BaseEjbProxyHandle
         }
     }
 
+    @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
     public boolean equals(Object obj) {
         if (obj == null) {
             return false;

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=1544088&r1=1544087&r2=1544088&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 Thu Nov 21 10:22:09 2013
@@ -25,13 +25,17 @@ import org.apache.openejb.OpenEJBExcepti
 import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.ProxyInfo;
 import org.apache.openejb.SystemException;
+import org.apache.openejb.async.AsynchronousPool;
 import org.apache.openejb.core.ServerFederation;
+import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.entity.EntityEjbHomeHandler;
 import org.apache.openejb.core.managed.ManagedHomeHandler;
 import org.apache.openejb.core.singleton.SingletonEjbHomeHandler;
 import org.apache.openejb.core.stateful.StatefulEjbHomeHandler;
 import org.apache.openejb.core.stateless.StatelessEjbHomeHandler;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ApplicationServer;
+import org.apache.openejb.spi.SecurityService;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.proxy.LocalBeanProxyFactory;
@@ -51,6 +55,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 public abstract class EjbHomeProxyHandler extends BaseEjbProxyHandler {
 
@@ -93,7 +98,10 @@ public abstract class EjbHomeProxyHandle
         throw new IllegalStateException("A home reference must never be invalidated!");
     }
 
-    protected static EjbHomeProxyHandler createHomeHandler(final BeanContext beanContext, final InterfaceType interfaceType, final List<Class> interfaces, final Class mainInterface) {
+    protected static EjbHomeProxyHandler createHomeHandler(final BeanContext beanContext,
+                                                           final InterfaceType interfaceType,
+                                                           final List<Class> interfaces,
+                                                           final Class mainInterface) {
         switch (beanContext.getComponentType()) {
             case STATEFUL:
                 return new StatefulEjbHomeHandler(beanContext, interfaceType, interfaces, mainInterface);
@@ -106,7 +114,8 @@ public abstract class EjbHomeProxyHandle
             case CMP_ENTITY:
             case BMP_ENTITY:
                 return new EntityEjbHomeHandler(beanContext, interfaceType, interfaces, mainInterface);
-            default: throw new IllegalStateException("Component type does not support rpc interfaces: " + beanContext.getComponentType());
+            default:
+                throw new IllegalStateException("Component type does not support rpc interfaces: " + beanContext.getComponentType());
         }
     }
 
@@ -115,8 +124,9 @@ public abstract class EjbHomeProxyHandle
     }
 
     public static Object createHomeProxy(final BeanContext beanContext, final InterfaceType interfaceType, final List<Class> objectInterfaces, final Class mainInterface) {
-        if (!interfaceType.isHome())
+        if (!interfaceType.isHome()) {
             throw new IllegalArgumentException("InterfaceType is not a Home type: " + interfaceType);
+        }
 
         try {
             final EjbHomeProxyHandler handler = createHomeHandler(beanContext, interfaceType, objectInterfaces, mainInterface);
@@ -153,7 +163,10 @@ public abstract class EjbHomeProxyHandle
                 if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
                     interfaces.add(BeanContext.Removable.class);
                 }
-                return LocalBeanProxyFactory.newProxyInstance(handler.getBeanContext().getClassLoader(), handler, handler.getBeanContext().getBeanClass(), interfaces.toArray(new Class<?>[interfaces.size()]));
+                return LocalBeanProxyFactory.newProxyInstance(handler.getBeanContext().getClassLoader(),
+                                                              handler,
+                                                              handler.getBeanContext().getBeanClass(),
+                                                              interfaces.toArray(new Class<?>[interfaces.size()]));
             } else {
                 final List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 2);
                 proxyInterfaces.addAll(handler.getInterfaces());
@@ -175,12 +188,12 @@ public abstract class EjbHomeProxyHandle
     @Override
     protected Object _invoke(final Object proxy, final Class interfce, final Method method, final Object[] args) throws Throwable {
 
+        final String methodName = method.getName();
+
         if (logger.isDebugEnabled()) {
-            logger.debug("invoking method " + method.getName() + " on " + deploymentID);
+            logger.debug("EjbHomeProxyHandler: invoking method " + methodName + " on " + deploymentID);
         }
 
-        final String methodName = method.getName();
-
         try {
             final Object retValue;
             final MethodType operation = dispatchTable.get(methodName);
@@ -223,7 +236,7 @@ public abstract class EjbHomeProxyHandle
             }
 
             if (logger.isDebugEnabled()) {
-                logger.debug("finished invoking method " + method.getName() + ". Return value:" + retValue);
+                logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + ". Return value:" + retValue);
             }
 
             return retValue;
@@ -289,7 +302,7 @@ public abstract class EjbHomeProxyHandle
                 throw new RemoteException("Unknown Container Exception", oe.getRootCause());
             }
         } catch (Throwable t) {
-            logger.debug("finished invoking method " + method.getName() + " with exception:" + t, t);
+            logger.debug("EjbHomeProxyHandler: finished invoking method " + method.getName() + " with exception:" + t, t);
             throw t;
         }
     }
@@ -300,6 +313,49 @@ public abstract class EjbHomeProxyHandle
 
     protected Object homeMethod(final Class interfce, final Method method, final Object[] args, final Object proxy) throws Throwable {
         checkAuthorization(method);
+
+        final BeanContext beanContext = getBeanContext();
+
+        if (beanContext.isAsynchronous(method)) {
+
+            final SecurityService<?> securityService = SystemInstance.get().getComponent(SecurityService.class);
+            final Object state = securityService.currentState();
+            final ThreadContext currentCtx = ThreadContext.getThreadContext();
+            final AsynchronousPool asynchronousPool = beanContext.getModuleContext().getAppContext().getAsynchronousPool();
+
+            return asynchronousPool.invoke(new Callable<Object>() {
+                @Override
+                public Object call() throws Exception {
+                    final ThreadContext oldCtx; // ensure context is the same as for the caller
+                    if (currentCtx != null) {
+                        oldCtx = ThreadContext.enter(new ThreadContext(currentCtx));
+                    } else {
+                        oldCtx = null;
+                    }
+
+                    final Object threadState = securityService.currentState();
+                    securityService.setState(state);
+                    try {
+                        return homeMethodInvoke(interfce, method, args);
+                    } catch (ApplicationException ae) {
+
+                        logger.warning("EjbHomeProxyHandler: Asynchronous call to '" + interfce.getSimpleName() + "' on '" + method.getName() + "' failed", ae);
+
+                        throw ae;
+                    } finally {
+                        securityService.setState(threadState);
+                        if (oldCtx != null) {
+                            ThreadContext.exit(oldCtx);
+                        }
+                    }
+                }
+            }, method.getReturnType() == Void.TYPE);
+        } else {
+            return homeMethodInvoke(interfce, method, args);
+        }
+    }
+
+    private Object homeMethodInvoke(final Class interfce, final Method method, final Object[] args) throws OpenEJBException {
         return container.invoke(deploymentID, interfaceType, interfce, method, args, null);
     }
 
@@ -327,7 +383,10 @@ public abstract class EjbHomeProxyHandle
 
     protected Object getEJBMetaData(final Method method, final Object[] args, final Object proxy) throws Throwable {
         checkAuthorization(method);
-        final IntraVmMetaData metaData = new IntraVmMetaData(getBeanContext().getHomeInterface(), getBeanContext().getRemoteInterface(), getBeanContext().getPrimaryKeyClass(), getBeanContext().getComponentType());
+        final IntraVmMetaData metaData = new IntraVmMetaData(getBeanContext().getHomeInterface(),
+                                                             getBeanContext().getRemoteInterface(),
+                                                             getBeanContext().getPrimaryKeyClass(),
+                                                             getBeanContext().getComponentType());
         metaData.setEJBHome((EJBHome) proxy);
         return metaData;
     }