use of org.apache.ignite.spi.systemview.view.datastructures.ReentrantLockView in project ignite by apache.
the class SystemViewSelfTest method testLocks.
/**
*/
@Test
public void testLocks() throws Exception {
try (IgniteEx g0 = startGrid(0);
IgniteEx g1 = startGrid(1)) {
IgniteLock l1 = g0.reentrantLock("l1", false, true, true);
IgniteLock l2 = g0.reentrantLock("l2", true, false, true);
SystemView<ReentrantLockView> locks0 = g0.context().systemView().view(LOCKS_VIEW);
SystemView<ReentrantLockView> locks1 = g1.context().systemView().view(LOCKS_VIEW);
assertEquals(2, locks0.size());
assertEquals(0, locks1.size());
String grpName = DEFAULT_VOLATILE_DS_GROUP_NAME + "@" + VOLATILE_DATA_REGION_NAME;
IgniteInternalFuture<?> lockFut = null;
Runnable lockNSleep = () -> {
l1.lock();
try {
Thread.sleep(getTestTimeout());
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
l1.unlock();
}
};
for (ReentrantLockView l : locks0) {
if ("l1".equals(l.name())) {
assertFalse(l.locked());
assertFalse(l.hasQueuedThreads());
assertFalse(l.failoverSafe());
assertTrue(l.fair());
assertFalse(l.broken());
assertFalse(l.removed());
lockFut = runAsync(lockNSleep);
assertTrue(waitForCondition(l::locked, getTestTimeout()));
} else {
assertFalse(l.hasQueuedThreads());
assertTrue(l.failoverSafe());
assertFalse(l.fair());
assertFalse(l.broken());
assertFalse(l.removed());
l2.close();
assertTrue(waitForCondition(l::removed, getTestTimeout()));
}
assertEquals(grpName, l.groupName());
assertEquals(CU.cacheId(grpName), l.groupId());
}
IgniteLock l3 = g1.reentrantLock("l1", true, false, true);
assertEquals(1, locks1.size());
ReentrantLockView s = locks1.iterator().next();
assertTrue(s.locked());
assertFalse(s.hasQueuedThreads());
assertFalse(s.failoverSafe());
assertTrue(s.fair());
assertFalse(s.broken());
assertFalse(s.removed());
lockFut.cancel();
assertTrue(waitForCondition(() -> !s.locked(), getTestTimeout()));
assertFalse(s.hasQueuedThreads());
l3.close();
assertTrue(waitForCondition(s::removed, getTestTimeout()));
assertEquals(0, locks0.size());
assertEquals(0, locks1.size());
}
}
use of org.apache.ignite.spi.systemview.view.datastructures.ReentrantLockView in project ignite by apache.
the class DataStructuresProcessor method registerSystemViews.
/**
* Register system views.
*/
private void registerSystemViews() {
ctx.systemView().registerView(SEQUENCES_VIEW, SEQUENCES_VIEW_DESC, new AtomicSequenceViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteAtomicSequence), AtomicSequenceView::new);
ctx.systemView().registerView(LONGS_VIEW, LONGS_VIEW_DESC, new AtomicLongViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteAtomicLong), AtomicLongView::new);
ctx.systemView().registerView(REFERENCES_VIEW, REFERENCES_VIEW_DESC, new AtomicReferenceViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteAtomicReference), AtomicReferenceView::new);
ctx.systemView().registerView(STAMPED_VIEW, STAMPED_VIEW_DESC, new AtomicStampedViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteAtomicStamped), AtomicStampedView::new);
ctx.systemView().registerView(LATCHES_VIEW, LATCHES_VIEW_DESC, new CountDownLatchViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteCountDownLatch), CountDownLatchView::new);
ctx.systemView().registerView(SEMAPHORES_VIEW, SEMAPHORES_VIEW_DESC, new SemaphoreViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteSemaphore), SemaphoreView::new);
ctx.systemView().registerView(LOCKS_VIEW, LOCKS_VIEW_DESC, new ReentrantLockViewWalker(), new PredicateCollectionView<>(dsMap.values(), v -> v instanceof IgniteLock), ReentrantLockView::new);
ctx.systemView().registerInnerCollectionView(QUEUES_VIEW, QUEUES_VIEW_DESC, new QueueViewWalker(), new TransformCollectionView<>(ctx.cache().cacheDescriptors().values(), desc -> ctx.cache().cache(desc.cacheName()).context().dataStructures(), desc -> desc.cacheType() == CacheType.DATA_STRUCTURES), cctx -> cctx.queues().values(), (cctx, queue) -> new QueueView(queue));
ctx.systemView().registerInnerCollectionView(SETS_VIEW, SETS_VIEW_DESC, new SetViewWalker(), F.viewReadOnly(ctx.cache().cacheDescriptors().values(), desc -> ctx.cache().cache(desc.cacheName()).context().dataStructures(), desc -> desc.cacheType() == CacheType.DATA_STRUCTURES), cctx -> cctx.sets().values(), (cctx, set) -> new SetView(set));
}
Aggregations