Yair Zaslavsky has uploaded a new change for review. Change subject: core: Adding support for completion service for ThreadPoolUtil ......................................................................
core: Adding support for completion service for ThreadPoolUtil Completion service (java.util.concurrent.ExecutorCompletionService) is a wrapper for Exeuctor which allows to submit tasks, and to dequeue (using an internal blocking queue) the results of the execution Added a support for it on top of our ThreadPoolUtil, as we use an exeuctor to hold the thread pool. These new static methods will be used by the multi-agents RFE implementation Bug-Url: Change-Id: If806302ecf028a5db1c9726a407a1643b5c000b6 signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java 1 file changed, 31 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/39/10439/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java index 771dca4..b5cc7ac 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java @@ -1,5 +1,8 @@ package org.ovirt.engine.core.utils.threadpool; +import java.util.Collection; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorCompletionService; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.SynchronousQueue; @@ -68,6 +71,34 @@ private static final ExecutorService es = new InternalThreadExecutor(); + /** + * Creates a completion service to allow launching of tasks (callable objects) + * concurrently, and use a blocking queue like interface to get the tasks + * execution results + * @return + */ + public static <V> ExecutorCompletionService<V> getCompletionService() { + ExecutorCompletionService<V> ecs = new ExecutorCompletionService<V>(es); + return ecs; + } + + /** + * Creates a completion service to allow launching of tasks (callable objects) + * concurrently, and use a blocking queue like interface to get the tasks + * @param tasks collection of tasks (callable objects) to submit + * @return + */ + public static <V> ExecutorCompletionService<V> getCompletionService(Collection<Callable<V>> tasks) { + ExecutorCompletionService<V> ecs = getCompletionService(); + if (tasks == null) { + return ecs; + } + for (Callable<V> callable:tasks) { + ecs.submit(callable); + } + return ecs; + } + public static void execute(Runnable command) { try { es.submit(new InternalWrapperRunnable(command, -- To view, visit http://gerrit.ovirt.org/10439 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If806302ecf028a5db1c9726a407a1643b5c000b6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches