Search in sources :

Example 1 with RemoteMapReduceException

use of com.hazelcast.mapreduce.RemoteMapReduceException in project hazelcast by hazelcast.

the class MapReduceUtil method executeOperation.

public static <V> List<V> executeOperation(Collection<Member> members, OperationFactory operationFactory, MapReduceService mapReduceService, NodeEngine nodeEngine) {
    final OperationService operationService = nodeEngine.getOperationService();
    final List<InternalCompletableFuture<V>> futures = new ArrayList<InternalCompletableFuture<V>>();
    final List<V> results = new ArrayList<V>();
    final List<Exception> exceptions = new ArrayList<Exception>(members.size());
    for (Member member : members) {
        try {
            Operation operation = operationFactory.createOperation();
            if (nodeEngine.getThisAddress().equals(member.getAddress())) {
                // Locally we can call the operation directly
                operation.setNodeEngine(nodeEngine);
                operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
                operation.setService(mapReduceService);
                operation.run();
                V response = (V) operation.getResponse();
                if (response != null) {
                    results.add(response);
                }
            } else {
                InvocationBuilder ib = operationService.createInvocationBuilder(SERVICE_NAME, operation, member.getAddress());
                final InternalCompletableFuture<V> future = ib.invoke();
                futures.add(future);
            }
        } catch (Exception e) {
            exceptions.add(e);
        }
    }
    for (InternalCompletableFuture<V> future : futures) {
        try {
            V response = future.join();
            if (response != null) {
                results.add(response);
            }
        } catch (Exception e) {
            exceptions.add(e);
        }
    }
    if (exceptions.size() > 0) {
        throw new RemoteMapReduceException("Exception on mapreduce operation", exceptions);
    }
    return results;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) Operation(com.hazelcast.spi.Operation) NotifyRemoteExceptionOperation(com.hazelcast.mapreduce.impl.operation.NotifyRemoteExceptionOperation) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) TimeoutException(java.util.concurrent.TimeoutException) RemoteMapReduceException(com.hazelcast.mapreduce.RemoteMapReduceException) OperationService(com.hazelcast.spi.OperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)1 RemoteMapReduceException (com.hazelcast.mapreduce.RemoteMapReduceException)1 NotifyRemoteExceptionOperation (com.hazelcast.mapreduce.impl.operation.NotifyRemoteExceptionOperation)1 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)1 InvocationBuilder (com.hazelcast.spi.InvocationBuilder)1 Operation (com.hazelcast.spi.Operation)1 OperationService (com.hazelcast.spi.OperationService)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1