use of com.hazelcast.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class DurableExecutorServiceProxy method submitToPartition.
private <T> DurableExecutorServiceFuture<T> submitToPartition(Callable<T> task, int partitionId, T defaultValue) {
checkNotNull(task, "task can't be null");
SerializationService serializationService = getNodeEngine().getSerializationService();
Data taskData = serializationService.toData(task);
TaskOperation operation = new TaskOperation(name, taskData);
operation.setPartitionId(partitionId);
InternalCompletableFuture<Integer> future = invokeOnPartition(operation);
int sequence;
try {
sequence = future.get();
} catch (Throwable t) {
CompletedFuture<T> completedFuture = new CompletedFuture<T>(serializationService, t, getAsyncExecutor());
return new DurableExecutorServiceDelegateFuture<T>(completedFuture, serializationService, null, -1);
}
Operation op = new RetrieveResultOperation(name, sequence).setPartitionId(partitionId);
InternalCompletableFuture<T> internalCompletableFuture = invokeOnPartition(op);
long taskId = Bits.combineToLong(partitionId, sequence);
return new DurableExecutorServiceDelegateFuture<T>(internalCompletableFuture, serializationService, defaultValue, taskId);
}
use of com.hazelcast.util.executor.CompletedFuture 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.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class ExecutorServiceProxy method wait.
private <T> boolean wait(long timeoutNanos, List<Future<T>> futures) throws InterruptedException {
boolean done = true;
for (int i = 0, size = futures.size(); i < size; i++) {
long start = System.nanoTime();
Object value;
try {
Future<T> future = futures.get(i);
value = future.get(timeoutNanos, TimeUnit.NANOSECONDS);
} catch (ExecutionException e) {
value = e;
} catch (TimeoutException e) {
done = false;
for (int l = i; l < size; l++) {
Future<T> f = futures.get(i);
if (f.isDone()) {
Object v;
try {
v = f.get();
} catch (ExecutionException ex) {
v = ex;
}
futures.set(l, new CompletedFuture<T>(getNodeEngine().getSerializationService(), v, getAsyncExecutor()));
}
}
break;
}
futures.set(i, new CompletedFuture<T>(getNodeEngine().getSerializationService(), value, getAsyncExecutor()));
timeoutNanos -= System.nanoTime() - start;
}
return done;
}
use of com.hazelcast.util.executor.CompletedFuture 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.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method checkSync.
private <T> Future<T> checkSync(ClientInvocationFuture f, String uuid, Address address, boolean preventSync, T defaultValue) {
boolean sync = isSyncComputation(preventSync);
if (sync) {
Object response = retrieveResultFromMessage(f);
Executor userExecutor = getContext().getExecutionService().getUserExecutor();
return new CompletedFuture<T>(getContext().getSerializationService(), response, userExecutor);
} else {
return new ClientAddressCancellableDelegatingFuture<T>(f, getContext(), uuid, address, defaultValue, SUBMIT_TO_ADDRESS_DECODER);
}
}
Aggregations