Package org.jboss.cache.lock

Examples of org.jboss.cache.lock.NodeLock


      Map nodeMap = w.getNodes();
      for (Iterator i = nodeMap.keySet().iterator(); i.hasNext();)
      {
         WorkspaceNode wn = (WorkspaceNode) nodeMap.get(i.next());
         NodeSPI n = wn.getNode();
         NodeLock lock = n.getLock();
         if (lock.isLocked())
         {
            actual.put(n.getFqn(), lock.isReadLocked() ? READ : WRITE);
         }
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here


   }

   @Override
   protected void assertLocked(Fqn fqn, CacheSPI cache, boolean writeLocked)
   {
      NodeLock lock = cache.peek(fqn, true, true).getLock();
      assertTrue("node " + fqn + " is not locked", lock.isLocked());
      if (writeLocked)
      {
         assertTrue("node " + fqn + " is not write-locked" + (lock.isReadLocked() ? " but is read-locked instead!" : "!"), lock.isWriteLocked());
      }
      else
      {
         assertTrue("node " + fqn + " is not read-locked" + (lock.isWriteLocked() ? " but is write-locked instead!" : "!"), lock.isReadLocked());
      }
   }
View Full Code Here

   }

   @Override
   protected void assertLocked(Fqn fqn, CacheSPI cache, boolean writeLocked)
   {
      NodeLock lock = cache.peek(fqn, true, true).getLock();
      assertTrue("node " + fqn + " is not locked", lock.isLocked());
      if (writeLocked)
      {
         assertTrue("node " + fqn + " is not write-locked" + (lock.isReadLocked() ? " but is read-locked instead!" : "!"), lock.isWriteLocked());
      }
      else
      {
         assertTrue("node " + fqn + " is not read-locked" + (lock.isWriteLocked() ? " but is write-locked instead!" : "!"), lock.isReadLocked());
      }
   }
View Full Code Here

      Map nodeMap = w.getNodes();
      for (Iterator i = nodeMap.keySet().iterator(); i.hasNext();)
      {
         WorkspaceNode wn = (WorkspaceNode) nodeMap.get(i.next());
         NodeSPI n = wn.getNode();
         NodeLock lock = n.getLock();
         if (lock.isLocked())
         {
            actual.put(n.getFqn(), lock.isReadLocked() ? READ : WRITE);
         }
      }
      return invokeNextInterceptor(ctx, command);
   }
