Class OrderedExecutorLimiter<T extends java.lang.Runnable>
- java.lang.Object
-
- org.threadly.concurrent.wrapper.limiter.OrderedExecutorLimiter<T>
-
- 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 ofExecutorLimiter
which allows you to order the tasks in a way other than FIFO. If first in first out is acceptableExecutorLimiter
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(T task)
The same asExecutor.execute(Runnable)
but typed for the sortable task.int
getMaxConcurrency()
Call to check what the maximum concurrency this limiter will allow.int
getUnsubmittedTaskCount()
Query how many tasks are being withheld from the parent scheduler.void
setMaxConcurrency(int maxConcurrency)
Updates the concurrency limit for this limiter.ListenableFuture<?>
submit(T task)
The same asSubmitterExecutor.submit(Runnable)
but typed for the sortable task.<R> ListenableFuture<R>
submit(T task, R result)
The same asSubmitterExecutor.submit(Runnable, Object)
but typed for the sortable task.
-
-
-
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. TheComparator
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 parallelsorter
- Implementation ofComparator
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. TheComparator
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 inListenableFuture.map(java.util.function.Function)
orListenableFuture.flatMap(java.util.function.Function)
should be counted towards the concurrency limit. Specifyingfalse
will release the limit as soon as the original task completes. Specifyingtrue
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 parallellimitFutureListenersExecution
-true
to include listener / mapped functions towards execution limitsorter
- Implementation ofComparator
to sort the task queue being limited
-
-
Method Detail
-
getMaxConcurrency
public int getMaxConcurrency()
Call to check what the maximum concurrency this limiter will allow.- Returns:
- maximum concurrent tasks to be run
- Since:
- 6.3
-
setMaxConcurrency
public void setMaxConcurrency(int maxConcurrency)
Updates the concurrency limit for this limiter.- 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.- Returns:
- Quantity of tasks queued in this limiter
- Since:
- 6.3
-
submit
public ListenableFuture<?> submit(T task)
The same asSubmitterExecutor.submit(Runnable)
but typed for the sortable task.- Parameters:
task
- runnable to be executed- Returns:
- a future to know when the task has completed
-
submit
public <R> ListenableFuture<R> submit(T task, R result)
The same asSubmitterExecutor.submit(Runnable, Object)
but typed for the sortable task.- Type Parameters:
R
- type of result for future- Parameters:
task
- runnable to be executedresult
- 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 asExecutor.execute(Runnable)
but typed for the sortable task.- Parameters:
task
- runnable to be executed
-
-