Class ExecutionCompletionService<V>
- java.lang.Object
-
- org.jgroups.blocks.executor.ExecutionCompletionService<V>
-
- All Implemented Interfaces:
java.util.concurrent.CompletionService<V>
public class ExecutionCompletionService<V> extends java.lang.Object implements java.util.concurrent.CompletionService<V>
ACompletionService
that uses a suppliedExecutionService
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. TheExecutorCompletionService
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ExecutionCompletionService.QueueingListener
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.BlockingQueue<NotifyingFuture<V>>
completionQueue
protected ExecutionService
executor
protected ExecutionCompletionService.QueueingListener
listener
-
Constructor Summary
Constructors Modifier Constructor Description ExecutionCompletionService(ExecutionService executor)
Creates an ExecutorCompletionService using the supplied executor for base task execution and aLinkedBlockingQueue
as a completion queue.ExecutionCompletionService(ExecutionService executor, java.util.concurrent.BlockingQueue<NotifyingFuture<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue.protected
ExecutionCompletionService(ExecutionService executor, java.util.concurrent.BlockingQueue<NotifyingFuture<V>> completionQueue, ExecutionCompletionService.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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NotifyingFuture<V>
poll()
{@inheritDoc CompletionService}NotifyingFuture<V>
poll(long timeout, java.util.concurrent.TimeUnit unit)
{@inheritDoc CompletionService}java.util.concurrent.Future<V>
submit(java.lang.Runnable task, V result)
{@inheritDoc CompletionService}java.util.concurrent.Future<V>
submit(java.util.concurrent.Callable<V> task)
{@inheritDoc CompletionService}NotifyingFuture<V>
take()
{@inheritDoc CompletionService}
-
-
-
Field Detail
-
executor
protected final ExecutionService executor
-
completionQueue
protected final java.util.concurrent.BlockingQueue<NotifyingFuture<V>> completionQueue
-
listener
protected final ExecutionCompletionService.QueueingListener listener
-
-
Constructor Detail
-
ExecutionCompletionService
public ExecutionCompletionService(ExecutionService executor)
Creates an ExecutorCompletionService using the supplied executor for base task execution and aLinkedBlockingQueue
as a completion queue.- Parameters:
executor
- the executor to use- Throws:
java.lang.NullPointerException
- if executor is null
-
ExecutionCompletionService
public ExecutionCompletionService(ExecutionService executor, java.util.concurrent.BlockingQueue<NotifyingFuture<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue.- Parameters:
executor
- the executor to usecompletionQueue
- the queue to use as the completion queue normally one dedicated for use by this service- Throws:
java.lang.NullPointerException
- if executor is null
-
ExecutionCompletionService
protected ExecutionCompletionService(ExecutionService executor, java.util.concurrent.BlockingQueue<NotifyingFuture<V>> completionQueue, ExecutionCompletionService.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- Parameters:
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 listener should at minimum call the super.futureDone or else this completion service may not work correctly.- Throws:
java.lang.NullPointerException
- if executor is null
-
-
Method Detail
-
submit
public java.util.concurrent.Future<V> submit(java.util.concurrent.Callable<V> task)
{@inheritDoc CompletionService}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.
- Specified by:
submit
in interfacejava.util.concurrent.CompletionService<V>
-
submit
public java.util.concurrent.Future<V> submit(java.lang.Runnable task, V result)
{@inheritDoc CompletionService}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.
- Specified by:
submit
in interfacejava.util.concurrent.CompletionService<V>
-
take
public NotifyingFuture<V> take() throws java.lang.InterruptedException
{@inheritDoc CompletionService}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.
- Specified by:
take
in interfacejava.util.concurrent.CompletionService<V>
- Throws:
java.lang.InterruptedException
-
poll
public NotifyingFuture<V> poll()
{@inheritDoc CompletionService}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.
- Specified by:
poll
in interfacejava.util.concurrent.CompletionService<V>
-
poll
public NotifyingFuture<V> poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
{@inheritDoc CompletionService}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.
- Specified by:
poll
in interfacejava.util.concurrent.CompletionService<V>
- Throws:
java.lang.InterruptedException
-
-