View Full Code Here


   private void removeLocksForDeadMembers(NodeSPI node, List deadMembers)
   {
      Set<GlobalTransaction> deadOwners = new HashSet<GlobalTransaction>();
      NodeLock lock = node.getLock();
      Object owner = lock.getWriterOwner();

      if (isLockOwnerDead(owner, deadMembers))
      {
         deadOwners.add((GlobalTransaction) owner);
      }

      for (Object readOwner : lock.getReaderOwners())
      {
         if (isLockOwnerDead(readOwner, deadMembers))
         {
            deadOwners.add((GlobalTransaction) readOwner);
         }
View Full Code Here

   }

   private void assertNotLocked(Fqn fqn)
   {
      NodeSPI<String, String> n = cache.peek(fqn, true);
      NodeLock lock = n.getLock();
      assertFalse("node " + fqn + " is locked!", lock.isLocked());
   }
View Full Code Here

   private void assertLocked(Object owner, Fqn fqn, boolean write_locked)
   {
      NodeSPI<String, String> n = cache.peek(fqn, true);
      if (owner == null)
         owner = Thread.currentThread();
      NodeLock lock = n.getLock();
      assertTrue("node " + fqn + " is not locked", lock.isLocked());
      if (write_locked)
      {
         assertTrue("node " + fqn + " is not write-locked" + (lock.isReadLocked() ? " but is read-locked instead!" : "!"), lock.isWriteLocked());
      }
      else
      {
         assertTrue("node " + fqn + " is not read-locked" + (lock.isWriteLocked() ? " but is write-locked instead!" : "!"), lock.isReadLocked());
      }
      assertTrue("owner " + owner + "is not owner for lock " + lock, lock.isOwner(owner));
   }
View Full Code Here

                  try
                  {
                     // make sure we release locks in *reverse* order!
                     for (int i = locks.size() - 1; i > -1; i--)
                     {
                        NodeLock nl = locks.get(i);
                        if (trace) log.trace("releasing lock for " + nl.getFqn() + ": " + nl);
                        nl.release(currentThread);
                     }
                  }
                  finally
                  {
                     ctx.clearInvocationLocksAcquired();
View Full Code Here

      return lockType == NodeLock.LockType.WRITE && isTargetNode;//write lock explicitly requested and this is the target to be written to.
   }

   private void acquireNodeLock(InvocationContext ctx, NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
   {
      NodeLock lock = node.getLock();
      boolean acquired = lock.acquire(owner, lockTimeout, lockType);
      if (acquired)
      {
         // Record the lock for release on method return or tx commit/rollback
         if (gtx != null)
         {
View Full Code Here

      NodeSPI parent = null;
      NodeSPI subtreeRoot = null;
      boolean parentLocked = false;
      boolean subtreeLocked = false;
      NodeLock parentLock = null;
      NodeLock subtreeLock = null;

      try
      {
         // Record that this fqn is in status change, so can't provide state
         activationChangeNodes.add(fqn);

         if (!isInactive(fqn))
         {
            deactivate(fqn);
         }

         // Create a list with the Fqn in the main cache and any buddy backup trees
         BuddyManager buddyManager = cache.getBuddyManager();
         ArrayList<Fqn> list = new ArrayList<Fqn>();
         list.add(fqn);

         if (buddyManager != null)
         {
            Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false, false).getChildrenNames();
            if (buddies != null)
            {
               for (Iterator it = buddies.iterator(); it.hasNext();)
               {
                  Fqn base = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, it.next());
                  list.add(new Fqn(base, fqn));
               }
            }
         }

         long stateFetchTimeout = cache.getConfiguration().getLockAcquisitionTimeout() + 5000;
         // Remove the subtree from the main cache  and any buddy backup trees
         for (Iterator<Fqn> it = list.iterator(); it.hasNext();)
         {
            Fqn subtree = it.next();
            subtreeRoot = cache.peek(subtree, false, false);
            if (subtreeRoot != null)
            {
               // Acquire locks

               Object owner = getOwnerForLock();
               subtreeLock = subtreeRoot.getLock();
               subtreeLock.acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
               subtreeLocked = true;

               // Lock the parent, as we're about to write to it
               parent = subtreeRoot.getParent();
               if (parent != null)
               {
                  parentLock = parent.getLock();
                  parentLock.acquire(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
                  parentLocked = true;
               }

               // Remove the subtree
               cache.evict(subtree, true);
               //cache._evictSubtree(subtree);

               // Release locks
               if (parent != null)
               {
                  log.debug("forcing release of locks in parent");
                  parentLock.releaseAll();
               }

               parentLocked = false;

               log.debug("forcing release of all locks in subtree");
               subtreeLock.releaseAll();
               subtreeLocked = false;
            }
         }
      }
      catch (InterruptedException ie)
      {
         throw new CacheException("Interrupted while acquiring lock", ie);
      }
      finally
      {
         // If we didn't succeed, undo the marshalling change
         // NO. Since we inactivated, we may have missed changes
         //if (!success && !inactive)
         //   marshaller_.activate(subtreeFqn);

         // If necessary, release locks
         if (parentLocked)
         {
            log.debug("forcing release of locks in parent");
            try
            {
               parentLock.releaseAll();
            }
            catch (Throwable t)
            {
               log.error("failed releasing locks", t);
            }
         }
         if (subtreeLocked)
         {
            log.debug("forcing release of all locks in subtree");
            try
            {
               subtreeLock.releaseAll();
            }
            catch (Throwable t)
            {
               log.error("failed releasing locks", t);
            }
View Full Code Here

TOP

Related Classes of org.jboss.cache.lock.NodeLock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.