use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToPartitionOwner.
private <T> Future<T> submitToPartitionOwner(Callable<T> task, int partitionId, boolean preventSync) {
checkNotNull(task, "task can't be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
String uuid = newUnsecureUuidString();
boolean sync = !preventSync && checkSync();
Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
InternalCompletableFuture future = invokeOnPartition(op);
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, partitionId);
}
use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.
the class ExecutorServiceSubmitToPartitionMessageTask method prepareOperation.
@Override
protected Operation prepareOperation() {
SecurityContext securityContext = clientEngine.getSecurityContext();
Data callableData = parameters.callable;
if (securityContext != null) {
Subject subject = endpoint.getSubject();
Object taskObject = serializationService.toObject(parameters.callable);
Callable callable;
if (taskObject instanceof Runnable) {
callable = securityContext.createSecureCallable(subject, (Runnable) taskObject);
} else {
callable = securityContext.createSecureCallable(subject, (Callable<? extends Object>) taskObject);
}
callableData = serializationService.toData(callable);
}
return new CallableTaskOperation(parameters.name, parameters.uuid, callableData);
}
use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submit.
@Nonnull
@Override
public <T> Future<T> submit(@Nonnull Runnable task, T result) {
checkNotNull(task, "task must not be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Callable<T> callable = createRunnableAdapter(task);
Data callableData = nodeEngine.toData(callable);
UUID uuid = newUnsecureUUID();
int partitionId = getTaskPartitionId(callable);
Operation op = new CallableTaskOperation(name, uuid, callableData).setPartitionId(partitionId);
InvocationFuture future = invokeOnPartition(op);
return new CancellableDelegatingFuture<>(future, result, nodeEngine, uuid, partitionId);
}
use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToPartitionOwner.
@Nonnull
private <T> Future<T> submitToPartitionOwner(@Nonnull Callable<T> task, int partitionId) {
checkNotNull(task, "task must not be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
UUID uuid = newUnsecureUUID();
Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
InternalCompletableFuture future = invokeOnPartition(op);
return new CancellableDelegatingFuture<>(future, nodeEngine, uuid, partitionId);
}
use of com.hazelcast.executor.impl.operations.CallableTaskOperation in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToPartitionOwner.
private <T> void submitToPartitionOwner(@Nonnull Callable<T> task, @Nullable ExecutionCallback<T> callback, int partitionId) {
checkNotShutdown();
checkNotNull(task, "task must not be null");
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
CallableTaskOperation op = new CallableTaskOperation(name, null, taskData);
OperationService operationService = nodeEngine.getOperationService();
InvocationFuture<T> future = operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId).invoke();
if (callback != null) {
future.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
if (t instanceof RejectedExecutionException) {
callback.onFailure(t);
}
});
}
}
Aggregations