Search in sources :

Example 1 with TasksReporterCallable

use of com.enonic.xp.impl.task.distributed.TasksReporterCallable 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;
}
Also used : TimeoutException(java.util.concurrent.TimeoutException) AllTasksReporter(com.enonic.xp.impl.task.distributed.AllTasksReporter) SingleTaskReporter(com.enonic.xp.impl.task.distributed.SingleTaskReporter) TaskInfo(com.enonic.xp.task.TaskInfo) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Component(org.osgi.service.component.annotations.Component) DescribedTask(com.enonic.xp.impl.task.distributed.DescribedTask) Duration(java.time.Duration) Map(java.util.Map) Activate(org.osgi.service.component.annotations.Activate) TaskManager(com.enonic.xp.impl.task.distributed.TaskManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TasksReporterCallable(com.enonic.xp.impl.task.distributed.TasksReporterCallable) MemberSelector(com.hazelcast.core.MemberSelector) Deactivate(org.osgi.service.component.annotations.Deactivate) ExceptionUtil(com.hazelcast.util.ExceptionUtil) RunningTasksReporter(com.enonic.xp.impl.task.distributed.RunningTasksReporter) Member(com.hazelcast.core.Member) BundleContext(org.osgi.framework.BundleContext) ApplicationKey(com.enonic.xp.app.ApplicationKey) OffloadedTaskCallable(com.enonic.xp.impl.task.distributed.OffloadedTaskCallable) SerializableFunction(com.enonic.xp.impl.task.distributed.SerializableFunction) TaskId(com.enonic.xp.task.TaskId) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) IExecutorService(com.hazelcast.core.IExecutorService) Modified(org.osgi.service.component.annotations.Modified) Reference(org.osgi.service.component.annotations.Reference) ArrayList(java.util.ArrayList) TaskInfo(com.enonic.xp.task.TaskInfo) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) TasksReporterCallable(com.enonic.xp.impl.task.distributed.TasksReporterCallable) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)1 AllTasksReporter (com.enonic.xp.impl.task.distributed.AllTasksReporter)1 DescribedTask (com.enonic.xp.impl.task.distributed.DescribedTask)1 OffloadedTaskCallable (com.enonic.xp.impl.task.distributed.OffloadedTaskCallable)1 RunningTasksReporter (com.enonic.xp.impl.task.distributed.RunningTasksReporter)1 SerializableFunction (com.enonic.xp.impl.task.distributed.SerializableFunction)1 SingleTaskReporter (com.enonic.xp.impl.task.distributed.SingleTaskReporter)1 TaskManager (com.enonic.xp.impl.task.distributed.TaskManager)1 TasksReporterCallable (com.enonic.xp.impl.task.distributed.TasksReporterCallable)1 TaskId (com.enonic.xp.task.TaskId)1 TaskInfo (com.enonic.xp.task.TaskInfo)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IExecutorService (com.hazelcast.core.IExecutorService)1 Member (com.hazelcast.core.Member)1 MemberSelector (com.hazelcast.core.MemberSelector)1 ExceptionUtil (com.hazelcast.util.ExceptionUtil)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1