Search in sources :

Example 1 with GetCacheEntryCommand

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;
        }
    });
}
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 2 with GetCacheEntryCommand

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);
}
Also used : GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand)

Example 3 with GetCacheEntryCommand

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());
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand)

Example 4 with GetCacheEntryCommand

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());
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) TestException(org.infinispan.test.TestException) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand)

Example 5 with GetCacheEntryCommand

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);
}
Also used : GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand)

Aggregations

GetCacheEntryCommand (org.infinispan.commands.read.GetCacheEntryCommand)5 InvocationStage (org.infinispan.interceptors.InvocationStage)2 TransactionConfiguration (org.infinispan.configuration.cache.TransactionConfiguration)1 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)1 MVCCEntry (org.infinispan.container.entries.MVCCEntry)1 InvocationContext (org.infinispan.context.InvocationContext)1 InvocationContextFactory (org.infinispan.context.InvocationContextFactory)1 AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)1 TestException (org.infinispan.test.TestException)1