Package org.jboss.cache.lock

Examples of org.jboss.cache.lock.IdentityLock


    * Optimistically locked nodes (VersionedNodes) will always use repeatable read.
    */
   @Override
   protected synchronized void initLock()
   {
      if (lock == null) lock = new IdentityLock(lockStrategyFactory, delegate);
   }
View Full Code Here


   protected synchronized void initLock()
   {
      if (lock == null)
      {
         lock = new IdentityLock(lockStrategyFactory, delegate);
      }
   }
View Full Code Here

   protected synchronized void initLock()
   {
      if (lock == null)
      {
         lock = new IdentityLock(lockStrategyFactory, delegate);
      }
   }
View Full Code Here

   protected synchronized void initLock()
   {
      if (lock == null)
      {
         lock = new IdentityLock(lockStrategyFactory, delegate);
      }
   }
View Full Code Here

    * Optimistically locked nodes (VersionedNodes) will always use repeatable read.
    */
   @Override
   protected synchronized void initLock()
   {
      if (lock == null) lock = new IdentityLock(lockStrategyFactory, delegate);
   }
View Full Code Here

    * @param lockChildren <code>true</code> if this method should be recursively
    *                     applied to <code>node</code>'s children.
    */
   protected void forceAcquireLock(DataNode node, Object newOwner, boolean lockChildren)
   {
      IdentityLock lock = node.getLock();
      boolean acquired = lock.isOwner(newOwner);

      if (!acquired && log.isDebugEnabled())
         log.debug("Force acquiring lock on node " + node.getFqn());

      while (!acquired)
      {
         Object curOwner = null;
         boolean attempted = false;

         // Keep breaking write locks until we acquire a read lock
         // or there are no more write locks
         while (!acquired && ((curOwner = lock.getWriterOwner()) != null))
         {
            acquired = acquireLockFromOwner(node, lock, curOwner, newOwner);
            attempted = true;
         }

         // If no more write locks, but we haven't acquired, see if we
         // need to break read locks as well
         if (!acquired && isolationLevel == IsolationLevel.SERIALIZABLE)
         {
            Iterator it = lock.getReaderOwners().iterator();
            if (it.hasNext())
            {
               curOwner = it.next();
               acquired = acquireLockFromOwner(node, lock, it.next(), newOwner);
               attempted = true;
View Full Code Here

   private void removeLocksForDeadMembers(DataNode node,
                                          Vector deadMembers)
   {
      Set deadOwners = new HashSet();
      IdentityLock lock = node.getLock();
      Object owner = lock.getWriterOwner();

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

      Iterator iter = lock.getReaderOwners().iterator();
      while (iter.hasNext())
      {
         owner = iter.next();
         if (isLockOwnerDead(owner, deadMembers))
         {
View Full Code Here

         }
      }
   }

   private void releaseLocks(List locks, Thread currentThread) {
      IdentityLock lock;
      for (ListIterator it=locks.listIterator(locks.size()); it.hasPrevious();) {
            lock=(IdentityLock)it.previous();
         if (trace)
               log.trace("releasing lock for " + lock.getFqn() + ": " + lock);
         lock.release(currentThread);
      }
   }
View Full Code Here

      GlobalTransaction gtx = cache.getCurrentTransaction();
      cache.put("/a/b/c", null);
      cache.put("/a/b/c", null);

      DataNode n=cache.get("/a");
      IdentityLock lock=n.getLock();
      int num=lock.getReaderOwners().size();
      assertEquals(0, num);
      // make sure this is write locked.
      assertLocked(gtx, "/a", true);

      n=cache.get("/a/b");
      lock=n.getLock();
      num=lock.getReaderOwners().size();
      assertEquals(0, num);
      // make sure this is write locked.
      assertLocked(gtx, "/a/b", true);

      n=cache.get("/a/b/c");
      lock=n.getLock();
      num=lock.getReaderOwners().size();
      assertEquals(0, num);
      // make sure this is write locked.
      assertLocked(gtx, "/a/b/c", true);

      tx.rollback();
View Full Code Here

      assertEquals(0, cache.getNumberOfLocksHeld());
   }

   private void assertLocked(Object owner, String fqn, boolean write_locked) throws Exception{
      DataNode n=cache.peek(Fqn.fromString(fqn));
      IdentityLock lock=n.getLock();
      if(owner == null)
         owner=Thread.currentThread();
      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", lock.isOwner(owner));
   }
View Full Code Here

TOP

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

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.