use of org.infinispan.commands.read.GetCacheEntryCommand 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.commands.read.GetCacheEntryCommand in project infinispan by infinispan.
the class CacheImpl method getCacheEntry.
final CacheEntry<K, V> getCacheEntry(Object key, long explicitFlags, InvocationContext ctx) {
assertKeyNotNull(key);
GetCacheEntryCommand command = commandsFactory.buildGetCacheEntryCommand(key, keyPartitioner.getSegment(key), explicitFlags);
return invocationHelper.invoke(ctx, command);
}
use of org.infinispan.commands.read.GetCacheEntryCommand in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitGetCacheEntryCommand.
public void testVisitGetCacheEntryCommand() throws Throwable {
GetCacheEntryCommand command = new GetCacheEntryCommand(KEY, 0, 0);
InvocationStage stage = makeStage(interceptor.visitGetCacheEntryCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocation(null);
assertNull(stage.get());
assertEquals(1, interceptor.getAverageReadTime());
}
use of org.infinispan.commands.read.GetCacheEntryCommand in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitGetCacheEntryCommandException.
public void testVisitGetCacheEntryCommandException() throws Throwable {
GetCacheEntryCommand command = new GetCacheEntryCommand(KEY, 0, 0);
InvocationStage stage = makeStage(interceptor.visitGetCacheEntryCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocationExceptionally(new TestException());
expectInvocationException(stage);
assertEquals(1, interceptor.getAverageReadTime());
}
use of org.infinispan.commands.read.GetCacheEntryCommand in project infinispan by infinispan.
the class CacheImpl method getCacheEntryAsync.
final CompletableFuture<CacheEntry<K, V>> getCacheEntryAsync(Object key, long explicitFlags, InvocationContext ctx) {
assertKeyNotNull(key);
GetCacheEntryCommand command = commandsFactory.buildGetCacheEntryCommand(key, keyPartitioner.getSegment(key), explicitFlags);
return invocationHelper.invokeAsync(ctx, command);
}
Aggregations