@Override protected void createCacheManagers() throws Throwable { super.createCacheManagers(); countingRequestRepositories = cacheManagers.stream().map(cm -> CountingRequestRepository.replaceDispatcher(cm)).collect(Collectors.toList()); Stream.of(null, DIST, REPL, SCATTERED).forEach(name -> caches(name).forEach(c -> { c.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(new CommandCachingInterceptor(), CallInterceptor.class); })); }
@TestCachePermission(AuthorizationPermission.ADMIN) public void testAddInterceptorBefore_CommandInterceptor_Class(SecureCache<String, String> cache) { cache.getAsyncInterceptorChain().addInterceptorBefore(interceptor, InvocationContextInterceptor.class); cache.getAsyncInterceptorChain().removeInterceptor(interceptor.getClass()); }
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; }
for (AdvancedCache cache : owners) { BlockingInterceptor bi = new BlockingInterceptor<>(barrier, ReadWriteKeyCommand.class, true, false); cache.getAsyncInterceptorChain().addInterceptorBefore(bi, EntryWrappingInterceptor.class);
public static CountingInterceptor inject(Cache cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); if (chain.containsInterceptorType(CountingInterceptor.class)) { return chain.findInterceptorWithClass(CountingInterceptor.class); } CountingInterceptor interceptor = new CountingInterceptor(); chain.addInterceptorBefore(interceptor, CallInterceptor.class); return interceptor; } }
if (!chain.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) { throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain); if (!chain.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class) && !chain.addInterceptorBefore( distributionInterceptor, TriangleDistributionInterceptor.class)) { throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
public static TxCommandInterceptor inject(Cache cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); if (chain.containsInterceptorType(TxCommandInterceptor.class)) { return chain.findInterceptorWithClass(TxCommandInterceptor.class); } TxCommandInterceptor interceptor = new TxCommandInterceptor(); chain.addInterceptorBefore(interceptor, CallInterceptor.class); return interceptor; } }
ic.addInterceptorBefore(txQueryInterceptor, wrappingInterceptor.getClass()); cr.registerComponent(TxQueryInterceptor.class, txQueryInterceptor, true); cr.addDynamicDependency(AsyncInterceptorChain.class.getName(), TxQueryInterceptor.class.getName());
private void initOurInterceptor() { if (ourInterceptor == null) { ourInterceptor = SequencerInterceptor.createUniqueInterceptor(cache.getAdvancedCache().getAsyncInterceptorChain()); ourInterceptor.init(stateSequencer, matcher); cache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(ourInterceptor, interceptorClass); } }
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)); } }
.addInterceptorBefore(beforeInterceptor, StateTransferInterceptor.class); cache(2).getAdvancedCache().getAsyncInterceptorChain() .addInterceptorBefore(afterInterceptor, StateTransferInterceptor.class);
cache0.getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor, TriangleDistributionInterceptor.class);
public void testModsCommit() throws Exception { Cache<Object, Object> c1 = cache(0); Cache<Object, Object> c2 = cache(NUM_CACHES /2); // force the prepare command to fail on c2 FailInterceptor interceptor = new FailInterceptor(); interceptor.failFor(VersionedPrepareCommand.class); AsyncInterceptorChain ic = c2.getAdvancedCache().getAsyncInterceptorChain(); ic.addInterceptorBefore(interceptor, VersionedDistributionInterceptor.class); MagicKey k1 = new MagicKey("k1", c1); tm(c1).begin(); c1.put(k1, "v1"); try { tm(c1).commit(); assert false : "Commit should have failed"; } catch (Exception e) { // expected } for (int i = 0; i < NUM_CACHES; i++) { assertEventuallyNotLocked(cache(i), k1); } } }
AnotherCollectionUpdateTestInterceptor anotherInterceptor = new AnotherCollectionUpdateTestInterceptor(putFromLoadLatch, committing); AsyncInterceptorChain interceptorChain = collectionCache.getAsyncInterceptorChain(); interceptorChain.addInterceptorBefore( collectionUpdateTestInterceptor, CallInterceptor.class ); interceptorChain.addInterceptor(anotherInterceptor, 0);
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);
cache1.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(blockingInterceptor, TriangleDistributionInterceptor.class);
c2ic.addInterceptorBefore(new CommandInterceptor() { @Override protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable {
interceptor.failFor(PrepareCommand.class); AsyncInterceptorChain ic = c2.getAdvancedCache().getAsyncInterceptorChain(); ic.addInterceptorBefore(interceptor, TxDistributionInterceptor.class);
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder configuration = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true); configuration.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()) .useSynchronization(false) .recovery().enable() .locking().useLockStriping(false) .clustering().hash().numOwners(2) .clustering().l1().disable().stateTransfer().fetchInMemoryState(false); createCluster(configuration, 2); waitForClusterToForm(); advancedCache(1).getAsyncInterceptorChain().addInterceptorBefore(new ForceFailureInterceptor(), InvocationContextInterceptor.class); }
Cache<String, String> cache2 = cache(1, CACHE_NAME); assertTrue(cache1.getAdvancedCache().getAsyncInterceptorChain().addInterceptorBefore(new BaseAsyncInterceptor() { @Override public Object visitCommand(InvocationContext ctx, VisitableCommand command)