[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...

Manik Surtani msurtani at jboss.com
Tue Sep 19 09:52:33 EDT 2006


  User: msurtani
  Date: 06/09/19 09:52:33

  Modified:    src/org/jboss/cache/interceptors   
                        CacheLoaderInterceptor.java
                        CacheStoreInterceptor.java
                        PassivationInterceptor.java
  Log:
  Fixed moving with cache loaders
  
  Revision  Changes    Path
  1.55      +96 -49    JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheLoaderInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheLoaderInterceptor.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -b -r1.54 -r1.55
  --- CacheLoaderInterceptor.java	7 Sep 2006 13:52:28 -0000	1.54
  +++ CacheLoaderInterceptor.java	19 Sep 2006 13:52:33 -0000	1.55
  @@ -32,7 +32,7 @@
    * Loads nodes that don't exist at the time of the call into memory from the CacheLoader
    *
    * @author Bela Ban
  - * @version $Id: CacheLoaderInterceptor.java,v 1.54 2006/09/07 13:52:28 msurtani Exp $
  + * @version $Id: CacheLoaderInterceptor.java,v 1.55 2006/09/19 13:52:33 msurtani Exp $
    */
   public class CacheLoaderInterceptor extends BaseCacheLoaderInterceptor implements CacheLoaderInterceptorMBean
   {
  @@ -94,7 +94,7 @@
       */
      public Object invoke(MethodCall m) throws Throwable
      {
  -      Fqn fqn = null; // if set, load the data
  +      Fqn fqn = null, fqn2 = null; // if set, load the data.  fqn2 for 2nd fqn in move().
   
         Object[]     args = m.getArgs();
         boolean acquireLock = false; // do we need to acquire a lock if we load this node from cloader?
  @@ -104,6 +104,8 @@
         InvocationContext ctx = cache.getInvocationContext();
         TransactionEntry entry = null;
         GlobalTransaction gtx;
  +      boolean recursive = false; // do we also load children?
  +
   
         if ((gtx = ctx.getGlobalTransaction()) != null)
         {
  @@ -132,6 +134,13 @@
                  acquireLock = true;
               }
               break;
  +         case MethodDeclarations.moveMethodLocal_id:
  +            fqn = (Fqn) args[1];
  +            fqn2 = (Fqn) args[0];
  +            acquireLock = true;
  +            //initNode = true;
  +            recursive = true;
  +            break;
            case MethodDeclarations.addChildMethodLocal_id:
               fqn = (Fqn) args[1];
               break;
  @@ -173,12 +182,23 @@
   
         if (fqn != null)
         {
  +         if (fqn2 != null) loadIfNeeded(fqn2, key, initNode, acquireLock, m, entry, false);
  +         loadIfNeeded(fqn, key, initNode, acquireLock, m, entry, recursive);
  +      }
  +
  +      return super.invoke(m);
  +   }
  +
   
  +   private void loadIfNeeded(Fqn fqn, Object key, boolean initNode, boolean acquireLock, MethodCall m, TransactionEntry entry, boolean recursive) throws Throwable
  +   {
            obtainLoaderLock(fqn);
  +
            try
            {
   
               TreeCacheProxyImpl cacheImpl = (TreeCacheProxyImpl) cache;
  +
               Node n = cacheImpl.peekNode(fqn);
   
               boolean mustLoad = mustLoad(n, key);
  @@ -210,17 +230,16 @@
                  // - Manik Surtani (21 March 2006)
                  if (acquireLock)
                  {
  -                  lock(fqn, DataNode.LockType.WRITE, false); // not recursive
  +               lock(fqn, DataNode.LockType.WRITE, false); // non-recursive for now
                  }
               }
   
               // The complete list of children aren't known without loading them
  -            if (m.getMethodId() == MethodDeclarations.getChildrenNamesMethodLocal_id)
  +         if (recursive || m.getMethodId() == MethodDeclarations.getChildrenNamesMethodLocal_id)
               {
  -               loadChildren(fqn, n);
  +            loadChildren(fqn, n, recursive);
               }
   
  -
            }
            finally
            {
  @@ -229,15 +248,12 @@
   
         }
   
  -      return super.invoke(m);
  -   }
  -
      /**
       * Load the children.
       *
       * @param node may be null if the node was not found.
       */
  -   private void loadChildren(Fqn fqn, Node node) throws Throwable
  +   private void loadChildren(Fqn fqn, Node node, boolean recursive) throws Throwable
      {
   
         TreeCacheProxyImpl n = (TreeCacheProxyImpl) node;
  @@ -269,6 +285,8 @@
         // Create if node had not been created already
         if (n == null) n = (TreeCacheProxyImpl) createNodes(fqn, null); // dont care about local transactions
   
  +      System.out.println("*** " + fqn + " has children " + children_names);
  +
         // Create one DataNode per child, mark as UNINITIALIZED
         for (Iterator i = children_names.iterator(); i.hasNext();)
         {
  @@ -277,15 +295,44 @@
            // create child if it didn't exist
            cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
            n.addChild(child_fqn);
  -         findChild(n.getChildren(), child_name).put(TreeCache.UNINITIALIZED, null);
  +         Node child = findChild(n.getChildren(), child_name);
  +         cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
  +         if (isActivation && recursive)
  +         {
  +            // load data for children as well!
  +            child.put(loader.get(child.getFqn()));
  +         }
  +         else
  +         {
  +            child.put(TreeCache.UNINITIALIZED, null);
  +         }
  +         if (recursive)
  +         {
  +            loadChildren(child.getFqn(), child, true);
  +         }
         }
  -      lock(fqn, DataNode.LockType.READ, true); // recursive=true: lock entire subtree
  +      lock(fqn, recursive ? DataNode.LockType.WRITE : DataNode.LockType.READ, true); // recursive=true: lock entire subtree
         n.setChildrenLoaded(true);
      }
   
      private boolean mustLoad(Node n, Object key)
      {
  -      return n == null || (n.getKeys().contains(TreeCache.UNINITIALIZED) && (key == null || !n.getKeys().contains(key)));
  +      boolean mustLoad = n == null || (n.getKeys().contains(TreeCache.UNINITIALIZED) && (key == null || !n.getKeys().contains(key)));
  +      if (log.isTraceEnabled())
  +      {
  +         String reason = null;
  +         if (n == null)
  +         {
  +            reason = "node is null";
  +         }
  +         else if (n.getKeys().contains(TreeCache.UNINITIALIZED))
  +         {
  +            reason = "node is uninitialised";
  +         }
  +         log.trace("mustLoad reason: " + reason);
  +      }
  +
  +      return mustLoad;
      }
   
      public long getCacheLoaderLoads()
  
  
  
  1.32      +36 -9     JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheStoreInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- CacheStoreInterceptor.java	16 Sep 2006 00:23:34 -0000	1.31
  +++ CacheStoreInterceptor.java	19 Sep 2006 13:52:33 -0000	1.32
  @@ -25,7 +25,7 @@
    * through the CacheLoader, either after each method call (no TXs), or at TX commit.
    *
    * @author Bela Ban
  - * @version $Id: CacheStoreInterceptor.java,v 1.31 2006/09/16 00:23:34 msurtani Exp $
  + * @version $Id: CacheStoreInterceptor.java,v 1.32 2006/09/19 13:52:33 msurtani Exp $
    */
   public class CacheStoreInterceptor extends BaseCacheLoaderInterceptor implements CacheStoreInterceptorMBean
   {
  @@ -190,9 +190,6 @@
                  releaseLoaderLock(fqn);
               }
               break;
  -         case MethodDeclarations.moveMethodLocal_id:
  -            recursiveRemoveForMove((Fqn) args[0], (Fqn) args[1]);
  -            break;
         }
   //      }
   
  @@ -203,7 +200,7 @@
         switch (m.getMethodId())
         {
            case MethodDeclarations.moveMethodLocal_id:
  -            recursivePutForMove((Fqn) args[0], (Fqn) args[1]);
  +            doMove((Fqn) args[0], (Fqn) args[1]);
               break;
            case MethodDeclarations.putDataMethodLocal_id:
            case MethodDeclarations.putDataEraseMethodLocal_id:
  @@ -256,14 +253,44 @@
         }
      }
   
  -   private void recursivePutForMove(Fqn parent, Fqn node)
  +   private void doMove(Fqn parent, Fqn node) throws Exception
  +   {
  +      Fqn newNodeFqn = new Fqn(parent, node.getLast());
  +      //NodeImpl n = (NodeImpl) ((TreeCacheProxyImpl) cache).peek(newNodeFqn);
  +      //recursiveMove(n);
  +//      throw new RuntimeException("Implement me!");
  +
  +      recursiveMove(node, newNodeFqn);
  +      try
      {
  -      throw new RuntimeException("Implement me!");
  +         obtainLoaderLock(node);
  +         loader.remove(node);
  +      }
  +      finally
  +      {
  +         releaseLoaderLock(node);
  +      }
      }
   
  -   private void recursiveRemoveForMove(Fqn parent, Fqn node)
  +   private void recursiveMove(Fqn n, Fqn nn) throws Exception
      {
  -      throw new RuntimeException("Implement me!");
  +      List fqns = new ArrayList();
  +      fqns.add(n);
  +      fqns.add(nn);
  +      obtainLoaderLocks(fqns);
  +      try
  +      {
  +         loader.put(nn, loader.get(n));
  +         //recurse
  +         for (Object child : loader.getChildrenNames(n))
  +         {
  +            recursiveMove(new Fqn(n, child), new Fqn(nn, child));
  +         }
  +      }
  +      finally
  +      {
  +         releaseLoaderLocks(fqns);
  +      }
      }
   
      private List getFqnsFromModificationList(List<MethodCall> modifications)
  
  
  
  1.28      +13 -2     JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PassivationInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PassivationInterceptor.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -b -r1.27 -r1.28
  --- PassivationInterceptor.java	5 Sep 2006 18:09:56 -0000	1.27
  +++ PassivationInterceptor.java	19 Sep 2006 13:52:33 -0000	1.28
  @@ -5,6 +5,7 @@
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
   import org.jboss.cache.TreeCache;
  +import org.jboss.cache.TreeCacheProxyImpl;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -17,7 +18,7 @@
    * CacheLoader, either before each method call (no TXs), or at TX commit.
    *
    * @author <a href="mailto:{hmesha at novell.com}">{Hany Mesha}</a>
  - * @version $Id: PassivationInterceptor.java,v 1.27 2006/09/05 18:09:56 msurtani Exp $
  + * @version $Id: PassivationInterceptor.java,v 1.28 2006/09/19 13:52:33 msurtani Exp $
    */
   public class PassivationInterceptor extends Interceptor implements PassivationInterceptorMBean
   {
  @@ -58,15 +59,19 @@
               Map attributes = getNodeAttributes(fqn);
               // remove internal flag if node was never fully loaded
               if (attributes != null)
  +            {
                  attributes.remove(TreeCache.UNINITIALIZED);
  +            }
               // notify listeners to the cache instance that this node is about to be passivated
               cache.getNotifier().notifyNodePassivated(fqn, true);
               cache.getNotifier().notifyNodePassivated(fqn, false);
               loader.put(fqn, attributes);
            }
            if (getStatisticsEnabled() && configuration.isUseInterceptorMbeans())
  +         {
               m_passivations.increment();
         }
  +      }
   
         return super.invoke(m);
      }
  @@ -94,7 +99,9 @@
      private Map getNodeAttributes(Fqn fqn)
      {
         if (fqn == null)
  +      {
            return null;
  +      }
         Node n = cache;
         int size = fqn.size();
         for (int i = 0; i < size && n != null; i++)
  @@ -103,8 +110,12 @@
            n = n.getChild(new Fqn(fqn.get(i)));
         }
         if (n != null)
  -         return n.getData();
  +      {
  +         return ((TreeCacheProxyImpl) n).currentNode.getData();
  +      }
         else
  +      {
            return null;
      }
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list