You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by dj...@apache.org on 2007/04/17 17:41:02 UTC

svn commit: r529649 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb: ./ core/stateful/ core/stateless/

Author: djencks
Date: Tue Apr 17 08:41:01 2007
New Revision: 529649

URL: http://svn.apache.org/viewvc?view=rev&rev=529649
Log:
OPENEJB-561 clean up pools on undeployment. still need to ejb-remove stateless beans.

Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulBeanManagedTxPolicy.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/UndeployException.java Tue Apr 17 08:41:01 2007
@@ -19,6 +19,7 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 
 /**
  * @version $Rev$ $Date$
@@ -47,6 +48,15 @@
     }
 
     public void printStackTrace(PrintStream s) {
+        super.printStackTrace(s);
+
+        for (Throwable throwable : causes) {
+            s.print("Nested caused by: ");
+            throwable.printStackTrace(s);
+        }
+    }
+    
+    public void printStackTrace(PrintWriter s) {
         super.printStackTrace(s);
 
         for (Throwable throwable : causes) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/SessionSynchronizationCoordinator.java Tue Apr 17 08:41:01 2007
@@ -117,7 +117,7 @@
                 StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) instanceManager.obtainInstance(callContext.getPrimaryKey(), callContext);
                 SessionSynchronization bean = (SessionSynchronization) instance.bean;
                 bean.beforeCompletion();
-                instanceManager.poolInstance(callContext.getPrimaryKey(), instance);
+                instanceManager.poolInstance(callContext, instance);
             } catch (org.apache.openejb.InvalidateReferenceException inv) {
 
             } catch (Exception e) {
@@ -182,7 +182,7 @@
                 SessionSynchronization bean = (SessionSynchronization) instance.bean;
 
                 bean.afterCompletion(status == Status.STATUS_COMMITTED);
-                instanceManager.poolInstance(callContext.getPrimaryKey(), instance);
+                instanceManager.poolInstance(callContext, instance);
             } catch (org.apache.openejb.InvalidateReferenceException inv) {
 
             } catch (Exception e) {
@@ -220,7 +220,7 @@
 
     protected void discardInstance(StatefulInstanceManager instanceManager, ThreadContext callContext) {
         try {
-            instanceManager.freeInstance(callContext.getPrimaryKey());
+            instanceManager.freeInstance(callContext);
         } catch (org.apache.openejb.OpenEJBException oee) {
 
         }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulBeanManagedTxPolicy.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulBeanManagedTxPolicy.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulBeanManagedTxPolicy.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulBeanManagedTxPolicy.java Tue Apr 17 08:41:01 2007
@@ -44,8 +44,7 @@
             context.clientTx = suspendTransaction(context);
 
             // Resume previous Bean transaction if there was one
-            Object primaryKey = context.callContext.getPrimaryKey();
-            Transaction beanTransaction = instanceManager.getBeanTransaction(primaryKey);
+            Transaction beanTransaction = instanceManager.getBeanTransaction(context.callContext);
             if (beanTransaction != null) {
                 context.currentTx = beanTransaction;
                 resumeTransaction(context, context.currentTx);
@@ -72,9 +71,8 @@
             }
 
             // Update the user transaction reference in the bean instance data
-            Object primaryKey = context.callContext.getPrimaryKey();
             StatefulInstanceManager instanceManager = ((StatefulContainer)container).getInstanceManager();
-            instanceManager.setBeanTransaction(primaryKey, context.currentTx);
+            instanceManager.setBeanTransaction(context.callContext, context.currentTx);
         } catch (OpenEJBException e) {
             handleSystemException(e.getRootCause(), instance, context);
         } catch (javax.transaction.SystemException e) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java Tue Apr 17 08:41:01 2007
@@ -62,7 +62,7 @@
     private static final Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.util.resources");
 
     private final Object containerID;
-    private final TransactionManager transactionManager;
+    private final TransactionManager transactionManager;  
     private final SecurityService securityService;
     private final StatefulInstanceManager instanceManager;
     // todo this should be part of the constructor
@@ -82,18 +82,6 @@
         instanceManager = new StatefulInstanceManager(transactionManager, securityService, entityManagerRegistry, passivator, timeOut, poolSize, bulkPassivate);
     }
 
-    private class Data {
-        private final Index<Method, MethodType> methodIndex;
-
-        private Data(Index<Method, MethodType> methodIndex) {
-            this.methodIndex = methodIndex;
-        }
-
-        public Index<Method, MethodType> getMethodIndex() {
-            return methodIndex;
-        }
-    }
-
     private Map<Method, MethodType> getLifecycelMethodsOfInterface(CoreDeploymentInfo deploymentInfo) {
         Map<Method, MethodType> methods = new HashMap<Method, MethodType>();
 
@@ -184,7 +172,7 @@
         return methods;
     }
 
-    private static enum MethodType {
+    static enum MethodType {
         CREATE, REMOVE, BUSINESS
     }
 
@@ -225,11 +213,10 @@
 
     private synchronized void deploy(CoreDeploymentInfo deploymentInfo) throws OpenEJBException {
         Map<Method, MethodType> methods = getLifecycelMethodsOfInterface(deploymentInfo);
-        deploymentInfo.setContainerData(new Data(new Index<Method, MethodType>(methods)));
 
         deploymentsById.put(deploymentInfo.getDeploymentID(), deploymentInfo);
         deploymentInfo.setContainer(this);
-        instanceManager.deploy(deploymentInfo);
+        instanceManager.deploy(deploymentInfo, new Index<Method, MethodType>(methods));
     }
 
     /**
@@ -244,8 +231,7 @@
         if (deployInfo == null)
             throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='" + deployID + "'), Container(id='" + containerID + "')");
 
-        Data data = (Data) deployInfo.getContainerData();
-        MethodType methodType = data.getMethodIndex().get(callMethod);
+        MethodType methodType = instanceManager.getMethodIndex(deployInfo).get(callMethod);
         methodType = (methodType != null) ? methodType : MethodType.BUSINESS;
 
         switch (methodType) {
@@ -281,7 +267,7 @@
             Object o = instanceManager.newInstance(primaryKey, deploymentInfo.getBeanClass());
             StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) o;
 
-            instanceManager.setEntityManagers(primaryKey, entityManagers);
+            instanceManager.setEntityManagers(createContext, entityManagers);
 
             if (!callMethod.getDeclaringClass().equals(DeploymentInfo.BusinessLocalHome.class) && !callMethod.getDeclaringClass().equals(DeploymentInfo.BusinessRemoteHome.class)){
 
@@ -292,7 +278,7 @@
                 _invoke(callMethod, interceptorStack, args, instance, createContext);
             }
 
-            instanceManager.poolInstance(primaryKey, instance);
+            instanceManager.poolInstance(createContext, instance);
 
             return new ProxyInfo(deploymentInfo, primaryKey);
         } finally {
@@ -334,7 +320,7 @@
                 throw e;
             } finally {
                 if (retain){
-                    instanceManager.poolInstance(primKey, instance);
+                    instanceManager.poolInstance(callContext, instance);
                 } else {
                     callContext.setCurrentOperation(Operation.PRE_DESTROY);
 
@@ -353,7 +339,7 @@
                     }
 
                     // todo destroy extended persistence contexts
-                    instanceManager.freeInstance(callContext.getPrimaryKey());
+                    instanceManager.freeInstance(callContext);
                 }
             }
         } finally {
@@ -370,7 +356,6 @@
             Object bean = instanceManager.obtainInstance(primKey, callContext);
             callContext.setCurrentOperation(Operation.BUSINESS);
             callContext.setCurrentAllowedStates(StatefulContext.getStates());
-            Object returnValue = null;
             Method runMethod = deploymentInfo.getMatchingBeanMethod(callMethod);
 
             callContext.set(Method.class, runMethod);
@@ -379,9 +364,9 @@
 
             List<InterceptorData> interceptors = deploymentInfo.getMethodInterceptors(runMethod);
             InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.BUSINESS, interceptors, instance.interceptors);
-            returnValue = _invoke(callMethod, interceptorStack, args, bean, callContext);
+            Object returnValue = _invoke(callMethod, interceptorStack, args, bean, callContext);
 
-            instanceManager.poolInstance(primKey, bean);
+            instanceManager.poolInstance(callContext, bean);
 
             return returnValue;
         } finally {
@@ -406,7 +391,7 @@
             if (e.getRootCause() instanceof TransactionRequiredException ||
                     e.getRootCause() instanceof RemoteException) {
 
-                instanceManager.poolInstance(callContext.getPrimaryKey(), bean);
+                instanceManager.poolInstance(callContext, bean);
             }
             throw e;
         }
@@ -427,7 +412,7 @@
                 txPolicy.handleSystemException(re, bean, txContext);
             } else {
                 /* Application Exception ***********************/
