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

Manik Surtani manik at jboss.org
Mon Jul 30 07:19:15 EDT 2007


  User: msurtani
  Date: 07/07/30 07:19:15

  Modified:    src/org/jboss/cache/interceptors 
                        PessimisticLockInterceptor.java
  Log:
  JBCACHE-1157
  
  Revision  Changes    Path
  1.55      +21 -28    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.54
  retrieving revision 1.55
  diff -u -b -r1.54 -r1.55
  --- PessimisticLockInterceptor.java	12 Jun 2007 07:39:50 -0000	1.54
  +++ PessimisticLockInterceptor.java	30 Jul 2007 11:19:15 -0000	1.55
  @@ -35,7 +35,7 @@
    * current method and unlock when the method returns.
    *
    * @author Bela Ban
  - * @version $Id: PessimisticLockInterceptor.java,v 1.54 2007/06/12 07:39:50 msurtani Exp $
  + * @version $Id: PessimisticLockInterceptor.java,v 1.55 2007/07/30 11:19:15 msurtani Exp $
    */
   public class PessimisticLockInterceptor extends Interceptor
   {
  @@ -97,6 +97,7 @@
         boolean zeroLockTimeout = false;// only used if the call is an evict() call.  See JBCACHE-794
         boolean isDeleteOperation = false;// needed for JBCACHE-871
         boolean isEvictOperation = false;
  +      boolean isRemoveDataOperation = false;
   
         // 1. Determine the type of lock (read, write, or none) depending on the method. If no lock is required, invoke
         //    the method, then return immediately
  @@ -110,13 +111,6 @@
               lockNecessary = true;
               isDeleteOperation = true;
               break;
  -         case MethodDeclarations.putDataMethodLocal_id:
  -         case MethodDeclarations.putDataEraseMethodLocal_id:
  -         case MethodDeclarations.putKeyValMethodLocal_id:
  -            createIfNotExists = true;
  -            fqn = (Fqn) args[1];
  -            lock_type = NodeLock.LockType.WRITE;
  -            break;
            case MethodDeclarations.putForExternalReadMethodLocal_id:
               createIfNotExists = true;
               fqn = (Fqn) args[1];
  @@ -129,8 +123,16 @@
               lock_type = NodeLock.LockType.WRITE;
               recursive = true;// remove node and *all* child nodes
               break;
  +         case MethodDeclarations.putDataMethodLocal_id:
  +         case MethodDeclarations.putDataEraseMethodLocal_id:
  +         case MethodDeclarations.putKeyValMethodLocal_id:
  +            createIfNotExists = true;
  +            fqn = (Fqn) args[1];
  +            lock_type = NodeLock.LockType.WRITE;
  +            break;
            case MethodDeclarations.removeKeyMethodLocal_id:
            case MethodDeclarations.removeDataMethodLocal_id:
  +            isRemoveDataOperation = true;
            case MethodDeclarations.addChildMethodLocal_id:
               fqn = (Fqn) args[1];
               lock_type = NodeLock.LockType.WRITE;
  @@ -182,7 +184,7 @@
            {
               do
               {
  -               lock(ctx, fqn, lock_type, recursive, createIfNotExists, zeroLockTimeout ? 0 : lock_acquisition_timeout, isDeleteOperation, isEvictOperation);
  +               lock(ctx, fqn, lock_type, recursive, createIfNotExists, zeroLockTimeout ? 0 : lock_acquisition_timeout, isDeleteOperation, isEvictOperation, isRemoveDataOperation);
               }
               while (createIfNotExists && cache.peek(fqn, false) == null);// keep trying until we have the lock (fixes concurrent remove())
            }
  @@ -229,11 +231,11 @@
   
         // this call will ensure the node gets a WL and it's current parent gets RL.
         if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved [" + node + "]");
  -      lock(ctx, node, NodeLock.LockType.WRITE, true, false, lock_acquisition_timeout, true, false);
  +      lock(ctx, node, NodeLock.LockType.WRITE, true, false, lock_acquisition_timeout, true, false, false);
   
         //now for an RL for the new parent.
         if (log.isTraceEnabled()) log.trace("Attempting to get RL on new parent [" + parent + "]");
  -      lock(ctx, parent, NodeLock.LockType.READ, true, false, lock_acquisition_timeout, false, false);
  +      lock(ctx, parent, NodeLock.LockType.READ, true, false, lock_acquisition_timeout, false, false, false);
      }
   
   
  @@ -244,7 +246,7 @@
       * @param lock_type DataNode.LOCK_TYPE_READ, DataNode.LOCK_TYPE_WRITE or DataNode.LOCK_TYPE_NONE
       * @param recursive Lock children recursively
       */
  -   private void lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lock_type, boolean recursive, boolean createIfNotExists, long timeout, boolean isDeleteOperation, boolean isEvictionOperation)
  +   private void lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lock_type, boolean recursive, boolean createIfNotExists, long timeout, boolean isDeleteOperation, boolean isEvictionOperation, boolean isRemoveDataOperation)
            throws TimeoutException, LockingException, InterruptedException
      {
         NodeSPI n;
  @@ -283,11 +285,7 @@
               child_name = fqn.get(i);
               child_node = n.getChildDirect(child_name);
            }
  -         /*
  -         cache.getInvocationContext().getOptionOverrides().setBypassInterceptorChain(true);
  -         Fqn childFqn = new Fqn(child_name);
  -         child_node = n.getChild(new Fqn(child_name));
  -         */
  +
            if (child_node == null && createIfNotExists)
            {
               child_node = n.addChildDirect(new Fqn(child_name));
  @@ -305,23 +303,18 @@
            NodeLock.LockType lockTypeRequired;
            if (lock_type == NodeLock.LockType.NONE)
            {
  -            // acquired=false;
               n = child_node;
               continue;
            }
            else
            {
  -            if (writeLockNeeded(ctx, lock_type, i, treeNodeSize, isEvictionOperation, isDeleteOperation, createIfNotExists, fqn, child_node.getFqn()))
  +            if (writeLockNeeded(ctx, lock_type, i, treeNodeSize, isEvictionOperation, isDeleteOperation, createIfNotExists, isRemoveDataOperation, fqn, child_node.getFqn()))
               {
  -               //acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_WRITE);
  -               //acquired = lockManager.acquire(child_node, owner, NodeLock.LockType.WRITE, timeout);
                  lockTypeRequired = NodeLock.LockType.WRITE;
   
               }
               else
               {
  -               //acquired=child_node.acquire(owner, lock_timeout, DataNode.LOCK_TYPE_READ);
  -               //acquired = lockManager.acquire(child_node, owner, NodeLock.LockType.READ, timeout);
                  lockTypeRequired = NodeLock.LockType.READ;
               }
            }
  @@ -332,11 +325,11 @@
               reverseRemove(child_node);
            }
   
  +         // actually acquire the lock we need.
            acquireNodeLock(child_node, owner, gtx, lockTypeRequired, timeout);
   
            if (recursive && isTargetNode(i, treeNodeSize))
            {
  -            //Set acquired_locks=child_node.acquireAll(owner, lock_timeout, lock_type);
               Set<NodeLock> acquired_locks = lockManager.acquireAll(child_node, owner, lock_type, timeout);
               if (acquired_locks.size() > 0)
               {
  @@ -368,7 +361,7 @@
         n.markAsDeleted(false);
      }
   
  -   private boolean writeLockNeeded(InvocationContext ctx, NodeLock.LockType lock_type, int currentNodeIndex, int treeNodeSize, boolean isEvictOperation, boolean isRemoveOperation, boolean createIfNotExists, Fqn targetFqn, Fqn currentFqn)
  +   private boolean writeLockNeeded(InvocationContext ctx, NodeLock.LockType lock_type, int currentNodeIndex, int treeNodeSize, boolean isEvictOperation, boolean isRemoveOperation, boolean isPutOperation, boolean isRemoveDataOperation, Fqn targetFqn, Fqn currentFqn)
      {
         // write lock forced!!
         boolean isTargetNode = isTargetNode(currentNodeIndex, treeNodeSize);
  @@ -384,10 +377,10 @@
   
            if (!isTargetNode && cache.peek(new Fqn(currentFqn, targetFqn.get(currentNodeIndex + 1)), false) == null)
            {
  -            return createIfNotExists;// we're at a node in the tree, not yet at the target node, and we need to create the next node.  So we need a WL here.
  +            return isPutOperation;// we're at a node in the tree, not yet at the target node, and we need to create the next node.  So we need a WL here.
            }
         }
  -      return lock_type == NodeLock.LockType.WRITE && isTargetNode && (createIfNotExists || isRemoveOperation || isEvictOperation);//normal operation, write lock explicitly requested and this is the target to be written to.
  +      return lock_type == NodeLock.LockType.WRITE && isTargetNode && (isPutOperation || isRemoveOperation || isEvictOperation || isRemoveDataOperation);//normal operation, write lock explicitly requested and this is the target to be written to.
      }
   
      private boolean isTargetNode(int nodePosition, int treeNodeSize)
  
  
  



More information about the jboss-cvs-commits mailing list