Search in sources :

Example 1 with SingleRpcCommand

use of org.infinispan.commands.remote.SingleRpcCommand in project infinispan by infinispan.

the class DistAsyncFuncTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    super.createCacheManagers();
    r1 = new ReplListener(c1, true, true);
    r2 = new ReplListener(c2, true, true);
    r3 = new ReplListener(c3, true, true);
    r4 = new ReplListener(c4, true, true);
    r = new ReplListener[] { r1, r2, r3, r4 };
    listenerLookup = new HashMap<>();
    for (ReplListener rl : r) listenerLookup.put(rl.getCache().getCacheManager().getAddress(), rl);
    for (Cache c : caches) {
        TestingUtil.wrapComponent(c, RpcManager.class, original -> new AbstractDelegatingRpcManager(original) {

            @Override
            protected <T> CompletionStage<T> performRequest(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, Function<ResponseCollector<T>, CompletionStage<T>> invoker, RpcOptions rpcOptions) {
                if (command instanceof SingleRpcCommand) {
                    command = ((SingleRpcCommand) command).getCommand();
                }
                if (command instanceof InvalidateL1Command) {
                    InvalidateL1Command invalidateL1Command = (InvalidateL1Command) command;
                    log.tracef("Sending invalidation %s to %s", command, targets);
                    Collection<Address> realTargets = targets != null ? targets : cacheAddresses;
                    for (Address target : realTargets) {
                        expectedL1Invalidations.computeIfAbsent(target, ignored -> Collections.synchronizedList(new ArrayList<>())).add(invalidateL1Command);
                    }
                }
                return super.performRequest(targets, command, collector, invoker, rpcOptions);
            }
        });
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) ArrayList(java.util.ArrayList) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) AbstractDelegatingRpcManager(org.infinispan.util.AbstractDelegatingRpcManager) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Collection(java.util.Collection) ReplListener(org.infinispan.test.ReplListener) CompletionStage(java.util.concurrent.CompletionStage) Cache(org.infinispan.Cache)

Example 2 with SingleRpcCommand

use of org.infinispan.commands.remote.SingleRpcCommand in project infinispan by infinispan.

the class ControlledRpcManager method performRequest.

@Override
protected <T> CompletionStage<T> performRequest(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, Function<ResponseCollector<T>, CompletionStage<T>> invoker, RpcOptions rpcOptions) {
    if (stopped || commandExcluded(command)) {
        log.tracef("Not blocking excluded command %s", command);
        return invoker.apply(collector);
    }
    log.debugf("Intercepted command to %s: %s", targets, command);
    // Ignore the SingleRpcCommand wrapper
    if (command instanceof SingleRpcCommand) {
        command = ((SingleRpcCommand) command).getCommand();
    }
    Address excluded = realOne.getAddress();
    ControlledRequest<T> controlledRequest = new ControlledRequest<>(command, targets, collector, invoker, nonBlockingExecutor, excluded);
    try {
        CompletableFuture<ControlledRequest<?>> waiter = waiters.poll(TIMEOUT_SECONDS, SECONDS);
        if (waiter == null) {
            TimeoutException t = new TimeoutException("Found no waiters for command " + command);
            addGlobalError(t);
            throw t;
        }
        waiter.complete(controlledRequest);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new TestException(e);
    } catch (Exception e) {
        throw new TestException(e);
    }
    if (collector != null) {
        ScheduledFuture<?> cancelTask = timeoutExecutor.schedule(() -> {
            TimeoutException e = new TimeoutException("Timed out waiting for test to unblock command " + controlledRequest.getCommand());
            addGlobalError(e);
            controlledRequest.fail(e);
        }, TIMEOUT_SECONDS * 2, SECONDS);
        controlledRequest.resultFuture.whenComplete((ignored, throwable) -> cancelTask.cancel(false));
    }
    // resultFuture is completed from a test thread, and we don't want to run the interceptor callbacks there
    return controlledRequest.resultFuture.whenCompleteAsync((r, t) -> {
    }, nonBlockingExecutor);
}
Also used : Address(org.infinispan.remoting.transport.Address) TestException(org.infinispan.test.TestException) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) TimeoutException(org.infinispan.util.concurrent.TimeoutException) TestException(org.infinispan.test.TestException) TimeoutException(org.infinispan.util.concurrent.TimeoutException)

Example 3 with SingleRpcCommand

use of org.infinispan.commands.remote.SingleRpcCommand in project infinispan by infinispan.

the class NonTxPerCacheInboundInvocationHandler method handle.

