use of com.hazelcast.util.executor.CompletedFuture 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.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method invokeAll.
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
final List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size());
final List<Future<T>> result = new ArrayList<Future<T>>(tasks.size());
for (Callable<T> task : tasks) {
futures.add(submitToRandomInternal(task, null, true));
}
Executor userExecutor = getContext().getExecutionService().getUserExecutor();
for (Future<T> future : futures) {
Object value = retrieveResult(future);
result.add(new CompletedFuture<T>(getContext().getSerializationService(), value, userExecutor));
}
return result;
}
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, int partitionId, 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 ClientPartitionCancellableDelegatingFuture<T>(f, getContext(), uuid, partitionId, defaultValue, SUBMIT_TO_PARTITION_DECODER);
}
}
use of com.hazelcast.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class ExecutorServiceProxy method invokeAll.
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
List<Future<T>> futures = new ArrayList<Future<T>>(tasks.size());
List<Future<T>> result = new ArrayList<Future<T>>(tasks.size());
for (Callable<T> task : tasks) {
futures.add(submit(task));
}
for (Future<T> future : futures) {
Object value;
try {
value = future.get();
} catch (ExecutionException e) {
value = e;
}
result.add(new CompletedFuture<T>(getNodeEngine().getSerializationService(), value, getAsyncExecutor()));
}
return result;
}
use of com.hazelcast.util.executor.CompletedFuture in project hazelcast by hazelcast.
the class FutureUtilTest method testGetAllDone_whenSomeFuturesAreCompleted.
@Test
public void testGetAllDone_whenSomeFuturesAreCompleted() {
Future completedFuture = new CompletedFuture(null, null, null);
Collection<Future> futures = asList(new UncancellableFuture(), completedFuture, new UncancellableFuture());
assertEquals(1, FutureUtil.getAllDone(futures).size());
assertEquals(completedFuture, FutureUtil.getAllDone(futures).get(0));
}
Aggregations