static <T extends AsyncInterceptor> T findInterceptor(Cache<?, ?> cache, Class<T> interceptorClass) { return cache.getAdvancedCache().getAsyncInterceptorChain().findInterceptorExtending(interceptorClass); } }
protected void invoke(Object session, InvocationContext ctx, RemoveCommand command) { invoker.invoke(ctx, command); }
@TestCachePermission(AuthorizationPermission.ADMIN) public void testAddInterceptor_CommandInterceptor_int(SecureCache<String, String> cache) { cache.getAsyncInterceptorChain().addInterceptor(interceptor, 0); cache.getAsyncInterceptorChain().removeInterceptor(0); }
private SkipIndexingFlagCheckCommandInterceptor init() { Iterator<CommandInterceptor> iterator = cacheManager.getCache(cacheName).getAdvancedCache().getInterceptorChain().iterator(); while (iterator.hasNext()) { CommandInterceptor commandInterceptor = iterator.next(); if (commandInterceptor instanceof SkipIndexingFlagCheckCommandInterceptor) return (SkipIndexingFlagCheckCommandInterceptor) commandInterceptor; } SkipIndexingFlagCheckCommandInterceptor ci = new SkipIndexingFlagCheckCommandInterceptor(); cacheManager.getCache(cacheName).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(ci, 1); return ci; }
AnotherCollectionUpdateTestInterceptor anotherInterceptor = new AnotherCollectionUpdateTestInterceptor(putFromLoadLatch, committing); AsyncInterceptorChain interceptorChain = collectionCache.getAsyncInterceptorChain(); interceptorChain.addInterceptorBefore( collectionUpdateTestInterceptor, CallInterceptor.class ); interceptorChain.addInterceptor(anotherInterceptor, 0); interceptorChain.removeInterceptor(CollectionUpdateTestInterceptor.class); interceptorChain.removeInterceptor(AnotherCollectionUpdateTestInterceptor.class);
/** * This methods should be called only from tests; it removes existing validator from the cache structures * in order to replace it with new one. * * @param cache */ public static PutFromLoadValidator removeFromCache(AdvancedCache cache) { AsyncInterceptorChain chain = cache.getAsyncInterceptorChain(); BasicComponentRegistry cr = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class); chain.removeInterceptor(TxPutFromLoadInterceptor.class); chain.removeInterceptor(NonTxPutFromLoadInterceptor.class); chain.getInterceptors().stream() .filter(BaseInvalidationInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass) .ifPresent(invalidationClass -> { InvalidationInterceptor invalidationInterceptor = new InvalidationInterceptor(); cr.replaceComponent(InvalidationInterceptor.class.getName(), invalidationInterceptor, true); cr.getComponent(InvalidationInterceptor.class).running(); chain.replaceInterceptor(invalidationInterceptor, invalidationClass); }); chain.getInterceptors().stream() .filter(LockingInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass) .ifPresent(invalidationClass -> { NonTransactionalLockingInterceptor lockingInterceptor = new NonTransactionalLockingInterceptor(); cr.replaceComponent(NonTransactionalLockingInterceptor.class.getName(), lockingInterceptor, true); cr.getComponent(NonTransactionalLockingInterceptor.class).running(); chain.replaceInterceptor(lockingInterceptor, LockingInterceptor.class); }); CacheCommandInitializer cci = cr.getComponent(CacheCommandInitializer.class).running(); return cci.removePutFromLoadValidator(cache.getName()); }
@TestCachePermission(AuthorizationPermission.ADMIN) public void testAddInterceptorBefore_CommandInterceptor_Class(SecureCache<String, String> cache) { cache.getAsyncInterceptorChain().addInterceptorBefore(interceptor, InvocationContextInterceptor.class); cache.getAsyncInterceptorChain().removeInterceptor(interceptor.getClass()); }
List<AsyncInterceptor> interceptors = chain.getInterceptors(); log.debugf("Interceptor chain was: ", interceptors); int position = 0; chain.replaceInterceptor(txInvalidationInterceptor, InvalidationInterceptor.class); componentRegistry.replaceComponent(TxPutFromLoadInterceptor.class.getName(), txPutFromLoadInterceptor, true); componentRegistry.getComponent(TxPutFromLoadInterceptor.class).running(); chain.addInterceptor(txPutFromLoadInterceptor, entryWrappingPosition); componentRegistry.replaceComponent(NonTxPutFromLoadInterceptor.class.getName(), nonTxPutFromLoadInterceptor, true); componentRegistry.getComponent(NonTxPutFromLoadInterceptor.class).running(); chain.addInterceptor(nonTxPutFromLoadInterceptor, entryWrappingPosition); chain.replaceInterceptor(nonTxInvalidationInterceptor, InvalidationInterceptor.class); chain.replaceInterceptor(lockingInterceptor, NonTransactionalLockingInterceptor.class);
EntryWrappingInterceptor wrappingInterceptor = ic.findInterceptorExtending(EntryWrappingInterceptor.class); AsyncInterceptor lastLoadingInterceptor = ic.findInterceptorExtending(CacheLoaderInterceptor.class); if (lastLoadingInterceptor == null) { lastLoadingInterceptor = wrappingInterceptor; ic.addInterceptorAfter(queryInterceptor, lastLoadingInterceptor.getClass()); cr.registerComponent(QueryInterceptor.class, queryInterceptor, true); cr.addDynamicDependency(AsyncInterceptorChain.class.getName(), QueryInterceptor.class.getName()); ic.addInterceptorBefore(txQueryInterceptor, wrappingInterceptor.getClass()); cr.registerComponent(TxQueryInterceptor.class, txQueryInterceptor, true); cr.addDynamicDependency(AsyncInterceptorChain.class.getName(), TxQueryInterceptor.class.getName());
@Override public Void run() { T interceptor = getFirstInterceptorWhichExtends(cache.getAsyncInterceptorChain().getInterceptors(), interceptorClass); if (interceptor != null) { interceptor.resetStatistics(); } return null; } }
public void testBothOwnersSuspected(Method m) throws ExecutionException, InterruptedException { initAndCheck(m); CountDownLatch arrival = new CountDownLatch(2); CountDownLatch release = new CountDownLatch(1); AtomicInteger thrown = new AtomicInteger(); AtomicInteger retried = new AtomicInteger(); cache(0).getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(new CheckOTEInterceptor(thrown, retried), StateTransferInterceptor.class); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); Future<Object> future = fork(() -> cache(0).get(key)); assertTrue(arrival.await(10, TimeUnit.SECONDS)); installNewView(cache(0), cache(0)); // The entry was lost, so we'll get null assertNull(future.get()); // Since we've lost all owners, we get an OutdatedTopologyException and we retry assertEquals(1, thrown.get()); assertEquals(1, retried.get()); release.countDown(); }
public static TransactionTrackInterceptor injectInCache(Cache<?, ?> cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); if (chain.containsInterceptorType(TransactionTrackInterceptor.class)) { return chain.findInterceptorWithClass(TransactionTrackInterceptor.class); } TransactionTrackInterceptor interceptor = new TransactionTrackInterceptor(); cache.getAdvancedCache().getComponentRegistry().wireDependencies(interceptor); TestingUtil.startComponent(interceptor); chain.addInterceptor(interceptor, 0); return interceptor; }
public AfterPassivationOrCacheWriter injectThis(Cache<Object, Object> injectInCache) { AsyncInterceptorChain chain = extractComponent(injectInCache, AsyncInterceptorChain.class); AsyncInterceptor interceptor = chain.findInterceptorExtending(CacheWriterInterceptor.class); if (interceptor == null) { interceptor = chain.findInterceptorExtending(CacheLoaderInterceptor.class); } if (interceptor == null) { throw new IllegalStateException("Should not happen!"); } chain.addInterceptorAfter(this, interceptor.getClass()); return this; }
@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); })); }
public AfterEntryWrappingInterceptor injectThis(Cache<Object, Object> injectInCache) { injectInCache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(this, EntryWrappingInterceptor.class); return this; }
private static BlockCommandInterceptor injectBlockCommandInterceptorIfAbsent(Cache<GroupKey, String> cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); BlockCommandInterceptor interceptor = chain.findInterceptorWithClass(BlockCommandInterceptor.class); if (interceptor == null) { interceptor = new BlockCommandInterceptor(); EntryWrappingInterceptor ewi = chain.findInterceptorExtending(EntryWrappingInterceptor.class); assertNotNull(ewi); chain.addInterceptorAfter(interceptor, ewi.getClass()); } interceptor.reset(); return interceptor; }
for (AdvancedCache cache : owners) { BlockingInterceptor bi = new BlockingInterceptor<>(barrier, ReadWriteKeyCommand.class, true, false); cache.getAsyncInterceptorChain().addInterceptorBefore(bi, EntryWrappingInterceptor.class); cache.getAsyncInterceptorChain().findInterceptorWithClass(BlockingInterceptor.class).suspend(true); cache.getAsyncInterceptorChain().removeInterceptor(BlockingInterceptor.class);
private FlagCheckCommandInterceptor init() { AsyncInterceptorChain interceptorChain = cacheManager.getCache(cacheName).getAdvancedCache().getAsyncInterceptorChain(); FlagCheckCommandInterceptor interceptor = interceptorChain.findInterceptorExtending(FlagCheckCommandInterceptor.class); if (interceptor != null) return interceptor; FlagCheckCommandInterceptor ci = new FlagCheckCommandInterceptor(); interceptorChain.addInterceptor(ci, 1); return ci; }
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; } }
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); } }