Search in sources :

Example 16 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class TriangleExceptionDuringMarshallingTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    GlobalConfigurationBuilder globalBuilder = GlobalConfigurationBuilder.defaultClusteredBuilder();
    globalBuilder.serialization().marshaller(new JavaSerializationMarshaller());
    globalBuilder.serialization().allowList().addClasses(MagicKey.class, MarshallingExceptionGenerator.class);
    ConfigurationBuilder cacheBuilder = new ConfigurationBuilder();
    ControlledConsistentHashFactory<?> chf = new ControlledConsistentHashFactory.Default(new int[][] { { 0, 1 }, { 1, 2 }, { 2, 0 } });
    cacheBuilder.clustering().cacheMode(CacheMode.DIST_SYNC).hash().numSegments(NUM_SEGMENTS).consistentHashFactory(chf);
    createCluster(globalBuilder, cacheBuilder, 3);
    // Make sure we're using the triangle algorithm
    AsyncInterceptorChain asyncInterceptorChain = extractInterceptorChain(cache(0));
    assertTrue(asyncInterceptorChain.containsInterceptorType(TriangleDistributionInterceptor.class));
}
Also used : GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) TriangleDistributionInterceptor(org.infinispan.interceptors.distribution.TriangleDistributionInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Example 17 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class GetGroupKeysTest method injectIfAbsent.

private BlockCommandInterceptor injectIfAbsent(Cache<?, ?> cache) {
    log.debugf("Injecting BlockCommandInterceptor in %s", cache);
    AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain();
    BlockCommandInterceptor interceptor = chain.findInterceptorExtending(BlockCommandInterceptor.class);
    if (interceptor == null) {
        interceptor = new BlockCommandInterceptor(log);
        EntryWrappingInterceptor ewi = chain.findInterceptorExtending(EntryWrappingInterceptor.class);
        AssertJUnit.assertTrue(chain.addInterceptorAfter(interceptor, ewi.getClass()));
    }
    interceptor.reset();
    log.debugf("Injected BlockCommandInterceptor in %s. Interceptor=%s", cache, interceptor);
    return interceptor;
}
Also used : AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) EntryWrappingInterceptor(org.infinispan.interceptors.impl.EntryWrappingInterceptor)

Example 18 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain 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)

Example 19 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class AddStoreTest method checkPassivation.

private void checkPassivation(Cache<?, ?> cache) {
    AsyncInterceptorChain asyncInterceptorChain = cache.getAdvancedCache().getAdvancedCache().getAsyncInterceptorChain();
    assertNotNull(asyncInterceptorChain.findInterceptorWithClass(PassivationWriterInterceptor.class));
    if (cache.getAdvancedCache().getCacheConfiguration().clustering().cacheMode().isClustered()) {
        assertNotNull(asyncInterceptorChain.findInterceptorWithClass(PassivationClusteredCacheLoaderInterceptor.class));
    } else {
        assertNotNull(asyncInterceptorChain.findInterceptorWithClass(PassivationCacheLoaderInterceptor.class));
    }
}
Also used : PassivationWriterInterceptor(org.infinispan.interceptors.impl.PassivationWriterInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) PassivationClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor) PassivationCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationCacheLoaderInterceptor)

Example 20 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class AddStoreTest method checkStore.

private void checkStore(Cache<?, ?> cache) {
    AsyncInterceptorChain asyncInterceptorChain = cache.getAdvancedCache().getAdvancedCache().getAsyncInterceptorChain();
    assertNotNull(asyncInterceptorChain.findInterceptorWithClass(CacheLoaderInterceptor.class));
    assertNotNull(asyncInterceptorChain.findInterceptorWithClass(CacheWriterInterceptor.class));
}
Also used : CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) ClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.ClusteredCacheLoaderInterceptor) PassivationCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationCacheLoaderInterceptor) PassivationClusteredCacheLoaderInterceptor(org.infinispan.interceptors.impl.PassivationClusteredCacheLoaderInterceptor)

Aggregations

AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)53 InvocationContext (org.infinispan.context.InvocationContext)15 CompletableFuture (java.util.concurrent.CompletableFuture)13 VisitableCommand (org.infinispan.commands.VisitableCommand)9 AsyncInterceptor (org.infinispan.interceptors.AsyncInterceptor)9 Future (java.util.concurrent.Future)8 SingleKeyNonTxInvocationContext (org.infinispan.context.impl.SingleKeyNonTxInvocationContext)8 BaseAsyncInterceptor (org.infinispan.interceptors.BaseAsyncInterceptor)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 TestException (org.infinispan.test.TestException)7 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)7 SECONDS (java.util.concurrent.TimeUnit.SECONDS)6 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 LockControlCommand (org.infinispan.commands.control.LockControlCommand)5 Test (org.testng.annotations.Test)5 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)4 EntryWrappingInterceptor (org.infinispan.interceptors.impl.EntryWrappingInterceptor)4 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)4 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)4