private Future<?> blockedPutFromLoad(CyclicBarrier putFromLoadBarrier) throws InterruptedException, BrokenBarrierException, TimeoutException { BlockingInterceptor blockingInterceptor = new BlockingInterceptor(putFromLoadBarrier, ReadWriteKeyCommand.class, false, true); entityCache.getAsyncInterceptorChain().addInterceptor(blockingInterceptor, 0); cleanup.add(() -> entityCache.removeInterceptor(BlockingInterceptor.class)); // the putFromLoad should be blocked in the interceptor Future<?> putFromLoad = executor.submit(() -> withTxSessionApply(s -> { assertEquals("Original item", s.load(Item.class, itemId).getDescription()); return null; })); putFromLoadBarrier.await(WAIT_TIMEOUT, TimeUnit.SECONDS); blockingInterceptor.suspend(true); return putFromLoad; }
@Override protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable { if (!blockAfter) { blockIfNeeded(ctx, command); } return invokeNextAndFinally(ctx, command, (rCtx, rCommand, rv, t) -> { if (blockAfter) { blockIfNeeded(rCtx, rCommand); } }); } }
protected BlockingInterceptor addBlockingInterceptor(Cache<?, ?> cache, final CyclicBarrier barrier, Class<? extends VisitableCommand> commandClass, Class<? extends AsyncInterceptor> interceptorPosition, boolean blockAfterCommand) { BlockingInterceptor bi = new BlockingInterceptor<>(barrier, commandClass, blockAfterCommand, false); AsyncInterceptorChain interceptorChain = cache.getAdvancedCache().getAsyncInterceptorChain(); assertTrue(interceptorChain.addInterceptorBefore(bi, interceptorPosition)); return bi; }
protected static void removeAllBlockingInterceptorsFromCache(Cache<?, ?> cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); BlockingInterceptor blockingInterceptor = chain.findInterceptorExtending(BlockingInterceptor.class); while (blockingInterceptor != null) { blockingInterceptor.suspend(true); chain.removeInterceptor(blockingInterceptor.getClass()); blockingInterceptor = chain.findInterceptorExtending(BlockingInterceptor.class); } }
public void test() throws Exception { MagicKey key = new MagicKey(cache(0), cache(1)); cache(2).put(key, "value"); CyclicBarrier barrier0 = new CyclicBarrier(2); cache(0).getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore( new BlockingInterceptor<>(barrier0, GetCacheEntryCommand.class, false, false), EntryWrappingInterceptor.class); Future<Object> f = fork(() -> cache(2).get(key)); barrier0.await(10, TimeUnit.SECONDS); cache(0).stop(); barrier0.await(10, TimeUnit.SECONDS); assertEquals("value", f.get(10, TimeUnit.SECONDS)); } }
blockingInterceptor.suspend(true);
BlockingInterceptor bi = new BlockingInterceptor<>(barrier, ReadWriteKeyCommand.class, true, false); cache.getAsyncInterceptorChain().addInterceptorBefore(bi, EntryWrappingInterceptor.class); cache.getAsyncInterceptorChain().findInterceptorWithClass(BlockingInterceptor.class).suspend(true);
.addInterceptorAfter(new BlockingInterceptor<>(barrier, InvalidateL1Command.class, true, false), EntryWrappingInterceptor.class);
blockingInterceptor.suspend(true);
BlockingInterceptor blockingInterceptor = new BlockingInterceptor<>(distInterceptorBarrier, PutKeyValueCommand.class, false, false); cache0.getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor, TriangleDistributionInterceptor.class); blockingInterceptor.suspend(true); blockingInterceptor.suspend(false);
BlockingInterceptor blockingInterceptor = new BlockingInterceptor<>(barrier, PutKeyValueCommand.class, true, false); cache1.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor, TriangleDistributionInterceptor.class);
BlockingInterceptor blockingInterceptor0 = new BlockingInterceptor<>(barrier, PutKeyValueCommand.class, true, false); cache0.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor0, EntryWrappingInterceptor.class); BlockingInterceptor blockingInterceptor2 = new BlockingInterceptor<>(barrier, PutKeyValueCommand.class, true, false); cache2.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor2, EntryWrappingInterceptor.class); blockingInterceptor0.suspend(true); blockingInterceptor2.suspend(true);
.interceptor(new BlockingInterceptor<>(barrier2, GetCacheEntryCommand.class, true, false))); .addInterceptor(new BlockingInterceptor<>(barrier1, GetCacheEntryCommand.class, false, false), 0);
BlockingInterceptor blockingInterceptor1 = new BlockingInterceptor<>(beforeCommitCache1Barrier, true, false, cacheMode.isScattered() ? t -> t instanceof PutKeyValueCommand || t instanceof RemoveCommand : t -> t.getClass().equals(op.getCommandClass())); blockingInterceptor1.suspend(true);
BlockingInterceptor blockingInterceptor1 = new BlockingInterceptor<>(beforeCache1Barrier, op.getCommandClass(), false, false); cache1.getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor1, TriangleDistributionInterceptor.class); BlockingInterceptor blockingInterceptor2 = new BlockingInterceptor<>(afterCache2Barrier, op.getCommandClass(), true, false, cmd -> !(cmd instanceof FlagAffectedCommand) || !((FlagAffectedCommand) cmd).hasAnyFlag(FlagBitSets.PUT_FOR_STATE_TRANSFER));
BlockingInterceptor blockingInterceptor0 = new BlockingInterceptor<>(beforeCache0Barrier, op.getCommandClass(), false, true); cache0.getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor0, EntryWrappingInterceptor.class); blockingInterceptor0.suspend(true); beforeCache0Barrier.await(10, TimeUnit.SECONDS);
BlockingInterceptor blockingInterceptor1 = new BlockingInterceptor<>(beforeCommitCache1Barrier, getVisitableCommand(op), false, false); primaryOwnerCache.getAsyncInterceptorChain().addInterceptorAfter(blockingInterceptor1, StateTransferInterceptor.class);
BlockingInterceptor oteInterceptor = new BlockingInterceptor(oteBarrier, GetKeyValueCommand.class, true, true); cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(oteInterceptor, StateTransferInterceptor.class); oteInterceptor.suspend(true);
new BlockingInterceptor<>(cyclicBarrier, getVisitableCommand(op), true, false), StateTransferInterceptor.class); return op.perform(primaryOwnerCache, key);
BlockingInterceptor blockingInterceptor1 = new BlockingInterceptor<>(beforeCommitCache1Barrier, op.getCommandClass(), true, false); nonOwnerCache.getAsyncInterceptorChain().addInterceptorAfter(blockingInterceptor1, EntryWrappingInterceptor.class);