[jboss-cvs] JBossAS SVN: r73456 - in projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3: cache/tree and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat May 17 08:41:54 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-05-17 08:41:54 -0400 (Sat, 17 May 2008)
New Revision: 73456

Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulBeanContext.java
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
Log:
[EJBTHREE-1367] Remove pool from SFSB creation/destruction

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2008-05-16 19:51:41 UTC (rev 73455)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/simple/SimpleStatefulCache.java	2008-05-17 12:41:54 UTC (rev 73456)
@@ -34,8 +34,8 @@
 import org.jboss.ejb3.annotation.CacheConfig;
 import org.jboss.ejb3.annotation.PersistenceManager;
 import org.jboss.ejb3.cache.StatefulCache;
-import org.jboss.ejb3.pool.Pool;
 import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.logging.Logger;
 
 /**
@@ -48,7 +48,7 @@
 {
    private Logger log = Logger.getLogger(SimpleStatefulCache.class);
 
-   private Pool pool;
+   private StatefulContainer container;
    private CacheMap cacheMap;
    private int maxSize = 1000;
    private StatefulSessionPersistenceManager pm;
@@ -240,8 +240,8 @@
 
    public void initialize(EJBContainer container) throws Exception
    {
+      this.container = (StatefulContainer) container;
       Advisor advisor = container.getAdvisor();
-      this.pool = container.getPool();
       cacheMap = new CacheMap();
       PersistenceManager pmConfig = (PersistenceManager) advisor.resolveAnnotation(PersistenceManager.class);
       EJBContainer ejbContainer = (EJBContainer)container;
@@ -311,34 +311,7 @@
 
    public StatefulBeanContext create()
    {
-      StatefulBeanContext ctx = null;
-      try
-      {
-         ctx = (StatefulBeanContext) pool.get();
-         
-         if (log.isTraceEnabled())
-         {
-            log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
-         }
-         synchronized (cacheMap)
-         {
-            cacheMap.put(ctx.getId(), ctx);
-         }
-         ctx.setInUse(true);
-         ctx.lastUsed = System.currentTimeMillis();
-         ++createCount;
-      }
-      catch (EJBException e)
-      {
-         e.printStackTrace();
-         throw e;
-      }
-      catch (Exception e)
-      {
-         e.printStackTrace();
-         throw new EJBException(e);
-      }
-      return ctx;
+      return create(null, null);
    }
 
    public StatefulBeanContext create(Class<?>[] initTypes, Object[] initValues)
@@ -346,7 +319,7 @@
       StatefulBeanContext ctx = null;
       try
       {
-         ctx = (StatefulBeanContext) pool.get(initTypes, initValues);
+         ctx = container.create(initTypes, initValues);
          if (log.isTraceEnabled())
          {
             log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
@@ -454,7 +427,7 @@
       if(ctx == null)
          throw new NoSuchEJBException("Could not find Stateful bean: " + key);
       if (!ctx.isRemoved())
-         pool.remove(ctx);
+         container.destroy(ctx);
       
       ++removeCount;
       

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2008-05-16 19:51:41 UTC (rev 73455)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2008-05-17 12:41:54 UTC (rev 73456)
@@ -52,6 +52,7 @@
 import org.jboss.ejb3.stateful.NestedStatefulBeanContext;
 import org.jboss.ejb3.stateful.ProxiedStatefulBeanContext;
 import org.jboss.ejb3.stateful.StatefulBeanContext;
+import org.jboss.ejb3.stateful.StatefulContainer;
 import org.jboss.ha.framework.server.CacheManagerLocator;
 import org.jboss.logging.Logger;
 import org.jboss.util.id.GUID;
@@ -83,7 +84,6 @@
 
    private ThreadLocal<Boolean> localActivity = new ThreadLocal<Boolean>();
    private Logger log = Logger.getLogger(StatefulTreeCache.class);
-   private Pool pool;
    private WeakReference<ClassLoader> classloader;
    private Cache cache;
    private Fqn cacheNode;
@@ -102,34 +102,12 @@
    protected Map<Object, Long> beans = new ConcurrentHashMap<Object, Long>();
    protected CacheConfig cacheConfig;
    protected CacheManager cacheManager;
-   protected EJBContainer ejbContainer;
+   protected StatefulContainer ejbContainer;
    protected Object shutdownLock = new Object();
 
    public StatefulBeanContext create()
-   {
-      StatefulBeanContext ctx = null;
-      try
-      {
-         ctx = (StatefulBeanContext) pool.get();
-         if (log.isTraceEnabled())
-         {
-            log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
-         }
-         putInCache(ctx);
-         ctx.setInUse(true);
-         ctx.lastUsed = System.currentTimeMillis();
-         ++createCount;
-         beans.put(ctx.getId(), new Long(ctx.lastUsed));
-      }
-      catch (EJBException e)
-      {
-         throw e;
-      }
-      catch (Exception e)
-      {
-         throw new EJBException(e);
-      }
-      return ctx;
+   {      
+      return create(null, null);
    }
 
    public StatefulBeanContext create(Class[] initTypes, Object[] initValues)
@@ -137,7 +115,7 @@
       StatefulBeanContext ctx = null;
       try
       {
-         ctx = (StatefulBeanContext) pool.get(initTypes, initValues);
+         ctx = ejbContainer.create(initTypes, initValues);
          if (log.isTraceEnabled())
          {
             log.trace("Caching context " + ctx.getId() + " of type " + ctx.getClass());
@@ -238,7 +216,13 @@
             throw new NoSuchEJBException("Could not find Stateful bean: " + key);
          
          if (!ctx.isRemoved())
-            pool.remove(ctx);
+         {
+            ejbContainer.destroy(ctx);
+         }
+         else if (log.isTraceEnabled())
+         {
+            log.trace("remove: " +id.toString() + " already removed from pool");
+         }
 
          if (ctx.getCanRemoveFromCache())
          {
@@ -250,6 +234,10 @@
             // We can't remove the ctx as it contains live nested beans
             // But, we must replicate it so other nodes know the parent is removed!
             putInCache(ctx);
+            if(log.isTraceEnabled())
+            {
+               log.trace("remove: removed bean " +id.toString() + " cannot be removed from cache");
+            }
          }
 
          ++removeCount;
@@ -298,11 +286,10 @@
 
    public void initialize(EJBContainer container) throws Exception
    {
-      this.ejbContainer = container;
+      this.ejbContainer = (StatefulContainer) container;
       
       log = Logger.getLogger(getClass().getName() + "." + this.ejbContainer.getEjbName());
 
-      this.pool = this.ejbContainer.getPool();
       this.classloader = new WeakReference<ClassLoader>(this.ejbContainer.getClassloader());
       
       cacheConfig = (CacheConfig) this.ejbContainer.getAnnotation(CacheConfig.class);

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java	2008-05-16 19:51:41 UTC (rev 73455)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/pool/AbstractPool.java	2008-05-17 12:41:54 UTC (rev 73456)
@@ -23,9 +23,6 @@
 
 import org.jboss.ejb3.BeanContext;
 import org.jboss.ejb3.Container;
-import org.jboss.ejb3.EJBContainer;
-import org.jboss.ejb3.annotation.CacheConfig;
-import org.jboss.ejb3.stateful.StatefulBeanContext;
 import org.jboss.injection.Injector;
 import org.jboss.logging.Logger;
 
@@ -80,20 +77,6 @@
    {
       BeanContext ctx;
       ctx = createBeanContext();
-      if (ctx instanceof StatefulBeanContext)
-      {         
-         StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
-         // FIXME: remove this class cast
-         EJBContainer c = (EJBContainer) container;
-         // Tell context how to handle replication
-         CacheConfig config = c.getAnnotation(CacheConfig.class);
-         if (config != null)
-         {
-            sfctx.setReplicationIsPassivation(config.replicationIsPassivation());
-         }
-         // this is for propagated extended PC's
-         ctx = sfctx = sfctx.pushContainedIn();
-      }
       container.pushContext(ctx);
       try
       {
@@ -111,12 +94,6 @@
       finally
       {
          container.popContext();
-         if (ctx instanceof StatefulBeanContext)
-         {
-            // this is for propagated extended PC's
-            StatefulBeanContext sfctx = (StatefulBeanContext) ctx;
-            sfctx.popContainedIn();
-         }
       }
       
       container.invokePostConstruct(ctx, initValues);

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulBeanContext.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulBeanContext.java	2008-05-16 19:51:41 UTC (rev 73455)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulBeanContext.java	2008-05-17 12:41:54 UTC (rev 73456)
@@ -41,6 +41,7 @@
 import org.jboss.ejb3.Ejb3Registry;
 import org.jboss.ejb3.ThreadLocalStack;
 import org.jboss.ejb3.cache.Identifiable;
+import org.jboss.ejb3.cache.Optimized;
 import org.jboss.ejb3.cache.StatefulCache;
 import org.jboss.ejb3.interceptor.InterceptorInfo;
 import org.jboss.ejb3.session.SessionSpecBeanContext;
@@ -59,7 +60,9 @@
  * 
  * @version $Revision$
  */
