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;
}
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;
}
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();
}
}
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();
}
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);
}
Aggregations