use of org.infinispan.interceptors.AsyncInterceptor in project infinispan by infinispan.
the class AbstractPartialUpdateTest method addFailureInducingInterceptor.
private AsyncInterceptor addFailureInducingInterceptor(AdvancedCache<?, ?> cache) {
final AsyncInterceptor interceptor = getFailureInducingInterceptor();
cache.getAsyncInterceptorChain().addInterceptor(interceptor, FIRST.ordinal());
log.trace("Injecting FailureInducingInterceptor into " + cache.getName());
return interceptor;
}
use of org.infinispan.interceptors.AsyncInterceptor in project infinispan by infinispan.
the class AbstractPartialUpdateTest method testPartialUpdate.
@Test
public void testPartialUpdate() throws Exception {
final AsyncInterceptor failureInterceptor = addFailureInducingInterceptor(remoteCustomerCache);
try {
// Remote update latch
CountDownLatch remoteLatch = new CountDownLatch(2);
ExpectingInterceptor.get(remoteCustomerCache).when((ctx, cmd) -> cmd instanceof ReadWriteKeyCommand).countDown(remoteLatch);
try {
Statistics statsNode0 = getStatistics(localFactory);
withTxSession(localFactory, s -> {
Customer customer = new Customer();
customer.setName("JBoss");
s.persist(customer);
});
assertEquals(1, statsNode0.getSecondLevelCachePutCount());
assertEquals(0, statsNode0.getSecondLevelCacheMissCount());
assertEquals(0, statsNode0.getSecondLevelCacheHitCount());
// Wait for value to be applied remotely
assertTrue(remoteLatch.await(2, TimeUnit.SECONDS));
} finally {
ExpectingInterceptor.cleanup(remoteCustomerCache);
}
Statistics statsNode1 = getStatistics(remoteFactory);
withSession(remoteFactory.withOptions(), s -> {
Customer customer = s.load(Customer.class, 1);
assertEquals("JBoss", customer.getName());
});
assertEquals(0, statsNode1.getSecondLevelCachePutCount());
assertEquals(0, statsNode1.getSecondLevelCacheMissCount());
assertEquals(1, statsNode1.getSecondLevelCacheHitCount());
final boolean updated = doUpdate();
if (updated) {
withSession(localFactory.withOptions(), s -> {
Customer customer = s.load(Customer.class, 1);
assertEquals("JBoss, a division of Red Hat", customer.getName());
});
withSession(remoteFactory.withOptions(), s -> {
Customer customer = s.load(Customer.class, 1);
assertEquals("JBoss, a division of Red Hat", customer.getName());
});
}
} finally {
remoteCustomerCache.getAsyncInterceptorChain().removeInterceptor(failureInterceptor.getClass());
}
}
use of org.infinispan.interceptors.AsyncInterceptor 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.AsyncInterceptor in project infinispan by infinispan.
the class CustomInterceptorInjectionTest method testBaseCustomAsyncInterceptorInjection.
public void testBaseCustomAsyncInterceptorInjection() {
AsyncInterceptor interceptor = cache.getAdvancedCache().getAsyncInterceptorChain().getInterceptors().get(0);
assertEquals(SomeAsyncInterceptor.class, interceptor.getClass());
SomeAsyncInterceptor someAsyncInterceptor = (SomeAsyncInterceptor) interceptor;
assertSame(cache.getAdvancedCache().getLockManager(), someAsyncInterceptor.lm);
assertSame(cache.getAdvancedCache().getDataContainer(), someAsyncInterceptor.dc);
}
use of org.infinispan.interceptors.AsyncInterceptor in project infinispan by infinispan.
the class InterceptorChainFactory method buildCustomInterceptors.
private void buildCustomInterceptors(AsyncInterceptorChain interceptorChain, CustomInterceptorsConfiguration customInterceptors) {
for (InterceptorConfiguration config : customInterceptors.interceptors()) {
if (interceptorChain.containsInterceptorType(config.asyncInterceptor().getClass()))
continue;
AsyncInterceptor customInterceptor = config.asyncInterceptor();
SecurityActions.applyProperties(customInterceptor, config.properties());
register(customInterceptor.getClass(), customInterceptor);
if (config.first())
interceptorChain.addInterceptor(customInterceptor, 0);
else if (config.last())
interceptorChain.addInterceptorBefore(customInterceptor, CallInterceptor.class);
else if (config.index() >= 0)
interceptorChain.addInterceptor(customInterceptor, config.index());
else if (config.after() != null) {
boolean added = interceptorChain.addInterceptorAfter(customInterceptor, config.after());
if (!added) {
throw new CacheConfigurationException("Cannot add after class: " + config.after() + " as no such interceptor exists in the default chain");
}
} else if (config.before() != null) {
boolean added = interceptorChain.addInterceptorBefore(customInterceptor, config.before());
if (!added) {
throw new CacheConfigurationException("Cannot add before class: " + config.before() + " as no such interceptor exists in the default chain");
}
} else if (config.position() == InterceptorConfiguration.Position.OTHER_THAN_FIRST_OR_LAST) {
interceptorChain.addInterceptor(customInterceptor, 1);
}
}
}
Aggregations