Search in sources :

Example 21 with AsyncInterceptorChain

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

the class AddStoreTest method checkClustered.

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

Example 22 with AsyncInterceptorChain

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

the class PersistenceManagerImpl method disableStore.

@Override
public CompletionStage<Void> disableStore(String storeType) {
    if (!enabled) {
        return CompletableFutures.completedNull();
    }
    boolean stillHasAStore = false;
    AggregateCompletionStage<Void> aggregateCompletionStage = CompletionStages.aggregateCompletionStage();
    long stamp = lock.writeLock();
    try {
        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();
    } finally {
        lock.unlockWrite(stamp);
    }
    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();
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Scopes(org.infinispan.factories.scopes.Scopes) AdvancedCache(org.infinispan.AdvancedCache) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Transaction(javax.transaction.Transaction) MethodHandles(java.lang.invoke.MethodHandles) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) ComposedSegmentedLoadWriteStore(org.infinispan.persistence.support.ComposedSegmentedLoadWriteStore) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) EnumUtil(org.infinispan.commons.util.EnumUtil) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) Start(org.infinispan.factories.annotations.Start) ArrayList(java.util.ArrayList) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SystemException(javax.transaction.SystemException) StampedLock(java.util.concurrent.locks.StampedLock) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Lifecycle(org.infinispan.commons.api.Lifecycle) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) CommandsFactory(org.infinispan.commands.CommandsFactory) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) GuardedBy(net.jcip.annotations.GuardedBy) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) PersistenceException(org.infinispan.persistence.spi.PersistenceException) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) HashSet(java.util.HashSet) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) BiPredicate(java.util.function.BiPredicate) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Util(org.infinispan.commons.util.Util) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) NotSupportedException(javax.transaction.NotSupportedException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TransactionManager(javax.transaction.TransactionManager) TimeService(org.infinispan.commons.time.TimeService) InputStream(java.io.InputStream) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor)

Example 23 with AsyncInterceptorChain

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

the class PrepareCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
    markTransactionAsRemote(true);
    RemoteTxInvocationContext ctx = createContext(registry);
    if (ctx == null) {
        return CompletableFutures.completedNull();
    }
    if (log.isTraceEnabled())
        log.tracef("Invoking remotely originated prepare: %s with invocation context: %s", this, ctx);
    CacheNotifier notifier = registry.getCacheNotifier().running();
    CompletionStage<Void> stage = notifier.notifyTransactionRegistered(ctx.getGlobalTransaction(), false);
    AsyncInterceptorChain invoker = registry.getInterceptorChain().running();
    for (VisitableCommand nested : getModifications()) nested.init(registry);
    if (CompletionStages.isCompletedSuccessfully(stage)) {
        return invoker.invokeAsync(ctx, this);
    } else {
        return stage.thenCompose(v -> invoker.invokeAsync(ctx, this));
    }
}
Also used : VisitableCommand(org.infinispan.commands.VisitableCommand) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain)

Example 24 with AsyncInterceptorChain

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

the class BaseDistFunctionalTest method removeAllBlockingInterceptorsFromCache.

protected static void removeAllBlockingInterceptorsFromCache(Cache<?, ?> cache) {
    AsyncInterceptorChain chain = TestingUtil.extractInterceptorChain(cache);
    BlockingInterceptor<?> blockingInterceptor = chain.findInterceptorExtending(BlockingInterceptor.class);
    while (blockingInterceptor != null) {
        blockingInterceptor.suspend(true);
        chain.removeInterceptor(blockingInterceptor.getClass());
        blockingInterceptor = chain.findInterceptorExtending(BlockingInterceptor.class);
    }
}
Also used : AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain)

Example 25 with AsyncInterceptorChain

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

the class AsyncInterceptorChainInvocationTest method testCompletedStage.

public void testCompletedStage() {
    AsyncInterceptorChain chain = newInterceptorChain(new BaseAsyncInterceptor() {

        @Override
        public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
            return "v1";
        }
    }, new BaseAsyncInterceptor() {

        @Override
        public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
            return "v2";
        }
    });
    InvocationContext context = newInvocationContext();
    Object returnValue = chain.invoke(context, testCommand);
    assertEquals("v1", returnValue);
}
Also used : VisitableCommand(org.infinispan.commands.VisitableCommand) BaseAsyncInterceptor(org.infinispan.interceptors.BaseAsyncInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) InvocationContext(org.infinispan.context.InvocationContext)

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