public class DistributedExecutionCompletionService<V>
extends java.lang.Object
implements java.util.concurrent.CompletionService<V>
CompletionService
that uses a supplied DistributedExecutorService
to execute
tasks. This class arranges that submitted tasks are, upon completion, placed on a queue
accessible using take. The class is lightweight enough to be suitable for transient use
when processing groups of tasks.
This class must be used instead of a ExecutorCompletionService
provided from
java.util.concurrent package. The ExecutorCompletionService
may not be used since it
requires the use of a non serializable RunnableFuture object.
Modifier and Type | Class and Description |
---|---|
protected class |
DistributedExecutionCompletionService.QueueingListener |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.BlockingQueue< |
completionQueue |
protected DistributedExecutorService |
executor |
protected DistributedExecutionCompletionService.QueueingListener |
listener |
Constructor and Description |
---|
DistributedExecutionCompletionService(DistributedExecutorService executor)
Creates an ExecutorCompletionService using the supplied executor for base task execution and a
LinkedBlockingQueue as a completion queue. |
DistributedExecutionCompletionService(DistributedExecutorService executor,
java.util.concurrent.BlockingQueue<
Creates an ExecutorCompletionService using the supplied executor for base task execution and
the supplied queue as its completion queue.
|
Modifier and Type | Method and Description |
---|---|
|
poll() |
|
poll(long timeout,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.Future<V> |
submit(java.util.concurrent.Callable<V> task) |
<K> java.util.concurrent.Future<V> |
submit(java.util.concurrent.Callable<V> task,
K... input) |
java.util.concurrent.Future<V> |
submit(java.lang.Runnable task,
V result) |
java.util.List<java.util.concurrent.Future<V>> |
submitEverywhere(java.util.concurrent.Callable<V> task) |
<K> java.util.List<java.util.concurrent.Future<V>> |
submitEverywhere(java.util.concurrent.Callable<V> task,
K... input) |
|
take() |
protected final DistributedExecutorService executor
protected final java.util.concurrent.BlockingQueue<> completionQueue
protected final DistributedExecutionCompletionService.QueueingListener listener
public DistributedExecutionCompletionService(DistributedExecutorService executor)
LinkedBlockingQueue
as a completion queue.executor
- the executor to usejava.lang.NullPointerException
- if executor is nullpublic DistributedExecutionCompletionService(DistributedExecutorService executor, java.util.concurrent.BlockingQueue<> completionQueue)
PriorityBlockingQueue
for completionQueue can only be used with accompanying
Comparator
as our internal implementation of Future
for each subtask does not
implement Comparable interface. Note that we do not provide any guarantees about which
particular internal class implements Future interface and these APIs will remain internal.executor
- the executor to usecompletionQueue
- the queue to use as the completion queue normally one dedicated for use by this
servicejava.lang.NullPointerException
- if executor is nullpublic java.util.concurrent.Future<V> submit(java.util.concurrent.Callable<V> task)
This future object may not be used as a NotifyingFuture. That is because internally this class sets the listener to provide ability to add to the queue.
submit
in interface java.util.concurrent.CompletionService<V>
public java.util.concurrent.Future<V> submit(java.lang.Runnable task, V result)
This future object may not be used as a NotifyingFuture. That is because internally this class sets the listener to provide ability to add to the queue.
submit
in interface java.util.concurrent.CompletionService<V>
publictake() throws java.lang.InterruptedException
This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
take
in interface java.util.concurrent.CompletionService<V>
java.lang.InterruptedException
publicpoll()
This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
poll
in interface java.util.concurrent.CompletionService<V>
publicpoll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
This future may safely be used as a NotifyingFuture if desired. This is because if it tries to set a listener it will be called immediately since the task has already been completed.
poll
in interface java.util.concurrent.CompletionService<V>
java.lang.InterruptedException
public <K> java.util.concurrent.Future<V> submit(java.util.concurrent.Callable<V> task, K... input)
public java.util.List<java.util.concurrent.Future<V>> submitEverywhere(java.util.concurrent.Callable<V> task)