public class DistributedExecutionCompletionService<V> extends Object implements 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. Since a ExecutionService
may only be used with serializable request objects, this class must be used
instead.
| Modifier and Type | Class and Description |
|---|---|
protected class |
DistributedExecutionCompletionService.QueueingListener |
| Modifier and Type | Field and Description |
|---|---|
protected BlockingQueue<NotifyingFuture<V>> |
completionQueue |
protected DistributedExecutorService |
executor |
protected DistributedExecutionCompletionService.QueueingListener |
listener |
| Modifier | 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,
BlockingQueue<NotifyingFuture<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied
executor for base task execution and the supplied queue as its
completion queue.
|
protected |
DistributedExecutionCompletionService(DistributedExecutorService executor,
BlockingQueue<NotifyingFuture<V>> completionQueue,
DistributedExecutionCompletionService.QueueingListener listener)
This constructor is here if someone wants to override this class and
provide their own QueueingListener to possibly listen in on futures
being finished
|
| Modifier and Type | Method and Description |
|---|---|
NotifyingFuture<V> |
poll() |
NotifyingFuture<V> |
poll(long timeout,
TimeUnit unit) |
Future<V> |
submit(Callable<V> task) |
<K> Future<V> |
submit(Callable<V> task,
K... input) |
Future<V> |
submit(Runnable task,
V result) |
List<Future<V>> |
submitEverywhere(Callable<V> task) |
<K> List<Future<V>> |
submitEverywhere(Callable<V> task,
K... input) |
NotifyingFuture<V> |
take() |
protected final DistributedExecutorService executor
protected final BlockingQueue<NotifyingFuture<V>> completionQueue
protected final DistributedExecutionCompletionService.QueueingListener listener
public DistributedExecutionCompletionService(DistributedExecutorService executor)
LinkedBlockingQueue as a completion queue.executor - the executor to useNullPointerException - if executor is nullpublic DistributedExecutionCompletionService(DistributedExecutorService executor, BlockingQueue<NotifyingFuture<V>> completionQueue)
executor - the executor to usecompletionQueue - the queue to use as the completion queue
normally one dedicated for use by this serviceNullPointerException - if executor is nullprotected DistributedExecutionCompletionService(DistributedExecutorService executor, BlockingQueue<NotifyingFuture<V>> completionQueue, DistributedExecutionCompletionService.QueueingListener listener)
executor - the executor to usecompletionQueue - the queue to use as the completion queue
normally one dedicated for use by this servicelistener - the listener to notify. To work properly this listner
should at minimum call the super.futureDone or else this
completion service may not work correctly.NullPointerException - if executor is nullpublic Future<V> submit(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 CompletionService<V>public Future<V> submit(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 CompletionService<V>public NotifyingFuture<V> take() throws 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 CompletionService<V>InterruptedExceptionpublic NotifyingFuture<V> poll()
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 CompletionService<V>public NotifyingFuture<V> poll(long timeout, TimeUnit unit) throws 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 CompletionService<V>InterruptedExceptionCopyright © 2012 JBoss by Red Hat. All Rights Reserved.