Search in sources :

Example 1 with BiasedEntryWrappingInterceptor

use of org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor in project infinispan by infinispan.

the class InterceptorChainFactory method buildInterceptorChain.

private AsyncInterceptorChain buildInterceptorChain() {
    TransactionMode transactionMode = configuration.transaction().transactionMode();
    boolean needsVersionAwareComponents = Configurations.isTxVersioned(configuration);
    AsyncInterceptorChain interceptorChain = new AsyncInterceptorChainImpl();
    boolean invocationBatching = configuration.invocationBatching().enabled();
    CacheMode cacheMode = configuration.clustering().cacheMode();
    // load the icInterceptor first
    if (invocationBatching) {
        interceptorChain.appendInterceptor(createInterceptor(new BatchingInterceptor(), BatchingInterceptor.class), false);
    }
    interceptorChain.appendInterceptor(createInterceptor(new InvocationContextInterceptor(), InvocationContextInterceptor.class), false);
    if (!configuration.transaction().transactionMode().isTransactional()) {
        interceptorChain.appendInterceptor(createInterceptor(new VersionInterceptor(), VersionInterceptor.class), false);
    }
    // add marshallable check interceptor for situations where we want to figure out before marshalling
    if (hasAsyncStore())
        interceptorChain.appendInterceptor(createInterceptor(new IsMarshallableInterceptor(), IsMarshallableInterceptor.class), false);
    // load the cache management interceptor next
    if (configuration.statistics().available()) {
        interceptorChain.appendInterceptor(createInterceptor(new CacheMgmtInterceptor(), CacheMgmtInterceptor.class), false);
    }
    // the only exception is non-tx invalidation mode, which ignores lock owners
    if (cacheMode.needsStateTransfer() || cacheMode.isInvalidation() && transactionMode.isTransactional()) {
        interceptorChain.appendInterceptor(createInterceptor(new StateTransferInterceptor(), StateTransferInterceptor.class), false);
    }
    if (cacheMode.needsStateTransfer()) {
        if (transactionMode.isTransactional()) {
            interceptorChain.appendInterceptor(createInterceptor(new TransactionSynchronizerInterceptor(), TransactionSynchronizerInterceptor.class), false);
        }
        if (configuration.clustering().partitionHandling().whenSplit() != PartitionHandling.ALLOW_READ_WRITES) {
            interceptorChain.appendInterceptor(createInterceptor(new PartitionHandlingInterceptor(), PartitionHandlingInterceptor.class), false);
        }
    }
    // load the tx interceptor
    if (transactionMode.isTransactional())
        interceptorChain.appendInterceptor(createInterceptor(new TxInterceptor<>(), TxInterceptor.class), false);
    if (!cacheMode.isScattered()) {
        if (transactionMode.isTransactional()) {
            if (configuration.transaction().lockingMode() == LockingMode.PESSIMISTIC) {
                interceptorChain.appendInterceptor(createInterceptor(new PessimisticLockingInterceptor(), PessimisticLockingInterceptor.class), false);
            } else {
                interceptorChain.appendInterceptor(createInterceptor(new OptimisticLockingInterceptor(), OptimisticLockingInterceptor.class), false);
            }
        } else {
            interceptorChain.appendInterceptor(createInterceptor(new NonTransactionalLockingInterceptor(), NonTransactionalLockingInterceptor.class), false);
        }
    }
    // This needs to be after locking interceptor to guarantee that locks are still held when raising notifications
    if (transactionMode.isTransactional() && configuration.transaction().notifications()) {
        interceptorChain.appendInterceptor(createInterceptor(new NotificationInterceptor(), NotificationInterceptor.class), false);
    }
    if (configuration.sites().hasBackups()) {
        if (transactionMode == TransactionMode.TRANSACTIONAL) {
            if (configuration.transaction().lockingMode() == LockingMode.OPTIMISTIC) {
                interceptorChain.appendInterceptor(createInterceptor(new OptimisticBackupInterceptor(), OptimisticBackupInterceptor.class), false);
            } else {
                interceptorChain.appendInterceptor(createInterceptor(new PessimisticBackupInterceptor(), PessimisticBackupInterceptor.class), false);
            }
        } else {
            interceptorChain.appendInterceptor(createInterceptor(new NonTransactionalBackupInterceptor(), NonTransactionalBackupInterceptor.class), false);
        }
    }
    // This needs to be added after the locking interceptor (for tx caches) but before the wrapping interceptor.
    if (configuration.clustering().l1().enabled()) {
        interceptorChain.appendInterceptor(createInterceptor(new L1LastChanceInterceptor(), L1LastChanceInterceptor.class), false);
    }
    if (configuration.clustering().hash().groups().enabled()) {
        interceptorChain.appendInterceptor(createInterceptor(new GroupingInterceptor(), GroupingInterceptor.class), false);
    }
    if (cacheMode.isScattered()) {
        interceptorChain.appendInterceptor(createInterceptor(new PrefetchInterceptor(), PrefetchInterceptor.class), false);
    }
    if (needsVersionAwareComponents) {
        interceptorChain.appendInterceptor(createInterceptor(new VersionedEntryWrappingInterceptor(), VersionedEntryWrappingInterceptor.class), false);
    } else if (cacheMode.isScattered()) {
        if (configuration.clustering().biasAcquisition() == BiasAcquisition.NEVER) {
            interceptorChain.appendInterceptor(createInterceptor(new RetryingEntryWrappingInterceptor(), RetryingEntryWrappingInterceptor.class), false);
        } else {
            interceptorChain.appendInterceptor(createInterceptor(new BiasedEntryWrappingInterceptor(), BiasedEntryWrappingInterceptor.class), false);
        }
    } else {
        interceptorChain.appendInterceptor(createInterceptor(new EntryWrappingInterceptor(), EntryWrappingInterceptor.class), false);
    }
    // Has to be after entry wrapping interceptor so it can properly see context values even when removed
    if (transactionMode.isTransactional()) {
        if (configuration.memory().evictionStrategy().isExceptionBased()) {
            interceptorChain.appendInterceptor(createInterceptor(new TransactionalExceptionEvictionInterceptor(), TransactionalExceptionEvictionInterceptor.class), false);
        }
    }
    if (configuration.persistence().usingStores()) {
        addPersistenceInterceptors(interceptorChain, configuration, configuration.persistence().stores());
    }
    if (configuration.clustering().l1().enabled()) {
        if (transactionMode.isTransactional()) {
            interceptorChain.appendInterceptor(createInterceptor(new L1TxInterceptor(), L1TxInterceptor.class), false);
        } else {
            interceptorChain.appendInterceptor(createInterceptor(new L1NonTxInterceptor(), L1NonTxInterceptor.class), false);
        }
    }
    if (configuration.sites().hasAsyncEnabledBackups() && cacheMode.isClustered()) {
        if (transactionMode == TransactionMode.TRANSACTIONAL) {
            if (configuration.transaction().lockingMode() == LockingMode.OPTIMISTIC) {
                interceptorChain.appendInterceptor(createInterceptor(new OptimisticTxIracLocalSiteInterceptor(), OptimisticTxIracLocalSiteInterceptor.class), false);
            } else {
                interceptorChain.appendInterceptor(createInterceptor(new PessimisticTxIracLocalInterceptor(), PessimisticTxIracLocalInterceptor.class), false);
            }
        } else {
            interceptorChain.appendInterceptor(createInterceptor(new NonTxIracLocalSiteInterceptor(), NonTxIracLocalSiteInterceptor.class), false);
        }
    }
    switch(cacheMode) {
        case INVALIDATION_SYNC:
        case INVALIDATION_ASYNC:
            interceptorChain.appendInterceptor(createInterceptor(new InvalidationInterceptor(), InvalidationInterceptor.class), false);
            break;
        case DIST_SYNC:
        case REPL_SYNC:
            if (needsVersionAwareComponents) {
                interceptorChain.appendInterceptor(createInterceptor(new VersionedDistributionInterceptor(), VersionedDistributionInterceptor.class), false);
                break;
            }
        case DIST_ASYNC:
        case REPL_ASYNC:
            if (transactionMode.isTransactional()) {
                interceptorChain.appendInterceptor(createInterceptor(new TxDistributionInterceptor(), TxDistributionInterceptor.class), false);
            } else {
                if (cacheMode.isDistributed() && Configurations.isEmbeddedMode(globalConfiguration)) {
                    interceptorChain.appendInterceptor(createInterceptor(new TriangleDistributionInterceptor(), TriangleDistributionInterceptor.class), false);
                } else {
                    interceptorChain.appendInterceptor(createInterceptor(new NonTxDistributionInterceptor(), NonTxDistributionInterceptor.class), false);
                }
            }
            break;
        case SCATTERED_SYNC:
            if (configuration.clustering().biasAcquisition() != BiasAcquisition.NEVER) {
                interceptorChain.appendInterceptor(createInterceptor(new BiasedScatteredDistributionInterceptor(), BiasedScatteredDistributionInterceptor.class), false);
            } else {
                interceptorChain.appendInterceptor(createInterceptor(new ScatteredDistributionInterceptor(), ScatteredDistributionInterceptor.class), false);
            }
            break;
        case LOCAL:
    }
    if (cacheMode.isClustered()) {
        // local caches not involved in Cross Site Replication
        interceptorChain.appendInterceptor(createInterceptor(new NonTxIracRemoteSiteInterceptor(needsVersionAwareComponents), NonTxIracRemoteSiteInterceptor.class), false);
    }
    AsyncInterceptor callInterceptor = createInterceptor(new CallInterceptor(), CallInterceptor.class);
    interceptorChain.appendInterceptor(callInterceptor, false);
    log.trace("Finished building default interceptor chain.");
    buildCustomInterceptors(interceptorChain, configuration.customInterceptors());
    return interceptorChain;
}
Also used : CallInterceptor(org.infinispan.interceptors.impl.CallInterceptor) NotificationInterceptor(org.infinispan.interceptors.impl.NotificationInterceptor) StateTransferInterceptor(org.infinispan.statetransfer.StateTransferInterceptor) PessimisticLockingInterceptor(org.infinispan.interceptors.locking.PessimisticLockingInterceptor) L1LastChanceInterceptor(org.infinispan.interceptors.distribution.L1LastChanceInterceptor) EntryWrappingInterceptor(org.infinispan.interceptors.impl.EntryWrappingInterceptor) RetryingEntryWrappingInterceptor(org.infinispan.interceptors.impl.RetryingEntryWrappingInterceptor) VersionedEntryWrappingInterceptor(org.infinispan.interceptors.impl.VersionedEntryWrappingInterceptor) BiasedEntryWrappingInterceptor(org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor) OptimisticBackupInterceptor(org.infinispan.interceptors.xsite.OptimisticBackupInterceptor) CacheMode(org.infinispan.configuration.cache.CacheMode) NonTxIracRemoteSiteInterceptor(org.infinispan.interceptors.impl.NonTxIracRemoteSiteInterceptor) VersionedEntryWrappingInterceptor(org.infinispan.interceptors.impl.VersionedEntryWrappingInterceptor) VersionInterceptor(org.infinispan.interceptors.impl.VersionInterceptor) NonTxIracLocalSiteInterceptor(org.infinispan.interceptors.impl.NonTxIracLocalSiteInterceptor) ScatteredDistributionInterceptor(org.infinispan.interceptors.distribution.ScatteredDistributionInterceptor) BiasedScatteredDistributionInterceptor(org.infinispan.interceptors.distribution.BiasedScatteredDistributionInterceptor) PartitionHandlingInterceptor(org.infinispan.partitionhandling.impl.PartitionHandlingInterceptor) TransactionalExceptionEvictionInterceptor(org.infinispan.interceptors.impl.TransactionalExceptionEvictionInterceptor) TxDistributionInterceptor(org.infinispan.interceptors.distribution.TxDistributionInterceptor) NonTxDistributionInterceptor(org.infinispan.interceptors.distribution.NonTxDistributionInterceptor) NonTransactionalBackupInterceptor(org.infinispan.interceptors.xsite.NonTransactionalBackupInterceptor) TransactionMode(org.infinispan.transaction.TransactionMode) NonTxDistributionInterceptor(org.infinispan.interceptors.distribution.NonTxDistributionInterceptor) PrefetchInterceptor(org.infinispan.interceptors.impl.PrefetchInterceptor) InvocationContextInterceptor(org.infinispan.interceptors.impl.InvocationContextInterceptor) BiasedEntryWrappingInterceptor(org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor) GroupingInterceptor(org.infinispan.interceptors.impl.GroupingInterceptor) CacheMgmtInterceptor(org.infinispan.interceptors.impl.CacheMgmtInterceptor) IsMarshallableInterceptor(org.infinispan.interceptors.impl.IsMarshallableInterceptor) InvalidationInterceptor(org.infinispan.interceptors.impl.InvalidationInterceptor) TransactionSynchronizerInterceptor(org.infinispan.statetransfer.TransactionSynchronizerInterceptor) TriangleDistributionInterceptor(org.infinispan.interceptors.distribution.TriangleDistributionInterceptor) AsyncInterceptorChainImpl(org.infinispan.interceptors.impl.AsyncInterceptorChainImpl) OptimisticTxIracLocalSiteInterceptor(org.infinispan.interceptors.impl.OptimisticTxIracLocalSiteInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) EmptyAsyncInterceptorChain(org.infinispan.interceptors.EmptyAsyncInterceptorChain) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) L1NonTxInterceptor(org.infinispan.interceptors.distribution.L1NonTxInterceptor) OptimisticLockingInterceptor(org.infinispan.interceptors.locking.OptimisticLockingInterceptor) L1TxInterceptor(org.infinispan.interceptors.distribution.L1TxInterceptor) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) BatchingInterceptor(org.infinispan.interceptors.impl.BatchingInterceptor) VersionedDistributionInterceptor(org.infinispan.interceptors.distribution.VersionedDistributionInterceptor) BiasedScatteredDistributionInterceptor(org.infinispan.interceptors.distribution.BiasedScatteredDistributionInterceptor) RetryingEntryWrappingInterceptor(org.infinispan.interceptors.impl.RetryingEntryWrappingInterceptor) PessimisticBackupInterceptor(org.infinispan.interceptors.xsite.PessimisticBackupInterceptor) PessimisticTxIracLocalInterceptor(org.infinispan.interceptors.impl.PessimisticTxIracLocalInterceptor)

