Search in sources :

Example 1 with ChainingFuture

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);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) ChainingFuture(com.hazelcast.internal.util.futures.ChainingFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RestartingMemberIterator(com.hazelcast.internal.util.iterator.RestartingMemberIterator)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)1 ChainingFuture (com.hazelcast.internal.util.futures.ChainingFuture)1 RestartingMemberIterator (com.hazelcast.internal.util.iterator.RestartingMemberIterator)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1