/** * 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()); }
/** * Replaces an existing interceptor of the given type in the interceptor chain with a new interceptor * instance passed * as parameter. * * @param replacingInterceptor the interceptor to add to the interceptor chain * @param toBeReplacedInterceptorType the type of interceptor that should be swapped with the new one * @return true if the interceptor was replaced */ public static boolean replaceInterceptor(Cache cache, AsyncInterceptor replacingInterceptor, Class<? extends AsyncInterceptor> toBeReplacedInterceptorType) { ComponentRegistry cr = extractComponentRegistry(cache); // make sure all interceptors here are wired. cr.wireDependencies(replacingInterceptor); AsyncInterceptorChain inch = cr.getComponent(AsyncInterceptorChain.class); return inch.replaceInterceptor(replacingInterceptor, toBeReplacedInterceptorType); }
/** * Replaces an existing interceptor of the given type in the interceptor chain with a new interceptor instance passed * as parameter. * * @param replacingInterceptor the interceptor to add to the interceptor chain * @param toBeReplacedInterceptorType the type of interceptor that should be swapped with the new one * * @return true if the interceptor was replaced */ public static boolean replaceInterceptor(Cache cache, CommandInterceptor replacingInterceptor, Class<? extends CommandInterceptor> toBeReplacedInterceptorType) { ComponentRegistry cr = extractComponentRegistry(cache); // make sure all interceptors here are wired. CommandInterceptor i = replacingInterceptor; do { cr.wireDependencies(i); } while ((i = i.getNext()) != null); AsyncInterceptorChain inch = cache.getAdvancedCache().getAsyncInterceptorChain(); return inch.replaceInterceptor(replacingInterceptor, toBeReplacedInterceptorType); }
chain.replaceInterceptor(txInvalidationInterceptor, InvalidationInterceptor.class); componentRegistry.replaceComponent(NonTxInvalidationInterceptor.class.getName(), nonTxInvalidationInterceptor, true); componentRegistry.getComponent(NonTxInvalidationInterceptor.class).running(); chain.replaceInterceptor(nonTxInvalidationInterceptor, InvalidationInterceptor.class); chain.replaceInterceptor(lockingInterceptor, NonTransactionalLockingInterceptor.class);