Package org.infinispan.util.concurrent.locks

Examples of org.infinispan.util.concurrent.locks.LockManager


      assertTrue("\"age\" must be 38", age == 38);
   }

   public void testSyncReplMap() throws Exception {
      Integer age;
      LockManager lm1 = TestingUtil.extractComponent(cache1, LockManager.class);

      assert lm1.getOwner("age") == null : "lock info is " + lm1.printLockInfo();
      LocalListener lis = new LocalListener();
      cache1.addListener(lis);
      lis.put("age", 38);
      assert lm1.getOwner("age") == null : "lock info is " + lm1.printLockInfo();

      cache1.put("name", "Ben");
      // value on cache2 must be 38
      age = (Integer) cache2.get("age");
      assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
      assertTrue("\"age\" must be 38", age == 38);
      assert lm1.getOwner("age") == null : "lock info is " + lm1.printLockInfo();
   }
View Full Code Here


   /**
    * Verifies the cache doesn't contain any lock
    * @param cache
    */
   public static void assertNoLocks(Cache<?,?> cache) {
      LockManager lm = TestingUtil.extractLockManager(cache);
      for (Object key : cache.keySet()) assert !lm.isLocked(key);
   }
View Full Code Here

      replaceLockManager(componentRegistry);
      componentRegistry.rewire();
   }

   private void replaceLockManager(ComponentRegistry componentRegistry) {
      LockManager oldLockManager = componentRegistry.getComponent(LockManager.class);
      LockManager newLockManager = new ExtendedStatisticLockManager(oldLockManager, cacheStatisticManager, timeService);
      log.replaceComponent("LockManager", oldLockManager, newLockManager);
      componentRegistry.registerComponent(newLockManager, LockManager.class);
   }
View Full Code Here

       */
      public int compareTo(ChangesContainer o)
      {
         // We use the lock manager to sort the key in order to be able
         // to use the lock stripping more details here https://issues.jboss.org/browse/ISPN-993
         LockManager lm = cache.getLockManager();
         int result = lm.getLockId(key) - lm.getLockId(o.getKey());
         return result == 0 ? historicalIndex - o.getHistoricalIndex() : result;
      }
View Full Code Here

   /**
    * Verifies the cache doesn't contain any lock
    * @param cache
    */
   public static void assertNoLocks(Cache<?,?> cache) {
      LockManager lm = TestingUtil.extractLockManager(cache);
      for (Object key : cache.keySet()) assert !lm.isLocked(key);
   }
View Full Code Here

         return currentStored;
      }

      private void checkNoLocks() {
         for (Cache c : caches) {
            LockManager lockManager = c.getAdvancedCache().getComponentRegistry().getComponent(LockManager.class);
            //locks might be released async, so give it some time
            boolean isLocked = true;
            for (int i = 0; i < 30; i++) {
               if (!lockManager.isLocked(SHARED_KEY)) {
                  isLocked = false;
                  break;
               }
               try {
                  Thread.sleep(500);
View Full Code Here

      TransactionManager tm = c.getAdvancedCache().getTransactionManager();
      tm.begin();
      c.getAdvancedCache().lock(new Key("k"));

      LockManager lockManager = TestingUtil.extractComponent(c, LockManager.class);

      assert cex.ctx instanceof LocalTxInvocationContext;

      assert cex.ctx.getLookedUpEntries().size() == 0 : "Looked up key should not be in transactional invocation context " +
                                                      "as we don't perform any changes";
      assertEquals(lockManager.getNumberOfLocksHeld(), 1, "Only one lock should be held");

      c.put(new Key("k"), "v2");

      assert cex.ctx.getLookedUpEntries().size() == 1 : "Still should only be one entry in the context";
      assert lockManager.getNumberOfLocksHeld() == 1 : "Only one lock should be held";

      tm.commit();

      assert lockManager.getNumberOfLocksHeld() == 0 : "No locks should be held anymore";

      assert "v2".equals(c.get(new Key("k")));
   }
View Full Code Here

      sleepThread(1000);
      t2.interrupt();
      TestingUtil.killCacheManagers(cm2);
      sleepThread(1100);
      t1.interrupt();
      LockManager lm = TestingUtil.extractComponent(cm1.getCache(), LockManager.class);
      Object owner = lm.getOwner(key);
      assert ownerIsLocalOrUnlocked(owner, cm1.getAddress()) : "Bad lock owner " + owner;
   }
View Full Code Here

      mgr2.resume(tx2);
      replListener(cache1).expect(InvalidateCommand.class);
      mgr2.commit();
      if (!isSync) replListener(cache1).waitForRpc();

      LockManager lm1 = TestingUtil.extractComponent(cache1, LockManager.class);
      LockManager lm2 = TestingUtil.extractComponent(cache2, LockManager.class);
      assert !lm1.isLocked("key");
      assert !lm2.isLocked("key");

      LockAssert.assertNoLocks(cache1);
      LockAssert.assertNoLocks(cache2);
   }
View Full Code Here

   protected void assertLocked(Cache cache, Object key) {
      assert checkLocked(cache, key) : "expected key '" + key + "' to be locked on cache " + cache + ", but it is not";
   }

   protected boolean checkLocked(Cache cache, Object key) {
      LockManager lockManager = TestingUtil.extractLockManager(cache);
      return lockManager.isLocked(key);
   }
View Full Code Here

TOP

Related Classes of org.infinispan.util.concurrent.locks.LockManager

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.