public void appendState(StringBuffer sbState) {
   sbState.append("\nClusterManager {");
   for (ScheduledAction sa : setScheduledActions) {
     sbState.append("\n\t" + sa + ", from:" + sa.getRequest().caller);
   }
   sbState.append("\n}");
 }
 public void invalidateScheduledActionsFor(Address endpoint, Set<Integer> threadIds) {
   if (!node.joined() || !node.isActive()) return;
   if (setScheduledActions.size() > 0) {
     Iterator<ScheduledAction> it = setScheduledActions.iterator();
     while (it.hasNext()) {
       ScheduledAction sa = it.next();
       Request request = sa.getRequest();
       if (endpoint.equals(request.caller) && threadIds.contains(request.lockThreadId)) {
         sa.setValid(false);
         it.remove();
       }
     }
   }
 }
 public void checkScheduledActions() {
   if (!node.joined() || !node.isActive()) return;
   if (setScheduledActions.size() > 0) {
     Iterator<ScheduledAction> it = setScheduledActions.iterator();
     while (it.hasNext()) {
       ScheduledAction sa = it.next();
       if (sa.expired() && sa.isValid()) {
         sa.onExpire();
         it.remove();
       } else if (!sa.isValid()) {
         it.remove();
       }
     }
   }
 }
Beispiel #4
0
 @Test
 public void testMigrationOfTTLAndLock() throws Exception {
   Config config = new Config();
   final HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
   final HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
   ConcurrentMapManager cmm1 = getConcurrentMapManager(h1);
   ConcurrentMapManager cmm2 = getConcurrentMapManager(h2);
   final IMap imap1 = h1.getMap("default");
   final IMap imap2 = h2.getMap("default");
   final Data dKey = toData("1");
   assertTrue(migrateKey("1", h1, h1, 0));
   assertTrue(migrateKey("1", h1, h2, 1));
   imap1.put("1", "value1", 60, TimeUnit.SECONDS);
   imap1.lock("1");
   Future put2 = imap2.putAsync("1", "value2");
   imap2.addEntryListener(
       new EntryAdapter() {
         @Override
         public void entryUpdated(EntryEvent entryEvent) {
           System.out.println(entryEvent);
         }
       },
       "1",
       true);
   if (put2 == null) fail();
   Thread.sleep(1000);
   CMap cmap1 = getCMap(h1, "default");
   CMap cmap2 = getCMap(h2, "default");
   Record record1 = cmap1.getRecord(dKey);
   assertEquals(1, record1.getScheduledActionCount());
   for (ScheduledAction scheduledAction : record1.getScheduledActions()) {
     assertTrue(scheduledAction.isValid());
   }
   assertNotNull(record1.getListeners());
   assertEquals(1, record1.getListeners().size());
   DistributedLock lock = cmap1.getRecord(dKey).getLock();
   assertTrue(cmm1.thisAddress.equals(lock.getLockAddress()));
   assertTrue(lock.getLockThreadId() != -1);
   assertEquals(1, lock.getLockCount());
   assertEquals(1, cmap1.mapRecords.size());
   assertEquals(1, cmap2.mapRecords.size());
   assertEquals(0, cmap2.getMapIndexService().getOwnedRecords().size());
   assertEquals(1, cmap1.getMapIndexService().getOwnedRecords().size());
   assertTrue(migrateKey("1", h1, h2, 0));
   assertTrue(migrateKey("1", h1, h1, 1));
   assertEquals(1, cmap1.mapRecords.size());
   assertEquals(1, cmap2.mapRecords.size());
   assertEquals(0, cmap1.getMapIndexService().getOwnedRecords().size());
   assertEquals(1, cmap2.getMapIndexService().getOwnedRecords().size());
   assertTrue(cmap1.getRecord(dKey).getRemainingTTL() < 60000);
   assertTrue(cmap2.getRecord(dKey).getRemainingTTL() < 60000);
   Record record2 = cmap2.getRecord(dKey);
   lock = record2.getLock();
   assertTrue(cmm1.thisAddress.equals(lock.getLockAddress()));
   assertTrue(lock.getLockThreadId() != -1);
   assertEquals(1, lock.getLockCount());
   lock = cmap1.getRecord(dKey).getLock();
   assertTrue(cmm1.thisAddress.equals(lock.getLockAddress()));
   assertTrue(lock.getLockThreadId() != -1);
   assertEquals(1, lock.getLockCount());
   imap1.unlock("1");
   put2.get(10, TimeUnit.SECONDS);
   assertEquals("value2", imap1.get("1"));
   assertEquals("value2", imap2.get("1"));
   assertNotNull(record2.getListeners());
   assertEquals(1, record2.getListeners().size());
 }