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

Manik Surtani msurtani at jboss.com
Thu Nov 2 10:34:06 EST 2006


  User: msurtani
  Date: 06/11/02 10:34:06

  Modified:    src/org/jboss/cache/interceptors   Tag:
                        Branch_JBossCache_1_4_0
                        DataGravitatorInterceptor.java
                        CacheLoaderInterceptor.java
  Log:
  JBCACHE-814
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.3  +409 -388  JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DataGravitatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/DataGravitatorInterceptor.java,v
  retrieving revision 1.16.2.2
  retrieving revision 1.16.2.3
  diff -u -b -r1.16.2.2 -r1.16.2.3
  --- DataGravitatorInterceptor.java	10 Jul 2006 16:21:09 -0000	1.16.2.2
  +++ DataGravitatorInterceptor.java	2 Nov 2006 15:34:06 -0000	1.16.2.3
  @@ -19,9 +19,9 @@
   import org.jboss.cache.buddyreplication.BuddyManager;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.loader.NodeData;
  +import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
  -import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.invocation.MarshalledValueInputStream;
   import org.jgroups.blocks.GroupRequest;
   import org.jgroups.blocks.MethodCall;
  @@ -36,11 +36,11 @@
   
   /**
    * The Data Gravitator interceptor intercepts cache misses and attempts t gravitate data from other parts of the cluster.
  - *
  + * <p/>
    * Only used if Buddy Replication is enabled.  Also, the interceptor only kicks in if an {@link Option} is passed in to
    * force Data Gravitation for a specific invocation or if <b>autoDataGravitation</b> is set to <b>true</b> when configuring 
    * Buddy Replication.
  - *
  + * <p/>
    * See the JBoss Cache User Guide for more details on configuration options.  There is a section dedicated to Buddy Replication
    * in the Replication chapter.
    *
  @@ -110,6 +110,9 @@
                                      log.trace("Passing the put call locally to make sure state is persisted and ownership is correctly established.");
                                      createNode(false, data.backupData);
   
  +                     // now obtain locks -
  +                     lock(data.primaryFqn);
  +
                                      // Clean up the other nodes
                                      cleanBackupData(data);
                                   }
  @@ -159,6 +162,20 @@
           return super.invoke(m);
       }
   
  +   protected void lock(Fqn fqn) throws Throwable
  +   {
  +
  +      if (cache.isNodeLockingOptimistic()) return;
  +
  +      MethodCall meth = MethodCallFactory.create(MethodDeclarations.lockMethodLocal,
  +              new Object[]{fqn,
  +                      new Integer(DataNode.LOCK_TYPE_WRITE),
  +                      Boolean.FALSE});
  +      //super.invoke(meth);
  +      // let's force this to go thru the whole chain, not just from here on.
  +      ((Interceptor) cache.getInterceptors().get(0)).invoke(meth); // need a better way to do this
  +   }
  +
       private boolean isGravitationEnabled(InvocationContext ctx)
       {       
          boolean enabled = ctx.isOriginLocal();
  @@ -280,7 +297,7 @@
           JBCMethodCall cleanup = MethodCallFactory.create(MethodDeclarations.dataGravitationCleanupMethod, new Object[]{getInvocationContext().getGlobalTransaction(), backup.primaryFqn, backup.backupFqn});
   
   
  -        if (log.isTraceEnabled()) log.trace("Performing cleanup on [" +backup.primaryFqn+ "]");
  +      if (log.isTraceEnabled()) log.trace("Performing cleanup on [" + backup.primaryFqn + "]");
           GlobalTransaction gtx = getInvocationContext().getGlobalTransaction();
           if (gtx == null)
           {
  @@ -288,14 +305,15 @@
              // remove main Fqn
              //replicateCall(cache.getMembers(), primaryDataCleanup, syncCommunications);
   
  -           if (log.isTraceEnabled()) log.trace("Performing cleanup on [" +backup.backupFqn+ "]");
  +         if (log.isTraceEnabled()) log.trace("Performing cleanup on [" + backup.backupFqn + "]");
              // remove backup Fqn
              //replicateCall(cache.getMembers(), backupDataCleanup, syncCommunications);
              replicateCall(cache.getMembers(), cleanup, syncCommunications);
           }
           else
           {
  -            if (log.isTraceEnabled()) log.trace("Data gravitation performed under global transaction " + gtx + ".  Not broadcasting cleanups until the tx commits.  Adding to tx mod list instead.");
  +         if (log.isTraceEnabled())
  +            log.trace("Data gravitation performed under global transaction " + gtx + ".  Not broadcasting cleanups until the tx commits.  Adding to tx mod list instead.");
               transactionMods.put(gtx, cleanup);
               TransactionEntry te = getTransactionEntry(gtx);
               te.addModification(cleanup);
  @@ -304,9 +322,10 @@
   
       private Object[] gravitateData(Fqn fqn) throws Exception
       {
  -        if (log.isTraceEnabled()) log.trace("cache=" + cache.getLocalAddress() + "; requesting data gravitation for Fqn " + fqn);
  +      if (log.isTraceEnabled())
  +         log.trace("cache=" + cache.getLocalAddress() + "; requesting data gravitation for Fqn " + fqn);
           Vector mbrs = cache.getMembers();
  -        Boolean searchSubtrees = (buddyManager.isDataGravitationSearchBackupTrees() ? Boolean.TRUE : Boolean.FALSE );
  +      Boolean searchSubtrees = (buddyManager.isDataGravitationSearchBackupTrees() ? Boolean.TRUE : Boolean.FALSE);
           Boolean marshal = cache.getUseRegionBasedMarshalling() ? Boolean.TRUE : Boolean.FALSE;
           MethodCall dGrav = MethodCallFactory.create(MethodDeclarations.dataGravitationMethod, new Object[]{fqn, searchSubtrees, marshal});
           List resps = cache.callRemoteMethods(mbrs, dGrav, GroupRequest.GET_FIRST, true, buddyManager.getBuddyCommunicationTimeout());
  @@ -322,12 +341,13 @@
               Object result = null;
               Object backupFqn = null;
   
  -            while(i.hasNext())
  +         while (i.hasNext())
               {
                   Object o = i.next();
                   if (o instanceof Throwable)
                   {
  -                    if (log.isDebugEnabled()) log.debug("Found remote Throwable among responses - removing from responses list", (Exception)o);
  +               if (log.isDebugEnabled())
  +                  log.debug("Found remote Throwable among responses - removing from responses list", (Exception) o);
                   }
                   else if (o != null)
                   {
  @@ -352,7 +372,7 @@
               }
   
               if (log.isTraceEnabled()) log.trace("got responses " + resps);
  -            return new Object[]{result,backupFqn};
  +         return new Object[]{result, backupFqn};
           }
       }
   
  @@ -381,15 +401,16 @@
       private void createNodes(GlobalTransaction gtx, Fqn fqn, Map data) throws CacheException
       {
           int treeNodeSize;
  -        if ((treeNodeSize=fqn.size()) == 0) return;
  -        DataNode n=cache.getRoot();
  -        for(int i=0; i < treeNodeSize; i++)
  -        {
  -            Object child_name=fqn.get(i);
  -            DataNode child_node=(DataNode) n.getOrCreateChild(child_name, gtx, true);
  -            if(child_node == null)
  +      if ((treeNodeSize = fqn.size()) == 0) return;
  +      DataNode n = cache.getRoot();
  +      for (int i = 0; i < treeNodeSize; i++)
  +      {
  +         Object child_name = fqn.get(i);
  +         DataNode child_node = (DataNode) n.getOrCreateChild(child_name, gtx, true);
  +         if (child_node == null)
               {
  -                if(log.isTraceEnabled()) log.trace("failed to find or create child " + child_name + " of node " + n.getFqn());
  +            if (log.isTraceEnabled())
  +               log.trace("failed to find or create child " + child_name + " of node " + n.getFqn());
                   return;
               }
               if (i == treeNodeSize - 1)
  @@ -430,7 +451,7 @@
       private BackupData localBackupGet(Fqn fqn) throws CacheException
       {
           List gravitatedData = cache._gravitateData(fqn, true, false); // a "local" gravitation
  -        boolean found = ((Boolean)gravitatedData.get(0)).booleanValue();
  +      boolean found = ((Boolean) gravitatedData.get(0)).booleanValue();
           BackupData data = null;
   
           if (found)
  
  
  
  1.40.2.2  +130 -101  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.40.2.1
  retrieving revision 1.40.2.2
  diff -u -b -r1.40.2.1 -r1.40.2.2
  --- CacheLoaderInterceptor.java	26 Sep 2006 14:15:23 -0000	1.40.2.1
  +++ CacheLoaderInterceptor.java	2 Nov 2006 15:34:06 -0000	1.40.2.2
  @@ -1,12 +1,20 @@
   package org.jboss.cache.interceptors;
   
  -import org.jboss.cache.*;
  +import org.jboss.cache.CacheException;
  +import org.jboss.cache.DataNode;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.GlobalTransaction;
  +import org.jboss.cache.InvocationContext;
  +import org.jboss.cache.TransactionEntry;
  +import org.jboss.cache.TransactionTable;
  +import org.jboss.cache.TreeCache;
  +import org.jboss.cache.TreeNode;
   import org.jboss.cache.loader.AsyncCacheLoader;
   import org.jboss.cache.loader.CacheLoader;
   import org.jboss.cache.loader.ChainingCacheLoader;
  +import org.jboss.cache.marshall.JBCMethodCall;
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
  -import org.jboss.cache.marshall.JBCMethodCall;
   import org.jgroups.blocks.MethodCall;
   
   import java.lang.reflect.Method;
  @@ -19,8 +27,9 @@
   
   /**
    * 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.40.2.1 2006/09/26 14:15:23 gzamarreno Exp $
  + * @version $Id: CacheLoaderInterceptor.java,v 1.40.2.2 2006/11/02 15:34:06 msurtani Exp $
    */
   public class CacheLoaderInterceptor extends BaseCacheLoaderInterceptor implements CacheLoaderInterceptorMBean
   {
  @@ -39,7 +48,7 @@
      public void setCache(TreeCache cache)
      {
         super.setCache(cache);
  -      isCustomCacheLoader = isCustomCacheLoaderConfigured( loader );
  +      isCustomCacheLoader = isCustomCacheLoaderConfigured(loader);
         txTable = cache.getTransactionTable();
      }
   
  @@ -62,7 +71,7 @@
         {
            // test the underlying cache loader
            CacheLoader underlying = ((AsyncCacheLoader) cl).getCacheLoader();
  -         return isCustomCacheLoaderConfigured( underlying );
  +         return isCustomCacheLoaderConfigured(underlying);
         }
         else
         {
  @@ -75,15 +84,17 @@
      /**
       * Makes sure a node is loaded into memory before a call executes (no-op if node is already loaded). If attributes
       * of a node are to be accessed by the method, the attributes are also loaded.
  -    * @param m
  +    *
  +    * @param call
       * @return
       * @throws Throwable
       */
  -   public Object invoke(MethodCall call) throws Throwable {
  +   public Object invoke(MethodCall call) throws Throwable
  +   {
         JBCMethodCall m = (JBCMethodCall) call;
  -      Fqn          fqn=null; // if set, load the data
  -      Method       meth=m.getMethod();
  -      Object[]     args=m.getArgs();
  +      Fqn fqn = null; // if set, load the data
  +      Method meth = m.getMethod();
  +      Object[] args = m.getArgs();
         boolean acquireLock = false; // do we need to acquire a lock if we load this node from cloader?
         Map nodeData = null;
         boolean initNode = false; // keep uninitialized
  @@ -102,21 +113,21 @@
         {
            case MethodDeclarations.putDataEraseMethodLocal_id:
            case MethodDeclarations.putDataMethodLocal_id:
  -            fqn=(Fqn)args[1];
  +            fqn = (Fqn) args[1];
               initNode = true;
               break;
            case MethodDeclarations.putKeyValMethodLocal_id:
  -            fqn=(Fqn)args[1];
  +            fqn = (Fqn) args[1];
               if (useCacheStore)
                 initNode = true;
               else
                 acquireLock = true;
               break;
            case MethodDeclarations.addChildMethodLocal_id:
  -            fqn=(Fqn)args[1];
  +            fqn = (Fqn) args[1];
               break;
            case MethodDeclarations.getKeyValueMethodLocal_id:
  -            fqn=(Fqn)args[0];
  +            fqn = (Fqn) args[0];
               key = args[1];
               acquireLock = true;
               break;
  @@ -125,19 +136,23 @@
            case MethodDeclarations.getChildrenNamesMethodLocal_id:
            case MethodDeclarations.releaseAllLocksMethodLocal_id:
            case MethodDeclarations.printMethodLocal_id:
  -            fqn=(Fqn)args[0];
  +            fqn = (Fqn) args[0];
               acquireLock = true;
               break;
            case MethodDeclarations.rollbackMethod_id:
               // clean up nodesCreated map
               cleanupNodesCreated(entry);
               break;
  -         default :
  -            if (!useCacheStore) {
  -               if (m.getMethodId() == MethodDeclarations.removeKeyMethodLocal_id) {
  -                  fqn=(Fqn)args[1];
  -               } else if (m.getMethodId() == MethodDeclarations.removeDataMethodLocal_id) {
  -                  fqn=(Fqn)args[1];
  +         default:
  +            if (!useCacheStore)
  +            {
  +               if (m.getMethodId() == MethodDeclarations.removeKeyMethodLocal_id)
  +               {
  +                  fqn = (Fqn) args[1];
  +               }
  +               else if (m.getMethodId() == MethodDeclarations.removeDataMethodLocal_id)
  +               {
  +                  fqn = (Fqn) args[1];
                     initNode = true;
                  }
               }
  @@ -199,6 +214,7 @@
   
      /**
       * Load the children.
  +    *
       * @param n may be null if the node was not found.
       */
      private void loadChildren(Fqn fqn, DataNode n) throws Throwable
  @@ -214,7 +230,8 @@
         // For getChildrenNames null means no children
         if (children_names == null)
         {
  -         if (n != null) {
  +         if (n != null)
  +         {
               if (useCacheStore)
                  n.setChildren(null);
               n.setChildrenLoaded(true);
  @@ -227,9 +244,9 @@
            n = createNodes(fqn, null); // dont care about local transactions
   
         // Create one DataNode per child, mark as UNINITIALIZED
  -      for (Iterator i = children_names.iterator(); i.hasNext(); )
  +      for (Iterator i = children_names.iterator(); i.hasNext();)
         {
  -         String child_name = (String)i.next();
  +         String child_name = (String) i.next();
            Fqn child_fqn = new Fqn(fqn, child_name);
            // create child if it didn't exist
            n.createChild(child_name, child_fqn, n, TreeCache.UNINITIALIZED, null);
  @@ -244,51 +261,61 @@
               (n.containsKey(TreeCache.UNINITIALIZED) && (key == null || !n.containsKey(key)));
      }
   
  -   public long getCacheLoaderLoads() {
  +   public long getCacheLoaderLoads()
  +   {
         return m_cacheLoads;
      }
   
  -   public long getCacheLoaderMisses() {
  +   public long getCacheLoaderMisses()
  +   {
         return m_cacheMisses;
      }
   
  -   public void resetStatistics() {
  +   public void resetStatistics()
  +   {
         m_cacheLoads = 0;
         m_cacheMisses = 0;
      }
   
  -   public Map dumpStatistics() {
  -      Map retval=new HashMap();
  +   public Map dumpStatistics()
  +   {
  +      Map retval = new HashMap();
         retval.put("CacheLoaderLoads", new Long(m_cacheLoads));
         retval.put("CacheLoaderMisses", new Long(m_cacheMisses));
         return retval;
      }
   
  -   protected void lock(Fqn fqn, int lock_type, boolean recursive) throws Throwable {
  +   protected void lock(Fqn fqn, int lock_type, boolean recursive) throws Throwable
  +   {
   
         if (cache.isNodeLockingOptimistic()) return;
   
  -      MethodCall meth=MethodCallFactory.create(MethodDeclarations.lockMethodLocal,
  +      MethodCall meth = MethodCallFactory.create(MethodDeclarations.lockMethodLocal,
                                        new Object[]{fqn,
                                                     new Integer(lock_type),
                                                Boolean.valueOf(recursive)});
  -      super.invoke(meth);
  +      //super.invoke(meth);
  +      // let's force this to go thru the whole chain, not just from here on.
  +      ((Interceptor) cache.getInterceptors().get(0)).invoke(meth); // need a better way to do this
      }
   
       /**
        * Retrieves a node from memory; doesn't access the cache loader
  +    *
        * @param fqn
        */
  -   protected DataNode getNode(Fqn fqn) {
  -      int treeNodeSize=fqn.size();
  +   protected DataNode getNode(Fqn fqn)
  +   {
  +      int treeNodeSize = fqn.size();
   
         TreeNode n = cache.getRoot();
         TreeNode child_node;
         Object   child_name;
  -      for(int i=0; i < treeNodeSize && n != null; i++) {
  -         child_name=fqn.get(i);
  -         child_node=n.getChild(child_name);
  -         n=child_node;
  +      for (int i = 0; i < treeNodeSize && n != null; i++)
  +      {
  +         child_name = fqn.get(i);
  +         child_node = n.getChild(child_name);
  +         n = child_node;
         }
         return (DataNode) n;
      }
  @@ -307,9 +334,9 @@
         Iterator i = entry.getCacheLoaderModifications().iterator();
         while (i.hasNext())
         {
  -         JBCMethodCall m = (JBCMethodCall)i.next();
  +         JBCMethodCall m = (JBCMethodCall) i.next();
            if (m.getMethodId() == MethodDeclarations.removeNodeMethodLocal_id
  -               && fqn.isChildOrEquals((Fqn)m.getArgs()[1]))
  +                 && fqn.isChildOrEquals((Fqn) m.getArgs()[1]))
               return true;
         }
         return false;
  @@ -411,7 +438,8 @@
      }
   
   
  -   private Map loadData(Fqn fqn) throws Exception {
  +   private Map loadData(Fqn fqn) throws Exception
  +   {
         Map nodeData = loader.get(fqn);
         boolean nodeExists = (nodeData != null);
         if (log.isTraceEnabled()) log.trace("nodeExists " + nodeExists);
  @@ -437,7 +465,8 @@
         return nodeData;
      }
   
  -   private void warnCustom() {
  +   private void warnCustom()
  +   {
         log.info("CacheLoader.get(Fqn) returned a null; assuming the node does not exist.");
         log.info("The CacheLoader interface has changed since JBossCache 1.3.x");
         log.info("Please see http://jira.jboss.com/jira/browse/JBCACHE-118");
  
  
  



More information about the jboss-cvs-commits mailing list