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

Manik Surtani msurtani at jboss.com
Tue Dec 12 09:51:44 EST 2006


  User: msurtani
  Date: 06/12/12 09:51:44

  Modified:    src/org/jboss/cache/interceptors      
                        InvocationContextInterceptor.java
                        OptimisticValidatorInterceptor.java
                        OptimisticCreateIfNotExistsInterceptor.java
                        OptimisticNodeInterceptor.java
                        PessimisticLockInterceptor.java
                        OptimisticReplicationInterceptor.java
  Log:
  JBCACHE-894
  
  Revision  Changes    Path
  1.11      +12 -7     JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InvocationContextInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/InvocationContextInterceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- InvocationContextInterceptor.java	20 Nov 2006 03:53:54 -0000	1.10
  +++ InvocationContextInterceptor.java	12 Dec 2006 14:51:44 -0000	1.11
  @@ -8,7 +8,6 @@
   
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.InvocationContext;
  -import org.jboss.cache.TreeCacheProxyImpl;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -30,14 +29,19 @@
         Transaction suspendedTransaction = null;
         boolean resumeSuspended = false;
   
  +      if (log.isTraceEnabled())
  +         log.trace("Invoked on cache instance [" + cache.getLocalAddress() + "] and InvocationContext [" + ctx + "]");
  +
         try
         {
            Transaction tx = getTransaction();
            setTransactionalContext(tx, getGlobalTransaction(tx, call));
   
  -         if (optionOverride != null) {
  +         if (optionOverride != null)
  +         {
               
  -            if (optionOverride.isFailSilently()) {
  +            if (optionOverride.isFailSilently())
  +            {
                  log.debug("FAIL_SILENTLY Option is present - suspending any ongoing transaction.");
                  if (ctx.getTransaction() != null)
                  {
  @@ -54,6 +58,7 @@
               
               if (optionOverride.isBypassInterceptorChain())
               {
  +               log.trace("Interceptor chain bypass option set for call; skipping interceptyor chain and proceeding to last interceptor.");
                  return getLast().invoke(call);
               }
            }
  
  
  
  1.46      +21 -39    JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticValidatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -b -r1.45 -r1.46
  --- OptimisticValidatorInterceptor.java	6 Dec 2006 16:28:37 -0000	1.45
  +++ OptimisticValidatorInterceptor.java	12 Dec 2006 14:51:44 -0000	1.46
  @@ -15,7 +15,6 @@
   import org.jboss.cache.OptimisticTreeNode;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  -import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.optimistic.DataVersioningException;
   import org.jboss.cache.optimistic.DefaultDataVersion;
   import org.jboss.cache.optimistic.TransactionWorkspace;
  @@ -23,7 +22,6 @@
   
   import javax.transaction.Transaction;
   import java.util.Collection;
  -import java.util.Iterator;
   import java.util.Map;
   
   /**
  @@ -96,7 +94,7 @@
         }
   
         // should be an ordered list - get the set of nodes
  -      Collection nodes = workspace.getNodes().values();
  +      Collection<WorkspaceNode> nodes = workspace.getNodes().values();
   
         //we have all locks here so lets try and validate
         if (log.isDebugEnabled()) log.debug("validating nodes. Num nodes: " + nodes.size());
  @@ -104,53 +102,37 @@
         log.debug("validated nodes");
      }
   
  -   private void simpleValidate(Collection nodes)
  -           throws DataVersioningException
  +   private void simpleValidate(Collection<WorkspaceNode> nodes) throws DataVersioningException
      {
  -      WorkspaceNode workspaceNode;
  -
         boolean trace = log.isTraceEnabled();
  -      for (Object node : nodes)
  +      for (WorkspaceNode workspaceNode : nodes)
         {
  -         workspaceNode = (WorkspaceNode) node;
            Fqn fqn = workspaceNode.getFqn();
  -         if (trace) log.trace("validating version for node " + fqn);
  +         if (trace) log.trace("Validating version for node " + fqn);
   
            OptimisticTreeNode realNode;
            realNode = (OptimisticTreeNode) cache.peek(fqn);
   
  -         if (workspaceNode.isCreated())
  -         {
  -            if (realNode != null)
  -            {
  -               throw new DataVersioningException("Tx attempted to create " + fqn + " anew.  It has already been created since this tx started by another (possibly remote) tx.");
  -            }
  -         }
  -         else
  -         {
  -            if (realNode == null)
  +         // if this is a newly created node then we expect the underlying node to be null.
  +         // if not, we have a problem...
  +         if (realNode == null && !workspaceNode.isCreated())
               {
                  throw new DataVersioningException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
               }
   
  -            if (workspaceNode == null)
  +         if (realNode != null && workspaceNode.isCreated())
               {
  -               throw new DataVersioningException("Workspace node for " + fqn + " is null, and this wasn't newly created in this tx!");
  +            throw new DataVersioningException("Tx attempted to create " + fqn + " anew.  It has already been created since this tx started by another (possibly remote) tx.");
               }
   
  -            if (workspaceNode.getVersion() == null)
  +         if (!workspaceNode.isCreated() && (workspaceNode.isDeleted() || workspaceNode.isDirty()))
               {
  -               throw new DataVersioningException("No version for workspace node");
  -            }
  -
  -            DataVersion rnv = realNode.getVersion();
  -            DataVersion wnv = workspaceNode.getVersion();
               // test that the 2 DataVersion types match up
  -            if (!rnv.getClass().equals(wnv.getClass()) && checkNotInitialRootVersion(realNode))
  +            if (!realNode.getVersion().getClass().equals(workspaceNode.getVersion().getClass()) && checkNotInitialRootVersion(realNode))
               {
  -               throw new DataVersioningException("Attempting to apply data version of type " + workspaceNode.getVersion().getClass() + " to a node that already contains version of type " + realNode.getVersion().getClass());
  +               throw new DataVersioningException("Attempting to apply data version of type " + workspaceNode.getVersion().getClass() + " to a node [fqn = " + realNode.getFqn() + "] that already contains version of type " + realNode.getVersion().getClass());
               }
  -            if ((workspaceNode.isDeleted() || workspaceNode.isDirty()) && realNode.getVersion().newerThan(workspaceNode.getVersion()))
  +            if (realNode.getVersion().newerThan(workspaceNode.getVersion()))
               {
                  // we have an out of date node here
                  throw new DataVersioningException("DataNode [" + fqn + "] version " + ((OptimisticTreeNode) workspaceNode.getNode()).getVersion() + " is newer than workspace node " + workspaceNode.getVersion());
  @@ -180,12 +162,11 @@
   
         log.debug("commiting validated changes ");
         // should be an ordered list
  -      Collection nodes = workspace.getNodes().values();
  +      Collection<WorkspaceNode> nodes = workspace.getNodes().values();
   
         boolean trace = log.isTraceEnabled();
  -      for (Iterator it = nodes.iterator(); it.hasNext();)
  +      for (WorkspaceNode wrappedNode : nodes)
         {
  -         WorkspaceNode wrappedNode = (WorkspaceNode) it.next();
            // short circuit if this node is deleted?
            if (wrappedNode.isDeleted())
            {
  @@ -239,8 +220,9 @@
                  Map raw = current.getNodeSPI().getRawData();
                  raw.clear();
                  raw.putAll(mergedData);
  -               if (workspace.isVersioningImplicit())
  +               if (wrappedNode.isVersioningImplicit())
                  {
  +                  if (trace) log.trace("Versioning is implicit; incrementing.");
                     current.setVersion(((DefaultDataVersion) wrappedNode.getVersion()).increment());
                  }
                  else
  
  
  
  1.32      +17 -9     JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticCreateIfNotExistsInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticCreateIfNotExistsInterceptor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- OptimisticCreateIfNotExistsInterceptor.java	20 Nov 2006 03:53:54 -0000	1.31
  +++ OptimisticCreateIfNotExistsInterceptor.java	12 Dec 2006 14:51:44 -0000	1.32
  @@ -7,16 +7,12 @@
   package org.jboss.cache.interceptors;
   
   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.Node;
   import org.jboss.cache.OptimisticTransactionEntry;
  -import org.jboss.cache.OptimisticTreeNode;
   import org.jboss.cache.TransactionEntry;
  -import org.jboss.cache.TreeCacheProxyImpl;
  -import org.jboss.cache.TreeNode;
   import org.jboss.cache.factories.NodeFactory;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -193,6 +189,9 @@
                  Node tempNode = workspaceNode.createChild(childName, copy, workspaceNode.getNode(), cache, versionToPassIn);
   
                  childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempNode, workspace);
  +               childWorkspaceNode.setVersioningImplicit(versionToPassIn == null || !isTargetFqn);
  +               if (log.isTraceEnabled())
  +                  log.trace("setting versioning of " + childWorkspaceNode.getFqn() + " to be " + (childWorkspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
   
                  // now add the wrapped child node into the transaction space
                  workspace.addNode(childWorkspaceNode);
  @@ -210,11 +209,20 @@
                  if (childWorkspaceNode == null || childWorkspaceNode.isDeleted())
                  {
                     if (debug)
  +                     log.debug("Child node " + tempchildNode.getFqn() + " doesn't exist in workspace or has been deleted.  Adding to workspace in gtx " + gtx);
  +                  childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempchildNode, workspace);
  +                  if (isTargetFqn && !workspace.isVersioningImplicit())
                     {
  -                     log.debug("Child node doesn't exist in workspace or has been deleted");
  +                     childWorkspaceNode.setVersion(version);
  +                     childWorkspaceNode.setVersioningImplicit(false);
                     }
  -                  childWorkspaceNode = NodeFactory.getInstance().createWorkspaceNode(tempchildNode, workspace);
  -                  if (!workspace.isVersioningImplicit()) childWorkspaceNode.setVersion(version);
  +                  else
  +                  {
  +                     childWorkspaceNode.setVersioningImplicit(true);
  +                  }
  +                  if (log.isTraceEnabled())
  +                     log.trace("setting versioning of " + childWorkspaceNode.getFqn() + " to be " + (childWorkspaceNode.isVersioningImplicit() ? "implicit" : "explicit"));
  +
                  }
                  else
                  {
  
  
  
  1.35      +21 -18    JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticNodeInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -b -r1.34 -r1.35
  --- OptimisticNodeInterceptor.java	20 Nov 2006 05:09:15 -0000	1.34
  +++ OptimisticNodeInterceptor.java	12 Dec 2006 14:51:44 -0000	1.35
  @@ -7,12 +7,10 @@
   package org.jboss.cache.interceptors;
   
   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.Node;
  -import org.jboss.cache.TreeCacheProxyImpl;
   import org.jboss.cache.TreeNode;
   import org.jboss.cache.config.Option;
   import org.jboss.cache.factories.NodeFactory;
  @@ -65,7 +63,6 @@
            WorkspaceNode parent = getOrCreateWorkspaceNode(parentFqn, workspace);
            WorkspaceNode node = getOrCreateWorkspaceNode(nodeFqn, workspace);
   
  -
            if (log.isTraceEnabled()) log.trace("Parent: " + parent);
            if (log.isTraceEnabled()) log.trace("Node: " + node);
   
  @@ -86,26 +83,32 @@
            // this in the transaction interceptor
            WorkspaceNode workspaceNode = getOrCreateWorkspaceNode(getFqn(args), workspace);
   
  +
  +         if (workspaceNode != null)
  +         {
            // use explicit versioning
            if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
            {
               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();
  -            // "fail-more-silently" patch thanks to Owen Taylor - JBCACHE-767
   
  -            // also, if this is a "remove", do we care if the node didn't exist?
  -
  -            if (workspaceNode != null)
  -            {
                  workspaceNode.setVersion(version);
  +               if (log.isTraceEnabled())
  +                  log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");
  +               workspaceNode.setVersioningImplicit(false);
               }
               else
               {
  -               if ((ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isFailSilently()) && MethodDeclarations.isPutMethod(m.getMethodId()))
  -               {
  -                  throw new CacheException("Unable to set node version for " + getFqn(args) + ", node is null.");
  +               if (log.isTraceEnabled())
  +                  log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to implicit");
  +               workspaceNode.setVersioningImplicit(true);
                  }
               }
  +         else
  +         {
  +            // "fail-more-silently" patch thanks to Owen Taylor - JBCACHE-767
  +            if ((ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isFailSilently()) && MethodDeclarations.isPutMethod(m.getMethodId()))
  +               throw new CacheException("Unable to set node version for " + getFqn(args) + ", node is null.");
            }
   
            switch (m.getMethodId())
  @@ -431,7 +434,7 @@
            {
               return null;// seems to happen quite a bit
            }
  -         workspaceNode = NodeFactory.getInstance().createWorkspaceNode((TreeNode)node, workspace);
  +         workspaceNode = NodeFactory.getInstance().createWorkspaceNode((TreeNode) node, workspace);
            workspace.addNode(workspaceNode);
         }
         // the node has been deleted dude!
  
  
  
  1.36      +2 -6      JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PessimisticLockInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -b -r1.35 -r1.36
  --- PessimisticLockInterceptor.java	20 Nov 2006 12:04:43 -0000	1.35
  +++ PessimisticLockInterceptor.java	12 Dec 2006 14:51:44 -0000	1.36
  @@ -11,14 +11,11 @@
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.InvocationContext;
   import org.jboss.cache.Node;
  -import org.jboss.cache.NodeImpl;
   import org.jboss.cache.TransactionEntry;
   import org.jboss.cache.TransactionTable;
  -import org.jboss.cache.TreeCacheProxyImpl;
  -import org.jboss.cache.lock.IdentityLock;
   import org.jboss.cache.lock.IsolationLevel;
  -import org.jboss.cache.lock.NodeLock;
   import org.jboss.cache.lock.LockingException;
  +import org.jboss.cache.lock.NodeLock;
   import org.jboss.cache.lock.TimeoutException;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -37,7 +34,7 @@
    * current method and unlock when the method returns.
    *
    * @author Bela Ban
  - * @version $Id: PessimisticLockInterceptor.java,v 1.35 2006/11/20 12:04:43 genman Exp $
  + * @version $Id: PessimisticLockInterceptor.java,v 1.36 2006/12/12 14:51:44 msurtani Exp $
    */
   public class PessimisticLockInterceptor extends Interceptor
   {
  @@ -366,7 +363,6 @@
         }
      }
   
  -
      /**
       * Remove all locks held by <tt>tx</tt>, remove the transaction from the transaction table
       *
  
  
  
  1.32      +10 -3     JBossCache/src/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticReplicationInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- OptimisticReplicationInterceptor.java	8 Dec 2006 18:49:17 -0000	1.31
  +++ OptimisticReplicationInterceptor.java	12 Dec 2006 14:51:44 -0000	1.32
  @@ -83,7 +83,7 @@
                     //if we have an exception then the remote methods failed
                     if (retval instanceof Throwable)
                     {
  -                     throw(Throwable) retval;
  +                     throw (Throwable) retval;
                     }
                  }
                  break;
  @@ -297,14 +297,21 @@
      private DataVersion getVersionToBroadcast(TransactionWorkspace w, Fqn f)
      {
         WorkspaceNode n = w.getNode(f);
  -      if (n == null) return null;
  -      if (w.isVersioningImplicit())
  +      if (n == null)
  +      {
  +         if (log.isTraceEnabled()) log.trace("Fqn " + f + " not found in workspace; not using a data version.");
  +         return null;
  +      }
  +      if (n.isVersioningImplicit())
         {
            DefaultDataVersion v = (DefaultDataVersion) n.getVersion();
  +         if (log.isTraceEnabled())
  +            log.trace("Fqn " + f + " has implicit versioning.  Broadcasting an incremented version.");
            return v.increment();
         }
         else
         {
  +         if (log.isTraceEnabled()) log.trace("Fqn " + f + " has explicit versioning.  Broadcasting the version as-is.");
            return n.getVersion();
         }
      }
  
  
  



More information about the jboss-cvs-commits mailing list