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