Search in sources :

Example 1 with InvocationContextFactory

use of org.infinispan.context.InvocationContextFactory in project infinispan by infinispan.

the class BackupWriteCommand method invokeAsync.

@Override
public final CompletionStage<?> invokeAsync(ComponentRegistry componentRegistry) {
    WriteCommand command = createWriteCommand();
    if (command == null) {
        // No-op command
        return CompletableFutures.completedNull();
    }
    command.init(componentRegistry);
    command.setFlagsBitSet(flags);
    // Mark the command as a backup write and skip locking
    command.addFlags(FlagBitSets.SKIP_LOCKING | FlagBitSets.BACKUP_WRITE);
    command.setValueMatcher(MATCH_ALWAYS);
    command.setTopologyId(topologyId);
    InvocationContextFactory invocationContextFactory = componentRegistry.getInvocationContextFactory().running();
    InvocationContext invocationContext = invocationContextFactory.createRemoteInvocationContextForCommand(command, getOrigin());
    AsyncInterceptorChain interceptorChain = componentRegistry.getInterceptorChain().running();
    return interceptorChain.invokeAsync(invocationContext, command);
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) InvocationContext(org.infinispan.context.InvocationContext) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Example 2 with InvocationContextFactory

use of org.infinispan.context.InvocationContextFactory in project infinispan by infinispan.

the class ClusteredGetCommand method invokeAsync.

/**
 * Invokes a logical "get(key)" on a remote cache and returns results.
 * @return
 */
@Override
public CompletionStage<?> invokeAsync(ComponentRegistry componentRegistry) throws Throwable {
    // make sure the get command doesn't perform a remote call
    // as our caller is already calling the ClusteredGetCommand on all the relevant nodes
    // CACHE_MODE_LOCAL is not used as it can be used when we want to ignore the ownership with respect to reads
    long flagBitSet = EnumUtil.bitSetOf(Flag.SKIP_REMOTE_LOOKUP);
    int segmentToUse;
    if (segment != null) {
        segmentToUse = segment;
    } else {
        segmentToUse = componentRegistry.getComponent(KeyPartitioner.class).getSegment(key);
    }
    // This code and the Flag can be removed when https://issues.redhat.com/browse/ISPN-12332 is complete
    if (isWrite) {
        TransactionConfiguration transactionConfiguration = componentRegistry.getConfiguration().transaction();
        if (transactionConfiguration.transactionMode() == TransactionMode.TRANSACTIONAL) {
            if (transactionConfiguration.lockingMode() == LockingMode.PESSIMISTIC) {
                flagBitSet = EnumUtil.mergeBitSets(flagBitSet, FlagBitSets.ALREADY_HAS_LOCK);
            }
        }
    }
    GetCacheEntryCommand command = componentRegistry.getCommandsFactory().buildGetCacheEntryCommand(key, segmentToUse, EnumUtil.mergeBitSets(flagBitSet, getFlagsBitSet()));
    command.setTopologyId(topologyId);
    InvocationContextFactory icf = componentRegistry.getInvocationContextFactory().running();
    InvocationContext invocationContext = icf.createRemoteInvocationContextForCommand(command, getOrigin());
    AsyncInterceptorChain invoker = componentRegistry.getInterceptorChain().running();
    return invoker.invokeAsync(invocationContext, command).thenApply(rv -> {
        if (log.isTraceEnabled())
            log.tracef("Return value for key=%s is %s", key, rv);
        // this might happen if the value was fetched from a cache loader
        if (rv instanceof MVCCEntry) {
            MVCCEntry<?, ?> mvccEntry = (MVCCEntry<?, ?>) rv;
            InternalCacheValue<?> icv = componentRegistry.getInternalEntryFactory().wired().createValue(mvccEntry);
            icv.setInternalMetadata(mvccEntry.getInternalMetadata());
            return icv;
        } else if (rv instanceof InternalCacheEntry) {
            InternalCacheEntry<?, ?> internalCacheEntry = (InternalCacheEntry<?, ?>) rv;
            return internalCacheEntry.toInternalCacheValue();
        } else {
            // null or Response
            return rv;
        }
    });
}
Also used : TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvocationContext(org.infinispan.context.InvocationContext) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Example 3 with InvocationContextFactory

