Search in sources :

Example 1 with InvocationBuilder

use of com.hazelcast.spi.InvocationBuilder 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)

Example 2 with InvocationBuilder

use of com.hazelcast.spi.InvocationBuilder in project hazelcast by hazelcast.

the class AbstractExecutorServiceCancelMessageTask method call.

@Override
protected Object call() throws Exception {
    InvocationBuilder builder = createInvocationBuilder();
    builder.setTryCount(CANCEL_TRY_COUNT).setTryPauseMillis(CANCEL_TRY_PAUSE_MILLIS);
    InternalCompletableFuture future = builder.invoke();
    boolean result = false;
    try {
        result = (Boolean) future.get();
    } catch (InterruptedException e) {
        logException(e);
    } catch (ExecutionException e) {
        logException(e);
    }
    return result;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with InvocationBuilder

use of com.hazelcast.spi.InvocationBuilder in project hazelcast by hazelcast.

the class AbstractMultiTargetMessageTask method processMessage.

@Override
protected void processMessage() throws Throwable {
    Supplier<Operation> operationSupplier = createOperationSupplier();
    Collection<Member> targets = getTargets();
    returnResponseIfNoTargetLeft(targets, EMPTY_MAP);
    final InternalOperationService operationService = nodeEngine.getOperationService();
    MultiTargetCallback callback = new MultiTargetCallback(targets);
    for (Member target : targets) {
        Operation op = operationSupplier.get();
        InvocationBuilder builder = operationService.createInvocationBuilder(getServiceName(), op, target.getAddress()).setResultDeserialized(false).setExecutionCallback(new SingleTargetCallback(target, callback));
        builder.invoke();
    }
}
Also used : Operation(com.hazelcast.spi.Operation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) Member(com.hazelcast.core.Member)

Example 4 with InvocationBuilder

use of com.hazelcast.spi.InvocationBuilder in project hazelcast by hazelcast.

the class AbstractInvocationMessageTask method processMessage.

@Override
protected void processMessage() {
    final ClientEndpoint endpoint = getEndpoint();
    Operation op = prepareOperation();
    op.setCallerUuid(endpoint.getUuid());
    InvocationBuilder builder = getInvocationBuilder(op).setExecutionCallback(this).setResultDeserialized(false);
    builder.invoke();
}
Also used : Operation(com.hazelcast.spi.Operation) InvocationBuilder(com.hazelcast.spi.InvocationBuilder) ClientEndpoint(com.hazelcast.client.ClientEndpoint)

Example 5 with InvocationBuilder

use of com.hazelcast.spi.InvocationBuilder in project hazelcast-jet by hazelcast.

the class JetJoinSubmittedJobMessageTask method processMessage.

@Override
protected void processMessage() {
    Operation op = prepareOperation();
    op.setCallerUuid(getEndpoint().getUuid());
    InvocationBuilder builder = getInvocationBuilder(op).setResultDeserialized(false);
    InternalCompletableFuture<Object> invocation = builder.invoke();
    invocation.andThen(this);
}
Also used : JoinSubmittedJobOperation(com.hazelcast.jet.impl.operation.JoinSubmittedJobOperation) Operation(com.hazelcast.spi.Operation) InvocationBuilder(com.hazelcast.spi.InvocationBuilder)

Aggregations

InvocationBuilder (com.hazelcast.spi.InvocationBuilder)9 Operation (com.hazelcast.spi.Operation)4 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 Member (com.hazelcast.core.Member)2 MemberImpl (com.hazelcast.instance.MemberImpl)2 RemoteMapReduceException (com.hazelcast.mapreduce.RemoteMapReduceException)2 Address (com.hazelcast.nio.Address)2 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)2 OperationService (com.hazelcast.spi.OperationService)2 Future (java.util.concurrent.Future)2 TimeoutException (java.util.concurrent.TimeoutException)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)1 JoinSubmittedJobOperation (com.hazelcast.jet.impl.operation.JoinSubmittedJobOperation)1 AccumulatorInfo (com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo)1 DestroyQueryCacheOperation (com.hazelcast.map.impl.querycache.subscriber.operation.DestroyQueryCacheOperation)1 PublisherCreateOperation (com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation)1 NotifyRemoteExceptionOperation (com.hazelcast.mapreduce.impl.operation.NotifyRemoteExceptionOperation)1 Predicate (com.hazelcast.query.Predicate)1 ArrayList (java.util.ArrayList)1