use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.
the class PutFromLoadValidator method removeFromCache.
/**
* 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);
});
return cr.getComponent(PutFromLoadValidator.class).running();
}
use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.
the class PersistenceManagerImpl method disableStore.
@Override
public CompletionStage<Void> disableStore(String storeType) {
boolean stillHasAStore = false;
AggregateCompletionStage<Void> aggregateCompletionStage = CompletionStages.aggregateCompletionStage();
long stamp = lock.writeLock();
try {
if (!checkStoreAvailability()) {
return CompletableFutures.completedNull();
}
boolean allAvailable = true;
Iterator<StoreStatus> statusIterator = stores.iterator();
while (statusIterator.hasNext()) {
StoreStatus status = statusIterator.next();
NonBlockingStore<?, ?> nonBlockingStore = unwrapStore(status.store());
if (nonBlockingStore.getClass().getName().equals(storeType) || containedInAdapter(nonBlockingStore, storeType)) {
statusIterator.remove();
aggregateCompletionStage.dependsOn(nonBlockingStore.stop().whenComplete((v, t) -> {
if (t != null) {
log.warn("There was an error stopping the store", t);
}
}));
} else {
stillHasAStore = true;
allAvailable = allAvailable && status.availability;
}
}
if (!stillHasAStore) {
unavailableExceptionMessage = null;
enabled = false;
stopAvailabilityTask();
} else if (allAvailable) {
unavailableExceptionMessage = null;
}
allSegmentedOrShared = allStoresSegmentedOrShared();
listeners.forEach(l -> l.storeChanged(createStatus()));
if (!stillHasAStore) {
AsyncInterceptorChain chain = cache.wired().getAsyncInterceptorChain();
AsyncInterceptor loaderInterceptor = chain.findInterceptorExtending(CacheLoaderInterceptor.class);
if (loaderInterceptor == null) {
PERSISTENCE.persistenceWithoutCacheLoaderInterceptor();
} else {
chain.removeInterceptor(loaderInterceptor.getClass());
}
AsyncInterceptor writerInterceptor = chain.findInterceptorExtending(CacheWriterInterceptor.class);
if (writerInterceptor == null) {
writerInterceptor = chain.findInterceptorWithClass(TransactionalStoreInterceptor.class);
if (writerInterceptor == null) {
PERSISTENCE.persistenceWithoutCacheWriteInterceptor();
} else {
chain.removeInterceptor(writerInterceptor.getClass());
}
} else {
chain.removeInterceptor(writerInterceptor.getClass());
}
}
return aggregateCompletionStage.freeze();
} finally {
lock.unlockWrite(stamp);
}
}
use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.
the class SimpleCacheTest method testFindInterceptor.
public void testFindInterceptor() {
AsyncInterceptorChain interceptorChain = cache().getAdvancedCache().getAsyncInterceptorChain();
assertNotNull(interceptorChain);
assertNull(interceptorChain.findInterceptorExtending(InvocationContextInterceptor.class));
}
use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.
the class CacheManagerComponentRegistryTest method testOverridingComponents.
public void testOverridingComponents() {
cm = TestCacheManagerFactory.createClusteredCacheManager(new ConfigurationBuilder());
// default cache with no overrides
Cache c = cm.getCache();
ConfigurationBuilder overrides = new ConfigurationBuilder();
overrides.invocationBatching().enable();
cm.defineConfiguration("overridden", overrides.build());
Cache overridden = cm.getCache("overridden");
// assert components.
AsyncInterceptorChain initialChain = c.getAdvancedCache().getAsyncInterceptorChain();
assert !initialChain.containsInterceptorType(BatchingInterceptor.class);
AsyncInterceptorChain overriddenChain = overridden.getAdvancedCache().getAsyncInterceptorChain();
assert overriddenChain.containsInterceptorType(BatchingInterceptor.class);
}
use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.
the class DomainDataRegionImpl method prepareCommon.
private void prepareCommon(CacheMode cacheMode) {
BasicComponentRegistry registry = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
if (cacheMode.isReplicated() || cacheMode.isDistributed()) {
AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
LockingInterceptor lockingInterceptor = new LockingInterceptor();
registry.registerComponent(LockingInterceptor.class, lockingInterceptor, true);
registry.getComponent(LockingInterceptor.class).running();
if (!chain.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) {
throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
}
chain.removeInterceptor(NonTransactionalLockingInterceptor.class);
UnorderedDistributionInterceptor distributionInterceptor = new UnorderedDistributionInterceptor();
registry.registerComponent(UnorderedDistributionInterceptor.class, distributionInterceptor, true);
registry.getComponent(UnorderedDistributionInterceptor.class).running();
if (!chain.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class) && !chain.addInterceptorBefore(distributionInterceptor, TriangleDistributionInterceptor.class)) {
throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
}
chain.removeInterceptor(NonTxDistributionInterceptor.class);
chain.removeInterceptor(TriangleDistributionInterceptor.class);
}
// ClusteredExpirationManager sends RemoteExpirationCommands to remote nodes which causes
// undesired overhead. When get() triggers a RemoteExpirationCommand executed in async executor
// this locks the entry for the duration of RPC, and putFromLoad with ZERO_LOCK_ACQUISITION_TIMEOUT
// fails as it finds the entry being blocked.
ComponentRef<InternalExpirationManager> ref = registry.getComponent(InternalExpirationManager.class);
InternalExpirationManager expirationManager = ref.running();
if (expirationManager instanceof ClusterExpirationManager) {
registry.replaceComponent(InternalExpirationManager.class.getName(), new ExpirationManagerImpl<>(), true);
registry.getComponent(InternalExpirationManager.class).running();
registry.rewire();
// re-registering component does not stop the old one
((ClusterExpirationManager) expirationManager).stop();
} else if (expirationManager instanceof ExpirationManagerImpl) {
// do nothing
} else {
throw new IllegalStateException("Expected clustered expiration manager, found " + expirationManager);
}
registry.registerComponent(InfinispanDataRegion.class, this, true);
if (cacheMode.isClustered()) {
UnorderedReplicationLogic replLogic = new UnorderedReplicationLogic();
registry.replaceComponent(ClusteringDependentLogic.class.getName(), replLogic, true);
registry.getComponent(ClusteringDependentLogic.class).running();
registry.rewire();
}
}
Aggregations