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);
}
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;
}
});
}
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());
}
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);
}
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);
}
Aggregations