-public class StatefulBeanContext extends SessionSpecBeanContext<StatefulContainer> implements Identifiable, Externalizable, org.jboss.ejb3.tx.container.StatefulBeanContext<Object>
+public class StatefulBeanContext 
+   extends SessionSpecBeanContext<StatefulContainer> 
+   implements Identifiable, Externalizable, org.jboss.ejb3.tx.container.StatefulBeanContext<Object>
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = -102470788178912606L;
@@ -366,6 +369,14 @@
          nested.replicationIsPassivation = replicationIsPassivation;
          containedIn.addContains(nested);
          thisPtr = new ProxiedStatefulBeanContext(nested);
+         
+         if (log.isTraceEnabled())
+         {
+            log.trace("Created ProxiedStatefulBeanContext for " + 
+                      containerGuid + "/" + id + " contained in " + 
+                      containedIn.getContainer().getIdentifier() + "/" + 
+                      containedIn.getId());
+         }
       }
       propagatedContainedIn.push(thisPtr);
       return thisPtr;
@@ -406,8 +417,10 @@
    public void prePassivate()
    {
       if (!removed && !passivated)
-      {  
-         extractBeanAndInterceptors(); // make sure we're unmarshalled
+      {   
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePrePassivate(this);
          passivated = true;
       }
@@ -431,7 +444,9 @@
    {
       if (!removed && passivated)
       {  
-         extractBeanAndInterceptors(); // make sure we're unmarshalled
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePostActivate(this);
          passivated = false;
       }
@@ -459,7 +474,9 @@
    {
       if (!removed && !passivated)
       {  
-         extractBeanAndInterceptors(); // make sure we're unmarshalled
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePrePassivate(this);
          passivated = true;
       }
@@ -484,8 +501,10 @@
    public void activateAfterReplication()
    {
       if (!removed && passivated)
-      {         
-         extractBeanAndInterceptors(); // make sure we're unmarshalled
+      {  
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePostActivate(this);
          passivated = false;
       }
@@ -519,7 +538,9 @@
    {
       if (!removed && replicationIsPassivation && !passivated)
       {  
-         getInstance(); // make sure we're unmarshalled
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePrePassivate(this);
          passivated = true;
       }
@@ -548,7 +569,9 @@
       // if we are marked as passivated
       if (!removed && passivated)
       {  
-         extractBeanAndInterceptors(); // make sure we're unmarshalled
+         // make sure we're unmarshalled
+         if (bean == null)
+            extractBeanAndInterceptors(); 
          getContainer().invokePostActivate(this);
          passivated = false;
       }
@@ -791,6 +814,16 @@
       }
       assert bean != null : "bean is null";
       return bean;
+   }   
+
+   public boolean isModified()
+   {
+      Object ourBean = getInstance();
+      if (ourBean instanceof Optimized)
+      {
+         return ((Optimized) ourBean).isModified();
+      }
+      return true;
    }
 
    @Override
@@ -946,6 +979,30 @@
    {
       return this.getId();
    }
+
+//   @Override
+//   public boolean equals(Object obj)
+//   {
+//      if (this == obj)
+//         return true;
+//      
+//      // Don't use instanceof check here as subclasses w/ same id are not equal
+//      if (obj != null && obj.getClass() == getClass())
+//      {
+//         StatefulBeanContext other = (StatefulBeanContext) obj;
+//         return (containerClusterUid.equals(other.containerClusterUid) && id.equals(other.id));
+//      }
+//      return false;
+//   }
+//
+//   @Override
+//   public int hashCode()
+//   {
+//      int result = 11;
+//      result = 29 * result + containerClusterUid.hashCode();
+//      result = 29 * result + id.hashCode();
+//      return result;
+//   }
    
    private static class XPCCloseSynchronization implements Synchronization
    {

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2008-05-16 19:51:41 UTC (rev 73455)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/stateful/StatefulContainer.java	2008-05-17 12:41:54 UTC (rev 73456)
@@ -53,6 +53,7 @@
 import org.jboss.ejb3.EJBContainerInvocation;
 import org.jboss.ejb3.Ejb3Deployment;
 import org.jboss.ejb3.annotation.Cache;
+import org.jboss.ejb3.annotation.CacheConfig;
 import org.jboss.ejb3.annotation.Clustered;
 import org.jboss.ejb3.annotation.LocalBinding;
 import org.jboss.ejb3.annotation.RemoteBinding;
@@ -99,9 +100,44 @@
 
    public StatefulBeanContext create(Class<?>[] initTypes, Object[] initValues)
    {
-      // FIXME: this method is not finished. In the old setup the call would go
-      // through Pool which would call the init method.
-      return (StatefulBeanContext) createBeanContext();
+      StatefulBeanContext sfctx = (StatefulBeanContext) createBeanContext();
+      // Tell context how to handle replication
+      CacheConfig config = getAnnotation(CacheConfig.class);
+      if (config != null)
+      {
+         sfctx.setReplicationIsPassivation(config.replicationIsPassivation());
+      }
+
+      // this is for propagated extended PC's
+      sfctx = sfctx.pushContainedIn();
+      
+      pushContext(sfctx);
+      try
+      {
+         if (injectors != null)
+         {
+            for (Injector injector : injectors)
+            {
+               injector.inject(sfctx);
+            }
+         }
+
+         sfctx.initialiseInterceptorInstances();
+
+      }
+      finally
+      {
+         popContext();
+         // this is for propagated extended PC's
+         sfctx.popContainedIn();
+      }
+      
+      invokePostConstruct(sfctx, initValues);
+      
+      //TODO This needs to be reimplemented as replacement for create() on home interface
+      invokeInit(sfctx.getInstance(), initTypes, initValues);
+      
+      return sfctx;
    }
    
    @Override
@@ -202,9 +238,16 @@
       return factory;
    }
    
-   public void destroy(StatefulBeanContext obj)
+   public void destroy(StatefulBeanContext ctx)
    {
-      invokePreDestroy(obj);
+      try
+      {
+         invokePreDestroy(ctx);
+      }
+      finally
+      {
+         ctx.remove();
+      }
    }
    
    public Object getMBean()
@@ -258,8 +301,8 @@
 
    public void stop() throws Exception
    {
+      super.stop();
       if (cache != null) cache.stop();
-      super.stop();
    }
 
    public StatefulCache getCache()




More information about the jboss-cvs-commits mailing list