use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToMember.
@Override
public <T> Future<T> submitToMember(Callable<T> task, Member member) {
checkNotNull(task, "task can't be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
String uuid = newUnsecureUuidString();
Address target = ((MemberImpl) member).getAddress();
boolean sync = checkSync();
MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
InternalCompletableFuture future = nodeEngine.getOperationService().invokeOnTarget(DistributedExecutorService.SERVICE_NAME, op, target);
if (sync) {
Object response;
try {
response = future.get();
} catch (Exception e) {
response = e;
}
return new CompletedFuture<T>(nodeEngine.getSerializationService(), response, getAsyncExecutor());
}
return new CancellableDelegatingFuture<T>(future, nodeEngine, uuid, target);
}
use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToMember.
@Override
public <T> void submitToMember(Callable<T> task, Member member, ExecutionCallback<T> callback) {
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
String uuid = newUnsecureUuidString();
MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
OperationService operationService = nodeEngine.getOperationService();
Address address = ((MemberImpl) member).getAddress();
operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, address).setExecutionCallback((ExecutionCallback) callback).invoke();
}
use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submit.
@Override
public <T> Future<T> submit(Runnable task, T result) {
checkNotNull(task, "task can't be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Callable<T> callable = createRunnableAdapter(task);
Data callableData = nodeEngine.toData(callable);
String uuid = newUnsecureUuidString();
int partitionId = getTaskPartitionId(callable);
Operation op = new CallableTaskOperation(name, uuid, callableData).setPartitionId(partitionId);
InternalCompletableFuture future = invokeOnPartition(op);
boolean sync = checkSync();
if (sync) {
try {
future.get();
} catch (Exception exception) {
logger.warning(exception);
}
return new CompletedFuture<T>(nodeEngine.getSerializationService(), result, getAsyncExecutor());
}
return new CancellableDelegatingFuture<T>(future, result, nodeEngine, uuid, partitionId);
}
use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToPartitionOwner.
private <T> void submitToPartitionOwner(Callable<T> task, ExecutionCallback<T> callback, int partitionId) {
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
CallableTaskOperation op = new CallableTaskOperation(name, null, taskData);
OperationService operationService = nodeEngine.getOperationService();
operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId).setExecutionCallback((ExecutionCallback) callback).invoke();
}
use of com.hazelcast.spi.NodeEngine in project hazelcast by hazelcast.
the class ExecutorServiceProxy method shutdown.
@Override
public void shutdown() {
NodeEngine nodeEngine = getNodeEngine();
Collection<Member> members = nodeEngine.getClusterService().getMembers();
OperationService operationService = nodeEngine.getOperationService();
Collection<Future> calls = new LinkedList<Future>();
for (Member member : members) {
if (member.localMember()) {
getService().shutdownExecutor(name);
} else {
Future f = submitShutdownOperation(operationService, member);
calls.add(f);
}
}
waitWithDeadline(calls, 1, TimeUnit.SECONDS, WHILE_SHUTDOWN_EXCEPTION_HANDLER);
}
Aggregations