openejb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1178455 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core: managed/ mdb/ singleton/ stateful/ stateless/
Date Mon, 03 Oct 2011 16:58:53 GMT
Author: rmannibucau
Date: Mon Oct  3 16:58:53 2011
New Revision: 1178455

URL: http://svn.apache.org/viewvc?rev=1178455&view=rev
Log:
trying to release cdi dependent beans from ejb instances (see creationcontext.release())

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/Instance.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/Instance.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/Instance.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/Instance.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/Instance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/Instance.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/Instance.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/Instance.java
Mon Oct  3 16:58:53 2011
@@ -25,6 +25,7 @@ import org.apache.openejb.util.Duration;
 import org.apache.openejb.util.Index;
 import org.apache.openejb.util.PojoSerialization;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.persistence.EntityManagerFactory;
 import javax.transaction.Transaction;
 import java.io.ObjectStreamException;
@@ -40,6 +41,7 @@ public class Instance implements Seriali
     public final BeanContext beanContext;
     public final Object primaryKey;
     public final Object bean;
+    public final CreationalContext creationalContext;
     public final Map<String, Object> interceptors;
 
     private boolean inUse;
@@ -53,16 +55,17 @@ public class Instance implements Seriali
     private Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>
entityManagers;
     private final JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray;
 
-    public Instance(BeanContext beanContext, Object primaryKey, Object bean, Map<String,
Object> interceptors, Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>
entityManagers) {
+    public Instance(BeanContext beanContext, Object primaryKey, Object bean, Map<String,
Object> interceptors, CreationalContext creationalContext, Map<EntityManagerFactory,
JtaEntityManagerRegistry.EntityManagerTracker> entityManagers) {
         this.beanContext = beanContext;
         this.primaryKey = primaryKey;
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
         this.entityManagers = entityManagers;
         this.entityManagerArray = null;
     }
 
-    public Instance(Object deploymentId, Object primaryKey, Object bean, Map<String, Object>
interceptors, JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray) {
+    public Instance(Object deploymentId, Object primaryKey, Object bean, Map<String, Object>
interceptors, CreationalContext creationalContext, JtaEntityManagerRegistry.EntityManagerTracker[]
entityManagerArray) {
         this.beanContext = SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext(deploymentId);
         if (beanContext == null) {
             throw new IllegalArgumentException("Unknown deployment " + deploymentId);
@@ -70,6 +73,7 @@ public class Instance implements Seriali
         this.primaryKey = primaryKey;
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
         this.entityManagerArray = entityManagerArray;
     }
 
@@ -147,12 +151,14 @@ public class Instance implements Seriali
         public final Object primaryKey;
         public final Object bean;
         public final Map<String, Object> interceptors;
+        public final CreationalContext creationalContext;
         public final JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray;
 
         public Serialization(Instance i) {
             deploymentId = i.beanContext.getDeploymentID();
             primaryKey = i.primaryKey;
             bean = toSerializable(i.bean);
+            creationalContext = i.creationalContext;
 
             interceptors = new HashMap<String, Object>(i.interceptors.size());
             for (Map.Entry<String, Object> e : i.interceptors.entrySet()) {
@@ -185,7 +191,7 @@ public class Instance implements Seriali
             // Anything wrapped with PojoSerialization will have been automatically
             // unwrapped via it's own readResolve so passing in the raw bean
             // and interceptors variables is totally fine.
-            return new Instance(deploymentId, primaryKey, bean, interceptors, entityManagerArray);
+            return new Instance(deploymentId, primaryKey, bean, interceptors, creationalContext,
entityManagerArray);
         }
     }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContainer.java
Mon Oct  3 16:58:53 2011
@@ -330,6 +330,8 @@ public class ManagedContainer implements
             default:
                 return businessMethod(beanContext, primKey, callInterface, callMethod, args,
type);
         }
+
+
     }
 
     protected ProxyInfo createEJBObject(BeanContext beanContext, Method callMethod, Object[]
args, InterfaceType interfaceType) throws OpenEJBException {
@@ -369,7 +371,7 @@ public class ManagedContainer implements
                     final InstanceContext context = beanContext.newInstance();
 
                     // Wrap-up everthing into a object
-                    instance = new Instance(beanContext, primaryKey, context.getBean(), context.getInterceptors(),
entityManagers);
+                    instance = new Instance(beanContext, primaryKey, context.getBean(), context.getInterceptors(),
context.getCreationalContext(), entityManagers);
 
                 } catch (Throwable throwable) {
                     ThreadContext callContext = ThreadContext.getThreadContext();
@@ -691,8 +693,11 @@ public class ManagedContainer implements
             return;
         }
 
-        checkedOutInstances.remove(primaryKey);
+        Instance instance = checkedOutInstances.remove(primaryKey);
         cache.remove(primaryKey);
+        if (instance.creationalContext != null) {
+            instance.creationalContext.release();
+        }
     }
 
     private void checkAuthorization(Method callMethod, InterfaceType interfaceType) throws