use of org.infinispan.context.InvocationContextFactory in project infinispan by infinispan.

the class PrepareCommand method createContext.

@Override
public RemoteTxInvocationContext createContext(ComponentRegistry componentRegistry) {
    RecoveryManager recoveryManager = componentRegistry.getRecoveryManager().running();
    if (recoveryManager != null && recoveryManager.isTransactionPrepared(globalTx)) {
        log.tracef("The transaction %s is already prepared. Skipping prepare call.", globalTx);
        return null;
    }
    // 1. first create a remote transaction (or get the existing one)
    TransactionTable txTable = componentRegistry.getTransactionTableRef().running();
    RemoteTransaction remoteTransaction = txTable.getOrCreateRemoteTransaction(globalTx, modifications);
    // LockControlCommand with null modifications.
    if (hasModifications()) {
        remoteTransaction.setModifications(Arrays.asList(modifications));
    }
    // 2. then set it on the invocation context
    InvocationContextFactory icf = componentRegistry.getInvocationContextFactory().running();
    return icf.createRemoteTxInvocationContext(remoteTransaction, getOrigin());
}
Also used : RecoveryManager(org.infinispan.transaction.xa.recovery.RecoveryManager) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Example 4 with InvocationContextFactory

use of org.infinispan.context.InvocationContextFactory in project infinispan by infinispan.

the class AbstractTransactionBoundaryCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry registry) throws Throwable {
    globalTx.setRemote(true);
    TransactionTable txTable = registry.getTransactionTableRef().running();
    RemoteTransaction transaction = txTable.getRemoteTransaction(globalTx);
    if (transaction == null) {
        if (log.isTraceEnabled())
            log.tracef("Did not find a RemoteTransaction for %s", globalTx);
        return CompletableFuture.completedFuture(invalidRemoteTxReturnValue(txTable));
    }
    visitRemoteTransaction(transaction);
    InvocationContextFactory icf = registry.getInvocationContextFactory().running();
    RemoteTxInvocationContext ctx = icf.createRemoteTxInvocationContext(transaction, getOrigin());
    if (log.isTraceEnabled())
        log.tracef("About to execute tx command %s", this);
    return registry.getInterceptorChain().running().invokeAsync(ctx, this);
}
Also used : RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) TransactionTable(org.infinispan.transaction.impl.TransactionTable) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Example 5 with InvocationContextFactory

use of org.infinispan.context.InvocationContextFactory in project infinispan by infinispan.

the class SingleRpcCommand method invokeAsync.

@Override
public CompletionStage<?> invokeAsync(ComponentRegistry componentRegistry) throws Throwable {
    command.init(componentRegistry);
    InvocationContextFactory icf = componentRegistry.getInvocationContextFactory().running();
    InvocationContext ctx = icf.createRemoteInvocationContextForCommand(command, getOrigin());
    if (command instanceof RemoteLockCommand) {
        ctx.setLockOwner(((RemoteLockCommand) command).getKeyLockOwner());
    }
    if (log.isTraceEnabled())
        log.tracef("Invoking command %s, with originLocal flag set to %b", command, ctx.isOriginLocal());
    return componentRegistry.getInterceptorChain().running().invokeAsync(ctx, command);
}
Also used : RemoteLockCommand(org.infinispan.util.concurrent.locks.RemoteLockCommand) InvocationContext(org.infinispan.context.InvocationContext) InvocationContextFactory(org.infinispan.context.InvocationContextFactory)

Aggregations

InvocationContextFactory (org.infinispan.context.InvocationContextFactory)8 InvocationContext (org.infinispan.context.InvocationContext)4 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)4 TransactionTable (org.infinispan.transaction.impl.TransactionTable)3 CommandsFactory (org.infinispan.commands.CommandsFactory)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)1 ExecutorService (java.util.concurrent.ExecutorService)1