[jboss-cvs] JBossAS SVN: r61593 - branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 22 12:28:58 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-22 12:28:58 -0400 (Thu, 22 Mar 2007)
New Revision: 61593

Modified:
   branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
Log:
[EJBTHREE-923] Avoid unnecessary passivation/activation callbacks for beans cached on remote nodes

Modified: branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java
===================================================================
--- branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-03-22 16:21:10 UTC (rev 61592)
+++ branches/Branch_4_2/ejb3/src/main/org/jboss/ejb3/cache/tree/StatefulTreeCache.java	2007-03-22 16:28:58 UTC (rev 61593)
@@ -78,6 +78,7 @@
       GRAVITATE_OPTION.setForceDataGravitation(true);
    }
    
+   private ThreadLocal<Boolean> localActivity = new ThreadLocal<Boolean>();
    private Logger log = Logger.getLogger(StatefulTreeCache.class);
    private Pool pool;
    private WeakReference<ClassLoader> classloader;
@@ -158,8 +159,10 @@
    {
       StatefulBeanContext entry = null;
       Fqn id = new Fqn(cacheNode, key.toString());
+      Boolean active = localActivity.get();
       try
       {
+         localActivity.set(Boolean.TRUE);
          Option opt = new Option();
          opt.setForceDataGravitation(true);
          entry = (StatefulBeanContext) cache.get(id, "bean", opt);
@@ -169,6 +172,10 @@
          RuntimeException re = convertToRuntimeException(e);
          throw re;
       }
+      finally
+      {
+         localActivity.set(active);
+      }
       
       if (entry == null)
       {
@@ -419,9 +426,19 @@
    
    private void putInCache(StatefulBeanContext ctx) throws CacheException
    {
-      ctx.preReplicate();
-      cache.put(new Fqn(cacheNode, ctx.getId().toString()), "bean", ctx);
-      ctx.markedForReplication = false;      
+      Boolean active = localActivity.get();
+      try
+      {
+         localActivity.set(Boolean.TRUE);
+         ctx.preReplicate();
+         cache.put(new Fqn(cacheNode, ctx.getId().toString()), "bean", ctx);
+         ctx.markedForReplication = false;
+      }
+      finally
+      {
+         localActivity.set(active);
+      }
+      
    }
    
    /** 
@@ -446,11 +463,21 @@
       @Override
       public void nodeActivate(Fqn fqn, boolean pre) 
       {
-         // Ignore everything but "post" events for nodes in our region
+         // Ignore everything but locally originating "post" events 
+         // for nodes in our region
          if(pre) return;
          if(fqn.size() != FQN_SIZE) return;
          if(!fqn.isChildOrEquals(cacheNode)) return;
 
+         // Don't activate a bean just so we can replace the object 
+         // with a replicated one
+         if (Boolean.TRUE != localActivity.get()) 
+         {
+            // But we do want to record that the bean's now in memory
+            --passivatedCount;
+            return; 
+         }
+         
          StatefulBeanContext bean = null;
          try {
             // TODO Can this cause deadlock in the cache level? Should be ok but need review.
@@ -500,9 +527,11 @@
          if(!fqn.isChildOrEquals(cacheNode)) return;
 
          StatefulBeanContext bean = null;
-         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();         
+         ClassLoader oldCl = Thread.currentThread().getContextClassLoader();  
+         Boolean active = localActivity.get();       
          try 
          {
+            localActivity.set(Boolean.TRUE);
             // EJBTHREE-746 Use peek to bypass interceptors and thus avoid generating another 
             // eviction event (which will cause another attempt to passivate)
             // Caller thread (eviction) already has a lock on the node
@@ -571,6 +600,7 @@
          finally
          {
             Thread.currentThread().setContextClassLoader(oldCl);
+            localActivity.set(active);
          }
       }
    }




More information about the jboss-cvs-commits mailing list