-                instanceManager.poolInstance(callContext.getPrimaryKey(), bean);
+                instanceManager.poolInstance(callContext, bean);
 
                 txPolicy.handleApplicationException(re, type == ExceptionType.APPLICATION_ROLLBACK, txContext);
             }
@@ -475,7 +460,7 @@
 
         // get the managers for the factories
         Object primaryKey = callContext.getPrimaryKey();
-        Map<EntityManagerFactory, EntityManager> entityManagers = instanceManager.getEntityManagers(primaryKey, factories);
+        Map<EntityManagerFactory, EntityManager> entityManagers = instanceManager.getEntityManagers(callContext, factories);
         if (entityManagers == null) return;
 
         // register them
@@ -500,8 +485,7 @@
 
     public void discardInstance(Object bean, ThreadContext threadContext) {
         try {
-            Object primaryKey = threadContext.getPrimaryKey();
-            instanceManager.freeInstance(primaryKey);
+            instanceManager.freeInstance(threadContext);
         } catch (Throwable t) {
             logger.error("", t);
         }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java Tue Apr 17 08:41:01 2007
@@ -64,8 +64,6 @@
 
     private final long timeOut;
 
-    private final Hashtable<Object, BeanEntry> beanIndex = new Hashtable<Object, BeanEntry>();
-
     // queue of beans for LRU algorithm
     private final BeanEntryQueue lruQueue;
 
@@ -97,32 +95,42 @@
         }
     }
 
