Search in sources :

Example 1 with RestartingMemberIterator

use of com.hazelcast.internal.util.iterator.RestartingMemberIterator 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)

Example 2 with RestartingMemberIterator

use of com.hazelcast.internal.util.iterator.RestartingMemberIterator in project hazelcast by hazelcast.

the class ChainingFutureTest method setup.

@Before
public void setup() {
    Set<Member> members = new HashSet<>();
    members.add(mock(Member.class));
    when(clusterService.getMembers()).thenReturn(members);
    repairingIterator = new RestartingMemberIterator(clusterService, 100);
}
Also used : RestartingMemberIterator(com.hazelcast.internal.util.iterator.RestartingMemberIterator) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

RestartingMemberIterator (com.hazelcast.internal.util.iterator.RestartingMemberIterator)2 Member (com.hazelcast.cluster.Member)1 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 ChainingFuture (com.hazelcast.internal.util.futures.ChainingFuture)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1