use of org.infinispan.interceptors.InvocationFinallyAction in project infinispan by infinispan.
the class NonTxDistributionInterceptor method createLocalInvocationHandler.
private <C extends WriteCommand, F extends CountDownCompletableFuture, Item> InvocationFinallyAction<C> createLocalInvocationHandler(F allFuture, IntSet segments, WriteManyCommandHelper<C, ?, Item> helper, BiConsumer<F, Object> returnValueConsumer, LocalizedCacheTopology topology) {
return (rCtx, rCommand, rv, throwable) -> {
if (throwable != null) {
allFuture.completeExceptionally(throwable);
} else
try {
returnValueConsumer.accept(allFuture, rv);
Map<Address, IntSet> backupOwners = backupOwnersOfSegments(topology, segments);
for (Entry<Address, IntSet> backup : backupOwners.entrySet()) {
// rCommand is the original command
C backupCopy = helper.copyForBackup(rCommand, topology, backup.getKey(), backup.getValue());
backupCopy.setTopologyId(rCommand.getTopologyId());
if (helper.getItems(backupCopy).isEmpty())
continue;
Address backupOwner = backup.getKey();
if (isSynchronous(backupCopy)) {
allFuture.increment();
rpcManager.invokeCommand(backupOwner, backupCopy, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).whenComplete((response, remoteThrowable) -> {
if (remoteThrowable != null) {
allFuture.completeExceptionally(remoteThrowable);
} else {
allFuture.countDown();
}
});
} else {
rpcManager.sendTo(backupOwner, backupCopy, DeliverOrder.PER_SENDER);
}
}
allFuture.countDown();
} catch (Throwable t) {
allFuture.completeExceptionally(t);
}
};
}
Aggregations