Aggregations

CacheMode (org.infinispan.configuration.cache.CacheMode)1 AsyncInterceptor (org.infinispan.interceptors.AsyncInterceptor)1 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)1 EmptyAsyncInterceptorChain (org.infinispan.interceptors.EmptyAsyncInterceptorChain)1 BiasedScatteredDistributionInterceptor (org.infinispan.interceptors.distribution.BiasedScatteredDistributionInterceptor)1 L1LastChanceInterceptor (org.infinispan.interceptors.distribution.L1LastChanceInterceptor)1 L1NonTxInterceptor (org.infinispan.interceptors.distribution.L1NonTxInterceptor)1 L1TxInterceptor (org.infinispan.interceptors.distribution.L1TxInterceptor)1 NonTxDistributionInterceptor (org.infinispan.interceptors.distribution.NonTxDistributionInterceptor)1 ScatteredDistributionInterceptor (org.infinispan.interceptors.distribution.ScatteredDistributionInterceptor)1 TriangleDistributionInterceptor (org.infinispan.interceptors.distribution.TriangleDistributionInterceptor)1 TxDistributionInterceptor (org.infinispan.interceptors.distribution.TxDistributionInterceptor)1 VersionedDistributionInterceptor (org.infinispan.interceptors.distribution.VersionedDistributionInterceptor)1 AsyncInterceptorChainImpl (org.infinispan.interceptors.impl.AsyncInterceptorChainImpl)1 BatchingInterceptor (org.infinispan.interceptors.impl.BatchingInterceptor)1 BiasedEntryWrappingInterceptor (org.infinispan.interceptors.impl.BiasedEntryWrappingInterceptor)1 CacheMgmtInterceptor (org.infinispan.interceptors.impl.CacheMgmtInterceptor)1 CallInterceptor (org.infinispan.interceptors.impl.CallInterceptor)1 EntryWrappingInterceptor (org.infinispan.interceptors.impl.EntryWrappingInterceptor)1 GroupingInterceptor (org.infinispan.interceptors.impl.GroupingInterceptor)1