Class PrioritizedParallelExecutor


  • public class PrioritizedParallelExecutor
    extends java.lang.Object
    Executor which will execute multiple Callables in parallel. The callables must be sorted and have the highest priority callable as the first in list. Executions of lower priority are canceled as soon as a higher priority result has been successfully been returned. The final Future will complete as soon as the first callable completed successfully and all other callables with higher priority (if any) have completed exceptionally
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.ExecutorService executor  
      private static java.lang.String LIST_PREFIX  
    • Constructor Summary

      Constructors 
      Constructor Description
      PrioritizedParallelExecutor​(java.util.concurrent.ExecutorService executor)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.Exception getFailureReason​(java.util.List<java.lang.Exception> exceptions)  
      <V> java.util.concurrent.Future<V> getSuccessfulResultWithHighestPriority​(java.util.List<java.util.concurrent.Callable<V>> callables)
      Executes the passed callables in parallel The callables must be sorted by priority with the highest priority as the first in list.
      • Methods inherited from class java.lang.Object

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

      • executor

        private final java.util.concurrent.ExecutorService executor
    • Constructor Detail

      • PrioritizedParallelExecutor

        public PrioritizedParallelExecutor​(java.util.concurrent.ExecutorService executor)
        Constructor
        Parameters:
        executor - the executor service which is used for executing the callables.
    • Method Detail

      • getSuccessfulResultWithHighestPriority

        public <V> java.util.concurrent.Future<V> getSuccessfulResultWithHighestPriority​(java.util.List<java.util.concurrent.Callable<V>> callables)
        Executes the passed callables in parallel The callables must be sorted by priority with the highest priority as the first in list. Executions of lower priority are canceled as soon as a higher priority result has successfully been calculated. The returned Future will complete as soon as the first callable completed successfully and all other callables with higher priority (if any) have completed exceptionally.
        Parameters:
        callables - the callables to execute.
        Returns:
        a future holding the best result from all callables.
      • getFailureReason

        private java.lang.Exception getFailureReason​(java.util.List<java.lang.Exception> exceptions)