use of org.infinispan.interceptors.impl.CacheLoaderInterceptor in project infinispan by infinispan.
the class InterceptorChainFactory method addPersistenceInterceptors.
/**
* Adds all the interceptors related to persistence to the stack.
*
* @param interceptorChain The chain
* @param cacheConfiguration The configuration of the cache that owns the interceptor
* @param stores A list of {@link StoreConfiguration} possibly not present in the cacheConfiguration
*/
public void addPersistenceInterceptors(AsyncInterceptorChain interceptorChain, Configuration cacheConfiguration, List<StoreConfiguration> stores) {
TransactionMode transactionMode = cacheConfiguration.transaction().transactionMode();
CacheMode cacheMode = cacheConfiguration.clustering().cacheMode();
EntryWrappingInterceptor ewi = interceptorChain.findInterceptorExtending(EntryWrappingInterceptor.class);
if (ewi == null) {
throw new CacheException("Cannot find instance of EntryWrappingInterceptor in the interceptor chain");
}
Class<? extends AsyncInterceptor> lastAdded = ewi.getClass();
if (cacheConfiguration.persistence().passivation()) {
if (cacheMode.isClustered()) {
lastAdded = addInterceptor(interceptorChain, new PassivationClusteredCacheLoaderInterceptor<>(), CacheLoaderInterceptor.class, lastAdded);
} else {
lastAdded = addInterceptor(interceptorChain, new PassivationCacheLoaderInterceptor<>(), CacheLoaderInterceptor.class, lastAdded);
}
addInterceptor(interceptorChain, new PassivationWriterInterceptor(), PassivationWriterInterceptor.class, lastAdded);
} else {
if (cacheMode.isClustered()) {
lastAdded = addInterceptor(interceptorChain, new ClusteredCacheLoaderInterceptor<>(), CacheLoaderInterceptor.class, lastAdded);
} else {
lastAdded = addInterceptor(interceptorChain, new CacheLoaderInterceptor<>(), CacheLoaderInterceptor.class, lastAdded);
}
boolean transactionalStore = cacheConfiguration.persistence().stores().stream().anyMatch(StoreConfiguration::transactional) || stores.stream().anyMatch(StoreConfiguration::transactional);
if (transactionalStore && transactionMode.isTransactional())
lastAdded = addInterceptor(interceptorChain, new TransactionalStoreInterceptor(), TransactionalStoreInterceptor.class, lastAdded);
switch(cacheMode) {
case DIST_SYNC:
case DIST_ASYNC:
case REPL_SYNC:
case REPL_ASYNC:
addInterceptor(interceptorChain, new DistCacheWriterInterceptor(), DistCacheWriterInterceptor.class, lastAdded);
break;
case SCATTERED_SYNC:
addInterceptor(interceptorChain, new ScatteredCacheWriterInterceptor(), ScatteredCacheWriterInterceptor.class, lastAdded);
break;
default:
addInterceptor(interceptorChain, new CacheWriterInterceptor(), CacheWriterInterceptor.class, lastAdded);
break;
}
}
}
Aggregations