Package org.infinispan.distexec
Class DistributedExecutionCompletionService<V>
- java.lang.Object
-
- org.infinispan.distexec.DistributedExecutionCompletionService<V>
-
- All Implemented Interfaces:
CompletionService<V>
public class DistributedExecutionCompletionService<V> extends Object implements CompletionService<V>
ACompletionService
that uses a suppliedDistributedExecutorService
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.- Author:
- William Burns, Vladimir Blagojevic
-
-
Field Summary
Fields Modifier and Type Field Description protected BlockingQueue<CompletableFuture<V>>
completionQueue
protected DistributedExecutorService
executor
-
Constructor Summary
Constructors Constructor Description DistributedExecutionCompletionService(DistributedExecutorService executor)
Creates an ExecutorCompletionService using the supplied executor for base task execution and aLinkedBlockingQueue
as a completion queue.DistributedExecutionCompletionService(DistributedExecutorService executor, BlockingQueue<CompletableFuture<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<V>
poll()
{@inheritDoc CompletionService}CompletableFuture<V>
poll(long timeout, TimeUnit unit)
{@inheritDoc CompletionService}CompletableFuture<V>
submit(Runnable task, V result)
{@inheritDoc CompletionService}CompletableFuture<V>
submit(Callable<V> task)
{@inheritDoc CompletionService}<K> Future<V>
submit(Callable<V> task, K... input)
<K> CompletableFuture<V>
submit(Address target, Callable<V> task)
List<CompletableFuture<V>>
submitEverywhere(Callable<V> task)
<K> List<CompletableFuture<V>>
submitEverywhere(Callable<V> task, K... input)
CompletableFuture<V>
take()
{@inheritDoc CompletionService}
-
-
-
Field Detail
-
executor
protected final DistributedExecutorService executor
-
completionQueue
protected final BlockingQueue<CompletableFuture<V>> completionQueue
-
-
Constructor Detail
-
DistributedExecutionCompletionService
public DistributedExecutionCompletionService(DistributedExecutorService 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:
NullPointerException
- if executor is null
-
DistributedExecutionCompletionService
public DistributedExecutionCompletionService(DistributedExecutorService executor, BlockingQueue<CompletableFuture<V>> completionQueue)
Creates an ExecutorCompletionService using the supplied executor for base task execution and the supplied queue as its completion queue. Note:PriorityBlockingQueue
for completionQueue can only be used with accompanyingComparator
as our internal implementation ofFuture
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.- Parameters:
executor
- the executor to usecompletionQueue
- the queue to use as the completion queue normally one dedicated for use by this service- Throws:
NullPointerException
- if executor is null
-
-
Method Detail
-
submit
public CompletableFuture<V> submit(Callable<V> task)
{@inheritDoc CompletionService}- Specified by:
submit
in interfaceCompletionService<V>
-
submit
public CompletableFuture<V> submit(Runnable task, V result)
{@inheritDoc CompletionService}- Specified by:
submit
in interfaceCompletionService<V>
-
take
public CompletableFuture<V> take() throws InterruptedException
{@inheritDoc CompletionService}- Specified by:
take
in interfaceCompletionService<V>
- Throws:
InterruptedException
-
poll
public CompletableFuture<V> poll()
{@inheritDoc CompletionService}- Specified by:
poll
in interfaceCompletionService<V>
-
poll
public CompletableFuture<V> poll(long timeout, TimeUnit unit) throws InterruptedException
{@inheritDoc CompletionService}- Specified by:
poll
in interfaceCompletionService<V>
- Throws:
InterruptedException
-
submitEverywhere
public List<CompletableFuture<V>> submitEverywhere(Callable<V> task)
-
submitEverywhere
public <K> List<CompletableFuture<V>> submitEverywhere(Callable<V> task, K... input)
-
submit
public <K> CompletableFuture<V> submit(Address target, Callable<V> task)
-
-