ApplicationException {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/Instance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/Instance.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/Instance.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/Instance.java
Mon Oct  3 16:58:53 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.core.mdb;
 
+import javax.enterprise.context.spi.CreationalContext;
 import java.util.Map;
 
 /**
@@ -24,9 +25,11 @@ import java.util.Map;
 public class Instance {
     public final Object bean;
     public final Map<String,Object> interceptors;
+    public final CreationalContext creationalContext;
 
-    public Instance(Object bean, Map<String, Object> interceptors) {
+    public Instance(Object bean, Map<String, Object> interceptors, CreationalContext
creationalContext) {
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
     }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbInstanceFactory.java
Mon Oct  3 16:58:53 2011
@@ -169,6 +169,9 @@ public class MdbInstanceFactory {
             List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
             InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove,
Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);
             interceptorStack.invoke();
+            if (instance.creationalContext != null) {
+                instance.creationalContext.release();
+            }
         } catch (Throwable re) {
             MdbInstanceFactory.logger.error("The bean instance " + instance.bean + " threw
a system exception:" + re, re);
         } finally {
@@ -209,7 +212,7 @@ public class MdbInstanceFactory {
                 ejbCreate.invoke();
             }
 
-            return new Instance(context.getBean(), context.getInterceptors());
+            return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext());
         } catch (Throwable e) {
             if (e instanceof java.lang.reflect.InvocationTargetException) {
                 e = ((java.lang.reflect.InvocationTargetException) e).getTargetException();

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/Instance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/Instance.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/Instance.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/Instance.java
Mon Oct  3 16:58:53 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.core.singleton;
 
+import javax.enterprise.context.spi.CreationalContext;
 import java.util.Map;
 import java.util.concurrent.locks.ReadWriteLock;
 
@@ -26,10 +27,12 @@ public class Instance {
     public final Object bean;
     public final Map<String,Object> interceptors;
     public final ReadWriteLock lock;
+    public final CreationalContext creationalContext;
 
-    public Instance(Object bean, Map<String, Object> interceptors, ReadWriteLock lock)
{
+    public Instance(Object bean, Map<String, Object> interceptors, CreationalContext
creationalContext, ReadWriteLock lock) {
         this.bean = bean;
         this.interceptors = interceptors;
         this.lock = lock;
+        this.creationalContext = creationalContext;
     }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonInstanceManager.java
Mon Oct  3 16:58:53 2011
@@ -196,7 +196,7 @@ public class SingletonInstanceManager {
                 lock = new ReentrantReadWriteLock();
             }
 
-            return new Instance(context.getBean(), context.getInterceptors(), lock);
+            return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext(),
lock);
         } catch (Throwable e) {
             if (e instanceof java.lang.reflect.InvocationTargetException) {
                 e = ((java.lang.reflect.InvocationTargetException) e).getTargetException();
@@ -256,6 +256,9 @@ public class SingletonInstanceManager {
             try{
                 //Call the chain
                 interceptorStack.invoke();
+                if (instance.creationalContext != null) {
+                    instance.creationalContext.release();
+                }
             } catch(Throwable e) {
                 //RollBack Transaction
                 EjbTransactionUtil.handleSystemException(transactionPolicy, e, callContext);

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/Instance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/Instance.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/Instance.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/Instance.java
Mon Oct  3 16:58:53 2011
@@ -25,6 +25,7 @@ import org.apache.openejb.util.Duration;
 import org.apache.openejb.util.Index;
 import org.apache.openejb.util.PojoSerialization;
 
+import javax.enterprise.context.spi.CreationalContext;
 import javax.persistence.EntityManagerFactory;
 import javax.transaction.Transaction;
 import java.io.ObjectStreamException;
@@ -40,6 +41,7 @@ public class Instance implements Seriali
     public final BeanContext beanContext;
     public final Object primaryKey;
     public final Object bean;
+    public CreationalContext creationalContext;
     public final Map<String, Object> interceptors;
 
     private boolean inUse;
@@ -53,22 +55,24 @@ public class Instance implements Seriali
     private Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>
entityManagers;
     private final JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray;
 
-    public Instance(BeanContext beanContext, Object primaryKey, Object bean, Map<String,
Object> interceptors, Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>
entityManagers) {
+    public Instance(BeanContext beanContext, Object primaryKey, Object bean, CreationalContext
creationalContext, Map<String, Object> interceptors, Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker>
entityManagers) {
         this.beanContext = beanContext;
         this.primaryKey = primaryKey;
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
         this.entityManagers = entityManagers;
         this.entityManagerArray = null;
     }
 
-    public Instance(Object deploymentId, Object primaryKey, Object bean, Map<String, Object>
interceptors, JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray) {
+    public Instance(Object deploymentId, Object primaryKey, Object bean, CreationalContext
creationalContext, Map<String, Object> interceptors, JtaEntityManagerRegistry.EntityManagerTracker[]
entityManagerArray) {
         this.beanContext = SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext(deploymentId);
         if (beanContext == null) {
             throw new IllegalArgumentException("Unknown deployment " + deploymentId);
         }
         this.primaryKey = primaryKey;
         this.bean = bean;
+        this.creationalContext = creationalContext;
         this.interceptors = interceptors;
         this.entityManagerArray = entityManagerArray;
     }
@@ -146,6 +150,7 @@ public class Instance implements Seriali
         public final Object deploymentId;
         public final Object primaryKey;
         public final Object bean;
+        public final CreationalContext creationalContext;
         public final Map<String, Object> interceptors;
         public final JtaEntityManagerRegistry.EntityManagerTracker[] entityManagerArray;
 
@@ -153,6 +158,7 @@ public class Instance implements Seriali
             deploymentId = i.beanContext.getDeploymentID();
             primaryKey = i.primaryKey;
             bean = toSerializable(i.bean);
+            creationalContext = i.creationalContext;
 
             interceptors = new HashMap<String, Object>(i.interceptors.size());
             for (Map.Entry<String, Object> e : i.interceptors.entrySet()) {
@@ -185,7 +191,7 @@ public class Instance implements Seriali
             // Anything wrapped with PojoSerialization will have been automatically
             // unwrapped via it's own readResolve so passing in the raw bean
             // and interceptors variables is totally fine.
-            return new Instance(deploymentId, primaryKey, bean, interceptors, entityManagerArray);
+            return new Instance(deploymentId, primaryKey, bean, creationalContext, interceptors,
entityManagerArray);
         }
     }
 }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
Mon Oct  3 16:58:53 2011
@@ -386,7 +386,7 @@ public class StatefulContainer implement
                     final InstanceContext context = beanContext.newInstance();
 
                     // Wrap-up everthing into a object
-                    instance = new Instance(beanContext, primaryKey, context.getBean(), context.getInterceptors(),
entityManagers);
+                    instance = new Instance(beanContext, primaryKey, context.getBean(), 
context.getCreationalContext(), context.getInterceptors(), entityManagers);
 
                 } catch (Throwable throwable) {
                     ThreadContext callContext = ThreadContext.getThreadContext();
@@ -770,8 +770,11 @@ public class StatefulContainer implement
             return;
         }
 
-        checkedOutInstances.remove(primaryKey);
+        Instance instance = checkedOutInstances.remove(primaryKey);
         cache.remove(primaryKey);
+        if (instance.creationalContext != null) {
+            instance.creationalContext.release();
+        }
     }
 
     private void checkAuthorization(Method callMethod, InterfaceType interfaceType) throws
ApplicationException {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/Instance.java
Mon Oct  3 16:58:53 2011
@@ -18,6 +18,7 @@ package org.apache.openejb.core.stateles
 
 import org.apache.openejb.util.Pool;
 
+import javax.enterprise.context.spi.CreationalContext;
 import java.util.Map;
 
 /**
@@ -26,12 +27,14 @@ import java.util.Map;
 public class Instance {
     public final Object bean;
     public final Map<String, Object> interceptors;
+    public CreationalContext creationalContext;
 
     private Pool<Instance>.Entry poolEntry;
 
-    public Instance(Object bean, Map<String, Object> interceptors) {
+    public Instance(Object bean, Map<String, Object> interceptors, CreationalContext
creationalContext) {
         this.bean = bean;
         this.interceptors = interceptors;
+        this.creationalContext = creationalContext;
     }
 
     public Pool<Instance>.Entry getPoolEntry() {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?rev=1178455&r1=1178454&r2=1178455&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
Mon Oct  3 16:58:53 2011
@@ -190,7 +190,7 @@ public class StatelessInstanceManager {
                 }
             }
 
-            return new Instance(context.getBean(), context.getInterceptors());
+            return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext());
         } catch (Throwable e) {
             if (e instanceof InvocationTargetException) {
                 e = ((InvocationTargetException) e).getTargetException();
@@ -261,6 +261,10 @@ public class StatelessInstanceManager {
             InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove,
Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);
 
             interceptorStack.invoke();
+
+            if (instance.creationalContext != null) {
+                instance.creationalContext.release();
+            }
         } catch (Throwable re) {
             logger.error("The bean instance " + instance + " threw a system exception:" +
re, re);
         }



Mime
View raw message