use of org.infinispan.commands.remote.ClusteredGetAllCommand in project infinispan by infinispan.
the class ScatteredDistributionInterceptor method visitGetAllCommand.
@Override
public Object visitGetAllCommand(InvocationContext ctx, GetAllCommand command) throws Throwable {
LocalizedCacheTopology cacheTopology = checkTopology(command);
if (command.hasAnyFlag(FlagBitSets.CACHE_MODE_LOCAL | FlagBitSets.SKIP_REMOTE_LOOKUP | FlagBitSets.SKIP_OWNERSHIP_CHECK)) {
return invokeNext(ctx, command);
}
if (ctx.isOriginLocal()) {
Map<Address, List<Object>> remoteKeys = new HashMap<>();
for (Object key : command.getKeys()) {
if (ctx.lookupEntry(key) != null) {
continue;
}
DistributionInfo info = cacheTopology.getDistribution(key);
if (info.primary() == null) {
throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
} else if (!info.isPrimary()) {
remoteKeys.computeIfAbsent(info.primary(), k -> new ArrayList<>()).add(key);
}
}
if (remoteKeys.isEmpty()) {
return invokeNext(ctx, command);
}
ClusteredGetAllFuture sync = new ClusteredGetAllFuture(remoteKeys.size());
for (Map.Entry<Address, List<Object>> remote : remoteKeys.entrySet()) {
List<Object> keys = remote.getValue();
ClusteredGetAllCommand clusteredGetAllCommand = cf.buildClusteredGetAllCommand(keys, command.getFlagsBitSet(), null);
clusteredGetAllCommand.setTopologyId(command.getTopologyId());
SingletonMapResponseCollector collector = SingletonMapResponseCollector.ignoreLeavers();
CompletionStage<Map<Address, Response>> rpcFuture = rpcManager.invokeCommand(remote.getKey(), clusteredGetAllCommand, collector, rpcManager.getSyncRpcOptions());
rpcFuture.whenComplete(((responseMap, throwable) -> handleGetAllResponse(responseMap, throwable, ctx, keys, sync)));
}
return asyncInvokeNext(ctx, command, sync);
} else {
// remote
for (Object key : command.getKeys()) {
if (ctx.lookupEntry(key) == null) {
return UnsureResponse.INSTANCE;
}
}
return invokeNext(ctx, command);
}
}
Aggregations