-    public void deploy(DeploymentInfo deploymentInfo) throws OpenEJBException {
-        deploymentInfo.set(Data.class, new Data());
+    public void deploy(CoreDeploymentInfo deploymentInfo, Index<Method, StatefulContainer.MethodType> index) throws OpenEJBException {
+        deploymentInfo.setContainerData(new Data(index));
     }
 
-    public void undeploy(DeploymentInfo deploymentInfo) throws OpenEJBException {
-        deploymentInfo.set(Data.class, null);
+    public void undeploy(CoreDeploymentInfo deploymentInfo) throws OpenEJBException {
+        Data data = (Data) deploymentInfo.getContainerData();
+        if (data != null) {
+            for (BeanEntry entry: data.getBeanIndex().values()) {
+                lruQueue.remove(entry);
+            }
+            deploymentInfo.setContainerData(null);
+        }
     }
 
+    Index<Method, StatefulContainer.MethodType> getMethodIndex(CoreDeploymentInfo deploymentInfo) {
+        Data data = (Data) deploymentInfo.getContainerData();
+        return data.getMethodIndex();
+    }
 
-    public Transaction getBeanTransaction(Object primaryKey) throws OpenEJBException {
-        BeanEntry entry = getBeanEntry(primaryKey);
+    public Transaction getBeanTransaction(ThreadContext callContext) throws OpenEJBException {
+        BeanEntry entry = getBeanEntry(callContext);
         return entry.beanTransaction;
     }
 
-    public void setBeanTransaction(Object primaryKey, Transaction beanTransaction) throws OpenEJBException {
-        BeanEntry entry = getBeanEntry(primaryKey);
+    public void setBeanTransaction(ThreadContext callContext, Transaction beanTransaction) throws OpenEJBException {
+        BeanEntry entry = getBeanEntry(callContext);
         entry.beanTransaction = beanTransaction;
     }
 
-    public Map<EntityManagerFactory, EntityManager> getEntityManagers(Object primaryKey, Index<EntityManagerFactory, Map> factories) throws OpenEJBException {
-        BeanEntry entry = getBeanEntry(primaryKey);
+    public Map<EntityManagerFactory, EntityManager> getEntityManagers(ThreadContext callContext, Index<EntityManagerFactory, Map> factories) throws OpenEJBException {
+        BeanEntry entry = getBeanEntry(callContext);
         return entry.getEntityManagers(factories);
     }
 
-    public void setEntityManagers(Object primaryKey, Index<EntityManagerFactory, EntityManager> entityManagers) throws OpenEJBException {
-        BeanEntry entry = getBeanEntry(primaryKey);
+    public void setEntityManagers(ThreadContext callContext, Index<EntityManagerFactory, EntityManager> entityManagers) throws OpenEJBException {
+        BeanEntry entry = getBeanEntry(callContext);
         entry.setEntityManagers(entityManagers);
     }
 
@@ -135,12 +143,12 @@
             ObjectRecipe objectRecipe = new ObjectRecipe(beanClass);
             objectRecipe.allow(Option.FIELD_INJECTION);
             objectRecipe.allow(Option.PRIVATE_PROPERTIES);
-            objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
+//            objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
 
             ThreadContext callContext = ThreadContext.getThreadContext();
             CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
             Context ctx = deploymentInfo.getJndiEnc();
-            SessionContext sessionContext = null;
+            SessionContext sessionContext;
             try {
                 sessionContext = (SessionContext) ctx.lookup("java:comp/EJBContext");
             } catch (NamingException e1) {
@@ -214,7 +222,7 @@
 
         // add to index
         BeanEntry entry = new BeanEntry(bean, primaryKey, timeOut);
-        getBeanIndex().put(primaryKey, entry);
+        getBeanIndex(threadContext).put(primaryKey, entry);
 
         return bean;
     }
@@ -240,7 +248,7 @@
         }
 
         // look for entry in index
-        BeanEntry entry = getBeanIndex().get(primaryKey);
+        BeanEntry entry = getBeanIndex(callContext).get(primaryKey);
 
         // if we didn't find the bean in the index, try to activate it
         if (entry == null) {
@@ -258,7 +266,7 @@
         if (queueEntry != null) {
             // if bean is timed out, destroy it
             if (entry.isTimedOut()) {
-                entry = getBeanIndex().remove(entry.primaryKey);
+                entry = getBeanIndex(callContext).remove(entry.primaryKey);
                 handleTimeout(entry, callContext);
                 throw new InvalidateReferenceException(new NoSuchObjectException("Stateful SessionBean has timed-out"));
             }
@@ -318,7 +326,7 @@
         }
 
         // add it to the index
-        getBeanIndex().put(primaryKey, entry);
+        getBeanIndex(callContext).put(primaryKey, entry);
 
         return entry.bean;
     }
@@ -356,12 +364,13 @@
         }
     }
 
-    public void poolInstance(Object primaryKey, Object bean) throws OpenEJBException {
+    public void poolInstance(ThreadContext callContext, Object bean) throws OpenEJBException {
+        Object primaryKey = callContext.getPrimaryKey();
         if (primaryKey == null || bean == null) {
             throw new SystemException("Invalid arguments");
         }
 
-        BeanEntry entry = getBeanIndex().get(primaryKey);
+        BeanEntry entry = getBeanIndex(callContext).get(primaryKey);
         if (entry == null) {
             entry = activate(primaryKey);
             if (entry == null) {
@@ -386,9 +395,9 @@
         }
     }
 
-    public Object freeInstance(Object primaryKey) throws SystemException {
-        BeanEntry entry = null;
-        entry = getBeanIndex().remove(primaryKey);// remove frm index
+    public Object freeInstance(ThreadContext threadContext) throws SystemException {
+        Object primaryKey = threadContext.getPrimaryKey();
+        BeanEntry entry = getBeanIndex(threadContext).remove(primaryKey);// remove frm index
         if (entry == null) {
             entry = activate(primaryKey);
         } else {
@@ -416,7 +425,7 @@
                 if (currentEntry == null) {
                     break;
                 }
-                getBeanIndex().remove(currentEntry.primaryKey);
+                getBeanIndex(threadContext).remove(currentEntry.primaryKey);
                 if (currentEntry.isTimedOut()) {
                     handleTimeout(currentEntry, threadContext);
                 } else {
@@ -466,9 +475,9 @@
         return (BeanEntry) passivator.activate(primaryKey);
     }
 
-    protected InvalidateReferenceException destroy(BeanEntry entry, Exception t) throws SystemException {
+    protected InvalidateReferenceException destroy(ThreadContext callContext, BeanEntry entry, Exception t) throws SystemException {
 
-        getBeanIndex().remove(entry.primaryKey);// remove frm index
+        getBeanIndex(callContext).remove(entry.primaryKey);// remove frm index
         lruQueue.remove(entry);// remove from queue
         if (entry.beanTransaction != null) {
             try {
@@ -490,31 +499,38 @@
 
     }
 
-    protected BeanEntry getBeanEntry(Object primaryKey) throws OpenEJBException {
+    protected BeanEntry getBeanEntry(ThreadContext callContext) throws OpenEJBException {
+        Object primaryKey = callContext.getPrimaryKey();
         if (primaryKey == null) {
             throw new SystemException(new NullPointerException("The primary key is null. Cannot get the bean entry"));
         }
-        BeanEntry entry = getBeanIndex().get(primaryKey);
+        BeanEntry entry = getBeanIndex(callContext).get(primaryKey);
         if (entry == null) {
             Object bean = this.obtainInstance(primaryKey, ThreadContext.getThreadContext());
-            this.poolInstance(primaryKey, bean);
-            entry = getBeanIndex().get(primaryKey);
+            this.poolInstance(callContext, bean);
+            entry = getBeanIndex(callContext).get(primaryKey);
         }
         return entry;
     }
 
-    private Hashtable<Object, BeanEntry> getBeanIndex() {
-        // TODO:
-//        ThreadContext threadContext = null;
-//        DeploymentInfo deployment = threadContext.getDeploymentInfo();
-//        StatefulInstanceManager.Data data = deployment.get(StatefulInstanceManager.Data.class);
-//        return data.getBeanIndex();
-        return beanIndex;
+    private Hashtable<Object, BeanEntry> getBeanIndex(ThreadContext threadContext) {
+        CoreDeploymentInfo deployment = threadContext.getDeploymentInfo();
+        Data data = (Data) deployment.getContainerData();
+        return data.getBeanIndex();
     }
 
     private static class Data {
+        private final Index<Method, StatefulContainer.MethodType> methodIndex;
         private final Hashtable<Object, BeanEntry> beanIndex = new Hashtable<Object, BeanEntry>();
 
+        private Data(Index<Method, StatefulContainer.MethodType> methodIndex) {
+            this.methodIndex = methodIndex;
+        }
+
+        public Index<Method, StatefulContainer.MethodType> getMethodIndex() {
+            return methodIndex;
+        }
+
         public Hashtable<Object, BeanEntry> getBeanIndex() {
             return beanIndex;
         }
@@ -579,7 +595,7 @@
         }
 
         /* [3] Discard the instance */
-        freeInstance(callContext.getPrimaryKey());
+        freeInstance(callContext);
 
         /* [4] throw the java.rmi.RemoteException to the client */
         if (transaction == null) {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContainer.java Tue Apr 17 08:41:01 2007
@@ -92,6 +92,7 @@
 
     public void deploy(DeploymentInfo info) throws OpenEJBException {
         CoreDeploymentInfo deploymentInfo = (CoreDeploymentInfo) info;
+        instanceManager.deploy(deploymentInfo);
         String id = (String) deploymentInfo.getDeploymentID();
         synchronized (this) {
             deploymentRegistry.put(id, deploymentInfo);
@@ -109,6 +110,7 @@
     }
 
     private void undeploy(CoreDeploymentInfo deploymentInfo) {
+        instanceManager.undeploy(deploymentInfo);
         EjbTimerService timerService = deploymentInfo.getEjbTimerService();
         if (timerService != null) {
             timerService.stop();

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?view=diff&rev=529649&r1=529648&r2=529649
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java Tue Apr 17 08:41:01 2007
@@ -16,6 +16,19 @@
  */
 package org.apache.openejb.core.stateless;
 
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
+
 import org.apache.openejb.Injection;
 import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.SystemException;
@@ -35,22 +48,9 @@
 import org.apache.xbean.recipe.Option;
 import org.apache.xbean.recipe.StaticRecipe;
 
-import javax.ejb.SessionBean;
-import javax.ejb.SessionContext;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.transaction.TransactionManager;
-import java.lang.reflect.Method;
-import java.rmi.RemoteException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-
 public class StatelessInstanceManager {
     private static final Logger logger = Logger.getInstance("OpenEJB", "org.apache.openejb.util.resources");
 
-    protected java.util.HashMap poolMap = new HashMap();
     protected int poolLimit = 0;
     protected int beanCount = 0;
     protected boolean strictPooling = false;
@@ -78,15 +78,10 @@
 
     public Object getInstance(ThreadContext callContext)
             throws OpenEJBException {
-        Object bean = null;
-        Object deploymentId = callContext.getDeploymentInfo().getDeploymentID();
-        Stack pool = (Stack) poolMap.get(deploymentId);
-        if (pool == null) {
-            pool = new LinkedListStack(poolLimit);
-            poolMap.put(deploymentId, pool);
-        } else {
-            bean = pool.pop();
-        }
+        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+        Data data = (Data) deploymentInfo.getContainerData();
+        Stack pool = data.getPool();
+        Object bean = pool.pop();
 
         while (strictPooling && bean == null && pool.size() >= poolLimit) {
             poolQueue.waitForAvailableInstance();
@@ -95,7 +90,6 @@
 
         if (bean == null) {
 
-            CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
             Class beanClass = deploymentInfo.getBeanClass();
             ObjectRecipe objectRecipe = new ObjectRecipe(beanClass);
             objectRecipe.allow(Option.FIELD_INJECTION);
@@ -107,7 +101,7 @@
 
             try {
                 Context ctx = deploymentInfo.getJndiEnc();
-                SessionContext sessionContext = null;
+                SessionContext sessionContext;
                 try {
                     sessionContext = (SessionContext) ctx.lookup("java:comp/EJBContext");
                 } catch (NamingException e1) {
@@ -178,7 +172,7 @@
                         callContext.setCurrentOperation(Operation.CREATE);
                         callContext.setCurrentAllowedStates(StatelessContext.getStates());
                         Method create = deploymentInfo.getCreateMethod();
-                        InterceptorStack interceptorStack = new InterceptorStack(bean, create, Operation.CREATE, new ArrayList(), new HashMap());
+                        InterceptorStack interceptorStack = new InterceptorStack(bean, create, Operation.CREATE, new ArrayList<InterceptorData>(), new HashMap());
                         interceptorStack.invoke();
                     }
                 } catch (Exception e) {
@@ -219,9 +213,9 @@
             throw new SystemException("Invalid arguments");
         }
 
-        Object deploymentId = callContext.getDeploymentInfo().getDeploymentID();
-
-        Stack pool = (Stack) poolMap.get(deploymentId);
+        CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
+        Data data = (Data) deploymentInfo.getContainerData();
+        Stack pool = data.getPool();
 
         if (strictPooling) {
             pool.push(bean);
@@ -257,6 +251,19 @@
 
     }
 
+    public void deploy(CoreDeploymentInfo deploymentInfo) {
+        Data data = new Data(poolLimit);
+        deploymentInfo.setContainerData(data);
+    }
+
+    public void undeploy(CoreDeploymentInfo deploymentInfo) {
+        Data data = (Data) deploymentInfo.getContainerData();
+        Stack pool = data.getPool();
+        //TODO ejbRemove on each bean in pool.
+        //clean pool
+        deploymentInfo.setContainerData(null);
+    }
+
     static class PoolQueue {
         private final long waitPeriod;
 
@@ -275,6 +282,18 @@
 
         public synchronized void notifyWaitingThreads() {
             notify();
+        }
+    }
+
+    private static final class Data {
+        private final Stack pool;
+
+        public Data(int poolLimit) {
+            pool = new LinkedListStack(poolLimit);
+        }
+
+        public Stack getPool() {
+            return pool;
         }
     }