use of com.hazelcast.internal.util.futures.ChainingFuture in project hazelcast by hazelcast.
the class InvocationUtil method invokeOnStableClusterSerial.
/**
* Invoke operation on all cluster members.
*
* The invocation is serial: It iterates over all members starting from the oldest member to the youngest one.
* If there is a cluster membership change while invoking then it will restart invocations on all members. This
* implies the operation should be idempotent.
*
* If there is an exception - other than {@link com.hazelcast.core.MemberLeftException} or
* {@link com.hazelcast.spi.exception.TargetNotMemberException} while invoking then the iteration
* is interrupted and the exception is propagated to the caller.
*/
public static <V> InternalCompletableFuture<V> invokeOnStableClusterSerial(NodeEngine nodeEngine, Supplier<? extends Operation> operationSupplier, int maxRetries) {
ClusterService clusterService = nodeEngine.getClusterService();
if (!clusterService.isJoined()) {
return newCompletedFuture(null);
}
RestartingMemberIterator memberIterator = new RestartingMemberIterator(clusterService, maxRetries);
// we are going to iterate over all members and invoke an operation on each of them
InvokeOnMemberFunction invokeOnMemberFunction = new InvokeOnMemberFunction(operationSupplier, nodeEngine, memberIterator);
Iterator<InternalCompletableFuture<Object>> invocationIterator = map(memberIterator, invokeOnMemberFunction);
// the future itself completes only when the last invocation completes (or if there is an error)
return new ChainingFuture(invocationIterator, memberIterator);
}
Aggregations