use of com.enonic.xp.impl.task.distributed.SerializableFunction in project xp by enonic.
the class ClusteredTaskManagerImpl method send.
private List<TaskInfo> send(final SerializableFunction<TaskManager, List<TaskInfo>> taskFunction) {
final List<TaskInfo> taskInfoBuilder = new ArrayList<>();
final Map<Member, Future<List<TaskInfo>>> resultsFromMembers = executorService.submitToAllMembers(new TasksReporterCallable(taskFunction));
for (Future<List<TaskInfo>> responseFuture : resultsFromMembers.values()) {
try {
final List<TaskInfo> response = responseFuture.get(outboundTimeoutNs, TimeUnit.NANOSECONDS);
taskInfoBuilder.addAll(response);
} catch (TimeoutException e) {
resultsFromMembers.values().forEach(f -> f.cancel(true));
throw new RuntimeException(e);
} catch (InterruptedException | ExecutionException e) {
throw ExceptionUtil.rethrow(e);
}
}
return taskInfoBuilder;
}
Aggregations