use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.
the class ScatteredDistributionInterceptor method visitClearCommand.
@Override
public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable {
// local mode clear will have unpredictable results
svm.clearInvalidations();
if (ctx.isOriginLocal() && !isLocalModeForced(command)) {
if (isSynchronous(command)) {
RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
return makeStage(asyncInvokeNext(ctx, command, rpcManager.invokeCommandOnAll(command, collector, rpcOptions))).thenApply(ctx, command, clearHandler);
} else {
rpcManager.sendToAll(command, DeliverOrder.PER_SENDER);
return invokeNextThenApply(ctx, command, clearHandler);
}
} else {
return invokeNextThenApply(ctx, command, clearHandler);
}
}
use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.
the class TxDistributionInterceptor method prepareOnAffectedNodes.
protected CompletionStage<Object> prepareOnAffectedNodes(TxInvocationContext<?> ctx, PrepareCommand command, Collection<Address> recipients) {
try {
CompletionStage<Map<Address, Response>> remoteInvocation;
if (recipients != null) {
MapResponseCollector collector = MapResponseCollector.ignoreLeavers(recipients.size());
remoteInvocation = rpcManager.invokeCommand(recipients, command, collector, rpcManager.getSyncRpcOptions());
} else {
MapResponseCollector collector = MapResponseCollector.ignoreLeavers(rpcManager.getMembers().size());
remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
}
return remoteInvocation.handle((responses, t) -> {
transactionRemotelyPrepared(ctx);
CompletableFutures.rethrowExceptionIfPresent(t);
PrepareResponse prepareResponse = new PrepareResponse();
checkTxCommandResponses(responses, command, (LocalTxInvocationContext) ctx, recipients, prepareResponse);
for (Response r : responses.values()) mergePrepareResponses(r, prepareResponse);
return prepareResponse;
});
} catch (Throwable t) {
transactionRemotelyPrepared(ctx);
throw t;
}
}
use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.
the class AnchoredDistributionInterceptor method primaryReturnHandler.
@Override
protected Object primaryReturnHandler(InvocationContext ctx, AbstractDataWriteCommand command, Object localResult) {
if (!command.isSuccessful()) {
if (log.isTraceEnabled())
log.tracef("Skipping the replication of the conditional command as it did not succeed on primary owner (%s).", command);
return localResult;
}
LocalizedCacheTopology cacheTopology = checkTopologyId(command);
DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(command.getSegment());
Collection<Address> owners = distributionInfo.writeOwners();
if (owners.size() == 1) {
// There are no backups, skip the replication part.
return localResult;
}
// Match always on the backups, but save the original matcher for retries
ValueMatcher originalMatcher = command.getValueMatcher();
command.setValueMatcher(ValueMatcher.MATCH_ALWAYS);
CommandCopier commandCopier = new CommandCopier(ctx, command);
// Ignore the previous value on the backup owners
assert isSynchronous(command);
MapResponseCollector collector = MapResponseCollector.ignoreLeavers(isReplicated, owners.size());
RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
CompletionStage<Map<Address, Response>> remoteInvocation = rpcManager.invokeCommands(distributionInfo.writeBackups(), commandCopier, collector, rpcOptions);
return asyncValue(remoteInvocation.handle((responses, t) -> {
// Switch to the retry policy, in case the primary owner changed
// and the write already succeeded on the new primary
command.setValueMatcher(originalMatcher.matcherForRetry());
CompletableFutures.rethrowExceptionIfPresent(t instanceof RemoteException ? t.getCause() : t);
return localResult;
}));
}
use of org.infinispan.remoting.transport.impl.MapResponseCollector 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.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.
the class MockTransport method invokeRemotelyAsync.
@Override
public CompletableFuture<Map<Address, Response>> invokeRemotelyAsync(Collection<Address> recipients, ReplicableCommand rpcCommand, ResponseMode mode, long timeout, ResponseFilter responseFilter, DeliverOrder deliverOrder, boolean anycast) {
Collection<Address> targets = recipients != null ? recipients : members;
MapResponseCollector collector = mode.isSynchronous() ? MapResponseCollector.ignoreLeavers(shouldIgnoreLeavers(mode), targets.size()) : null;
return blockRequest(recipients, rpcCommand, collector);
}
Aggregations