Class OrderedExecutorLimiter<T extends java.lang.Runnable>

  • Type Parameters:
    T - Type of task that can be used for comparison

    public class OrderedExecutorLimiter<T extends java.lang.Runnable>
    extends java.lang.Object
    Implementation of ExecutorLimiter which allows you to order the tasks in a way other than FIFO. If first in first out is acceptable ExecutorLimiter is a superior option. Please see the constructor javadocs for more details about sorting: OrderedExecutorLimiter(Executor, int, Comparator)
    Since:
    6.2
    • Constructor Summary

      Constructors 
      Constructor Description
      OrderedExecutorLimiter​(java.util.concurrent.Executor executor, int maxConcurrency, boolean limitFutureListenersExecution, java.util.Comparator<? super T> sorter)
      Construct a new limiter, providing the implementation of how tasks should be sorted relative to each other.
      OrderedExecutorLimiter​(java.util.concurrent.Executor executor, int maxConcurrency, java.util.Comparator<? super T> sorter)
      Construct a new limiter, providing the implementation of how tasks should be sorted relative to each other.
    • Constructor Detail

      • OrderedExecutorLimiter

        public OrderedExecutorLimiter​(java.util.concurrent.Executor executor,
                                      int maxConcurrency,
                                      java.util.Comparator<? super T> sorter)
        Construct a new limiter, providing the implementation of how tasks should be sorted relative to each other. The Comparator provided must deterministically provide ordering such that two tasks must always have the same relative order.
        Parameters:
        executor - Executor to submit task executions to.
        maxConcurrency - maximum quantity of tasks to run in parallel
        sorter - Implementation of Comparator to sort the task queue being limited
      • OrderedExecutorLimiter

        public OrderedExecutorLimiter​(java.util.concurrent.Executor executor,
                                      int maxConcurrency,
                                      boolean limitFutureListenersExecution,
                                      java.util.Comparator<? super T> sorter)
        Construct a new limiter, providing the implementation of how tasks should be sorted relative to each other. The Comparator provided must deterministically provide ordering such that two tasks must always have the same relative order.

        This constructor allows you to specify if listeners / FutureCallback's / functions in ListenableFuture.map(java.util.function.Function) or ListenableFuture.flatMap(java.util.function.Function) should be counted towards the concurrency limit. Specifying false will release the limit as soon as the original task completes. Specifying true will continue to enforce the limit until all listeners (without an executor) complete.

        Parameters:
        executor - Executor to submit task executions to.
        maxConcurrency - maximum quantity of tasks to run in parallel
        limitFutureListenersExecution - true to include listener / mapped functions towards execution limit
        sorter - Implementation of Comparator to sort the task queue being limited
    • Method Detail

      • getMaxConcurrency

        public int getMaxConcurrency()
        Call to check what the maximum concurrency this limiter will allow.

        See ExecutorLimiter.getMaxConcurrency().

        Returns:
        maximum concurrent tasks to be run
        Since:
        6.3
      • setMaxConcurrency

        public void setMaxConcurrency​(int maxConcurrency)
        Updates the concurrency limit for this limiter.

        See ExecutorLimiter.setMaxConcurrency(int).

        Parameters:
        maxConcurrency - maximum quantity of tasks to run in parallel
        Since:
        6.3
      • getUnsubmittedTaskCount

        public int getUnsubmittedTaskCount()
        Query how many tasks are being withheld from the parent scheduler.

        See ExecutorLimiter.getUnsubmittedTaskCount().

        Returns:
        Quantity of tasks queued in this limiter
        Since:
        6.3
      • submit

        public <R> ListenableFuture<R> submit​(T task,
                                              R result)
        The same as SubmitterExecutor.submit(Runnable, Object) but typed for the sortable task.
        Type Parameters:
        R - type of result for future
        Parameters:
        task - runnable to be executed
        result - result to be returned from resulting future .get() when runnable completes
        Returns:
        a future to know when the task has completed
      • execute

        public void execute​(T task)
        The same as Executor.execute(Runnable) but typed for the sortable task.
        Parameters:
        task - runnable to be executed