T
- Type of task that can be used for comparisonpublic class OrderedExecutorLimiter<T extends java.lang.Runnable>
extends java.lang.Object
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)
Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(T task)
The same as
Executor.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 as
SubmitterExecutor.submit(Runnable) but
typed for the sortable task. |
<R> ListenableFuture<R> |
submit(T task,
R result)
The same as
SubmitterExecutor.submit(Runnable, Object) but
typed for the sortable task. |
public OrderedExecutorLimiter(java.util.concurrent.Executor executor, int maxConcurrency, java.util.Comparator<? super T> sorter)
Comparator
provided must deterministically provide ordering such
that two tasks must always have the same relative order.executor
- Executor
to submit task executions to.maxConcurrency
- maximum quantity of tasks to run in parallelsorter
- Implementation of Comparator
to sort the task queue being limitedpublic OrderedExecutorLimiter(java.util.concurrent.Executor executor, int maxConcurrency, boolean limitFutureListenersExecution, java.util.Comparator<? super T> sorter)
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.
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 of Comparator
to sort the task queue being limitedpublic int getMaxConcurrency()
public void setMaxConcurrency(int maxConcurrency)
maxConcurrency
- maximum quantity of tasks to run in parallelpublic int getUnsubmittedTaskCount()
public ListenableFuture<?> submit(T task)
SubmitterExecutor.submit(Runnable)
but
typed for the sortable task.task
- runnable to be executedpublic <R> ListenableFuture<R> submit(T task, R result)
SubmitterExecutor.submit(Runnable, Object)
but
typed for the sortable task.R
- type of result for futuretask
- runnable to be executedresult
- result to be returned from resulting future .get() when runnable completespublic void execute(T task)
Executor.execute(Runnable)
but typed for the sortable task.task
- runnable to be executed