@Override
public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) {
    try {
        final int commandTopologyId = extractCommandTopologyId(command);
        final boolean onExecutorService = executeOnExecutorService(order, command);
        final boolean sync = order.preserveOrder();
        final BlockingRunnable runnable;
        boolean waitForTransactionalData = true;
        switch(command.getCommandId()) {
            case SingleRpcCommand.COMMAND_ID:
                runnable = onExecutorService ? createReadyActionRunnable(command, reply, commandTopologyId, sync, createReadyAction(commandTopologyId, (SingleRpcCommand) command)) : createDefaultRunnable(command, reply, commandTopologyId, TopologyMode.WAIT_TX_DATA, sync);
                break;
            case ConflictResolutionStartCommand.COMMAND_ID:
            case ScatteredStateConfirmRevokedCommand.COMMAND_ID:
            case ScatteredStateGetKeysCommand.COMMAND_ID:
            case StateTransferCancelCommand.COMMAND_ID:
            case StateTransferGetListenersCommand.COMMAND_ID:
            case StateTransferGetTransactionsCommand.COMMAND_ID:
            case StateTransferStartCommand.COMMAND_ID:
                waitForTransactionalData = false;
            default:
                runnable = createDefaultRunnable(command, reply, commandTopologyId, waitForTransactionalData, onExecutorService, sync);
                break;
        }
        handleRunnable(runnable, onExecutorService);
    } catch (Throwable throwable) {
        reply.reply(exceptionHandlingCommand(command, throwable));
    }
}
Also used : BlockingRunnable(org.infinispan.util.concurrent.BlockingRunnable) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand)

Example 4 with SingleRpcCommand

use of org.infinispan.commands.remote.SingleRpcCommand in project infinispan by infinispan.

the class L1ManagerImpl method flushCache.

@Override
public CompletableFuture<?> flushCache(Collection<Object> keys, Address origin, boolean assumeOriginKeptEntryInL1) {
    final Collection<Address> invalidationAddresses = buildInvalidationAddressList(keys, origin, assumeOriginKeptEntryInL1);
    int nodes = invalidationAddresses.size();
    if (nodes > 0) {
        InvalidateCommand ic = commandsFactory.buildInvalidateFromL1Command(origin, EnumUtil.EMPTY_BIT_SET, keys);
        final SingleRpcCommand rpcCommand = commandsFactory.buildSingleRpcCommand(ic);
        // No need to invalidate at all if there is no one to invalidate!
        boolean multicast = isUseMulticast(nodes);
        if (log.isTraceEnabled())
            log.tracef("Invalidating keys %s on nodes %s. Use multicast? %s", keys, invalidationAddresses, multicast);
        // L1 invalidations can ignore a member leaving while sending invalidation
        MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
        CompletionStage<Map<Address, Response>> request;
        if (multicast) {
            request = rpcManager.invokeCommandOnAll(rpcCommand, collector, rpcManager.getSyncRpcOptions());
        } else {
            request = rpcManager.invokeCommand(invalidationAddresses, rpcCommand, collector, rpcManager.getSyncRpcOptions());
        }
        return request.toCompletableFuture();
    } else {
        if (log.isTraceEnabled())
            log.tracef("No L1 caches to invalidate for keys %s", keys);
        return null;
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Example 5 with SingleRpcCommand

use of org.infinispan.commands.remote.SingleRpcCommand in project infinispan by infinispan.

the class AsynchronousInvocationTest method testSingleRpcCommand.

public void testSingleRpcCommand() throws Throwable {
    SingleRpcCommand blockingSingleRpcCommand = mockSingleRpcCommand(true);
    assertDispatchForCommand(blockingSingleRpcCommand, true);
    SingleRpcCommand nonBlockingSingleRpcCommand = mockSingleRpcCommand(false);
    assertDispatchForCommand(nonBlockingSingleRpcCommand, false);
}
Also used : SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand)

Aggregations

SingleRpcCommand (org.infinispan.commands.remote.SingleRpcCommand)6 Address (org.infinispan.remoting.transport.Address)3 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Cache (org.infinispan.Cache)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 VisitableCommand (org.infinispan.commands.VisitableCommand)1 InvalidateCommand (org.infinispan.commands.write.InvalidateCommand)1 InvalidateL1Command (org.infinispan.commands.write.InvalidateL1Command)1 RpcOptions (org.infinispan.remoting.rpc.RpcOptions)1 ResponseCollector (org.infinispan.remoting.transport.ResponseCollector)1 MapResponseCollector (org.infinispan.remoting.transport.impl.MapResponseCollector)1 ReplListener (org.infinispan.test.ReplListener)1 TestException (org.infinispan.test.TestException)1 AbstractDelegatingRpcManager (org.infinispan.util.AbstractDelegatingRpcManager)1 BlockingRunnable (org.infinispan.util.concurrent.BlockingRunnable)1