Class DistributedExecutionCompletionService<V>

  • All Implemented Interfaces:
    java.util.concurrent.CompletionService<V>

    public class DistributedExecutionCompletionService<V>
    extends java.lang.Object
    implements java.util.concurrent.CompletionService<V>
    A 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.

    Author:
    William Burns, Vladimir Blagojevic
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<V> poll()
      {@inheritDoc CompletionService}
      java.util.concurrent.CompletableFuture<V> poll​(long timeout, java.util.concurrent.TimeUnit unit)
      {@inheritDoc CompletionService}
      java.util.concurrent.CompletableFuture<V> submit​(java.lang.Runnable task, V result)
      {@inheritDoc CompletionService}
      java.util.concurrent.CompletableFuture<V> submit​(java.util.concurrent.Callable<V> task)
      {@inheritDoc CompletionService}
      <K> java.util.concurrent.Future<V> submit​(java.util.concurrent.Callable<V> task, K... input)  
      <K> java.util.concurrent.CompletableFuture<V> submit​(Address target, java.util.concurrent.Callable<V> task)  
      java.util.List<java.util.concurrent.CompletableFuture<V>> submitEverywhere​(java.util.concurrent.Callable<V> task)  
      <K> java.util.List<java.util.concurrent.CompletableFuture<V>> submitEverywhere​(java.util.concurrent.Callable<V> task, K... input)  
      java.util.concurrent.CompletableFuture<V> take()
      {@inheritDoc CompletionService}
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • completionQueue

        protected final java.util.concurrent.BlockingQueue<java.util.concurrent.CompletableFuture<V>> completionQueue
    • Constructor Detail

      • DistributedExecutionCompletionService

        public DistributedExecutionCompletionService​(DistributedExecutorService executor)
        Creates an ExecutorCompletionService using the supplied executor for base task execution and a LinkedBlockingQueue as a completion queue.
        Parameters:
        executor - the executor to use
        Throws:
        java.lang.NullPointerException - if executor is null
      • DistributedExecutionCompletionService

        public DistributedExecutionCompletionService​(DistributedExecutorService executor,
                                                     java.util.concurrent.BlockingQueue<java.util.concurrent.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 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.
        Parameters:
        executor - the executor to use
        completionQueue - the queue to use as the completion queue normally one dedicated for use by this service
        Throws:
        java.lang.NullPointerException - if executor is null
    • Method Detail

      • submit

        public java.util.concurrent.CompletableFuture<V> submit​(java.util.concurrent.Callable<V> task)
        {@inheritDoc CompletionService}
        Specified by:
        submit in interface java.util.concurrent.CompletionService<V>
      • submit

        public java.util.concurrent.CompletableFuture<V> submit​(java.lang.Runnable task,
                                                                V result)
        {@inheritDoc CompletionService}
        Specified by:
        submit in interface java.util.concurrent.CompletionService<V>
      • take

        public java.util.concurrent.CompletableFuture<V> take()
                                                       throws java.lang.InterruptedException
        {@inheritDoc CompletionService}
        Specified by:
        take in interface java.util.concurrent.CompletionService<V>
        Throws:
        java.lang.InterruptedException
      • poll

        public java.util.concurrent.CompletableFuture<V> poll()
        {@inheritDoc CompletionService}
        Specified by:
        poll in interface java.util.concurrent.CompletionService<V>
      • poll

        public java.util.concurrent.CompletableFuture<V> poll​(long timeout,
                                                              java.util.concurrent.TimeUnit unit)
                                                       throws java.lang.InterruptedException
        {@inheritDoc CompletionService}
        Specified by:
        poll in interface java.util.concurrent.CompletionService<V>
        Throws:
        java.lang.InterruptedException
      • submit

        public <K> java.util.concurrent.Future<V> submit​(java.util.concurrent.Callable<V> task,
                                                         K... input)
      • submitEverywhere

        public java.util.List<java.util.concurrent.CompletableFuture<V>> submitEverywhere​(java.util.concurrent.Callable<V> task)
      • submitEverywhere

        public <K> java.util.List<java.util.concurrent.CompletableFuture<V>> submitEverywhere​(java.util.concurrent.Callable<V> task,
                                                                                              K... input)
      • submit

        public <K> java.util.concurrent.CompletableFuture<V> submit​(Address target,
                                                                    java.util.concurrent.Callable<V> task)