Search in sources :

Example 1 with CacheLoaderInterceptor

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;
        }
    }
}
Also used : PassivationWriterInterceptor(org.infinispan.interceptors.impl.PassivationWriterInterceptor) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) CacheException(org.infinispan.commons.CacheException) EntryWrappingInterceptor(org.infinispan.interceptors.impl.EntryWrappingInterceptor) RetryingEntryWrappingInterceptor(org.infinispan.interceptors.impl.RetryingEntryWrappingInterceptor) VersionedEntryWrappingInterceptor(org.infinispan.interceptors.impl.VersionedEntryWrappingInterceptor) BiasedEntryWrappingInterceptor(org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor) PassivationClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor) CacheMode(org.infinispan.configuration.cache.CacheMode) DistCacheWriterInterceptor(org.infinispan.interceptors.impl.DistCacheWriterInterceptor) ScatteredCacheWriterInterceptor(org.infinispan.interceptors.impl.ScatteredCacheWriterInterceptor) DistCacheWriterInterceptor(org.infinispan.interceptors.impl.DistCacheWriterInterceptor) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) ScatteredCacheWriterInterceptor(org.infinispan.interceptors.impl.ScatteredCacheWriterInterceptor) TransactionMode(org.infinispan.transaction.TransactionMode) ClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.ClusteredCacheLoaderInterceptor) PassivationClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor) ClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.ClusteredCacheLoaderInterceptor) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) PassivationCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationCacheLoaderInterceptor) PassivationClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor) PassivationCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationCacheLoaderInterceptor)

Aggregations

CacheException (org.infinispan.commons.CacheException)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1 BiasedEntryWrappingInterceptor (org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor)1 CacheLoaderInterceptor (org.infinispan.interceptors.impl.CacheLoaderInterceptor)1 CacheWriterInterceptor (org.infinispan.interceptors.impl.CacheWriterInterceptor)1 ClusteredCacheLoaderInterceptor (org.infinispan.interceptors.impl.ClusteredCacheLoaderInterceptor)1 DistCacheWriterInterceptor (org.infinispan.interceptors.impl.DistCacheWriterInterceptor)1 EntryWrappingInterceptor (org.infinispan.interceptors.impl.EntryWrappingInterceptor)1 PassivationCacheLoaderInterceptor (org.infinispan.interceptors.impl.PassivationCacheLoaderInterceptor)1 PassivationClusteredCacheLoaderInterceptor (org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor)1 PassivationWriterInterceptor (org.infinispan.interceptors.impl.PassivationWriterInterceptor)1 RetryingEntryWrappingInterceptor (org.infinispan.interceptors.impl.RetryingEntryWrappingInterceptor)1 ScatteredCacheWriterInterceptor (org.infinispan.interceptors.impl.ScatteredCacheWriterInterceptor)1 TransactionalStoreInterceptor (org.infinispan.interceptors.impl.TransactionalStoreInterceptor)1 VersionedEntryWrappingInterceptor (org.infinispan.interceptors.impl.VersionedEntryWrappingInterceptor)1 TransactionMode (org.infinispan.transaction.TransactionMode)1