use of org.infinispan.expiration.TouchMode in project infinispan by infinispan.
the class ClusteringInterceptor method visitTouchCommand.
@Override
public Object visitTouchCommand(InvocationContext ctx, TouchCommand command) throws Throwable {
if (command.hasAnyFlag(FlagBitSets.CACHE_MODE_LOCAL | FlagBitSets.SKIP_REMOTE_LOOKUP)) {
return invokeNext(ctx, command);
}
LocalizedCacheTopology cacheTopology = checkTopologyId(command);
DistributionInfo info = cacheTopology.getSegmentDistribution(command.getSegment());
// Scattered any node could be a backup, so we have to touch all members
List<Address> owners = isScattered ? cacheTopology.getActualMembers() : info.readOwners();
if (touchMode == TouchMode.ASYNC) {
if (ctx.isOriginLocal()) {
// Send to all the owners
rpcManager.sendToMany(owners, command, DeliverOrder.NONE);
}
return invokeNext(ctx, command);
}
if (info.isPrimary()) {
AbstractTouchResponseCollector collector = isScattered ? ScatteredTouchResponseCollector.INSTANCE : TouchResponseCollector.INSTANCE;
CompletionStage<Boolean> remoteInvocation = rpcManager.invokeCommand(owners, command, collector, rpcManager.getSyncRpcOptions());
return invokeNextThenApply(ctx, command, (rCtx, rCommand, rValue) -> {
Boolean touchedLocally = (Boolean) rValue;
if (touchedLocally) {
return asyncValue(remoteInvocation);
}
// If primary can't touch - it doesn't matter about others
return Boolean.FALSE;
});
} else if (ctx.isOriginLocal()) {
// Send to the primary owner
CompletionStage<ValidResponse> remoteInvocation = rpcManager.invokeCommand(info.primary(), command, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
return asyncValue(remoteInvocation).thenApply(ctx, command, (rCtx, rCommand, rResponse) -> ((ValidResponse) rResponse).getResponseValue());
}
return invokeNext(ctx, command);
}
Aggregations