public class KeyDistributedScheduler extends KeyDistributedExecutor
KeyDistributedExecutor
, but it does
require a scheduler implementation in order to be able to perform scheduling.
The same guarantees and restrictions for the KeyDistributedExecutor
also exist for this
class. Please read the javadoc for KeyDistributedExecutor
to understand more about how
this operates.
Constructor and Description |
---|
KeyDistributedScheduler(int expectedParallism,
SubmitterScheduler scheduler)
Deprecated.
Please use
KeyDistributedScheduler(SubmitterScheduler) |
KeyDistributedScheduler(int expectedParallism,
SubmitterScheduler scheduler,
boolean accurateQueueSize)
Deprecated.
|
KeyDistributedScheduler(int expectedParallism,
SubmitterScheduler scheduler,
int maxTasksPerCycle)
Deprecated.
|
KeyDistributedScheduler(int expectedParallism,
SubmitterScheduler scheduler,
int maxTasksPerCycle,
boolean accurateQueueSize)
Deprecated.
|
KeyDistributedScheduler(SubmitterScheduler scheduler)
Constructor to use a provided scheduler implementation for running tasks.
|
KeyDistributedScheduler(SubmitterScheduler scheduler,
boolean accurateQueueSize)
Constructor to use a provided executor implementation for running tasks.
|
KeyDistributedScheduler(SubmitterScheduler scheduler,
int maxTasksPerCycle)
Constructor to use a provided executor implementation for running tasks.
|
KeyDistributedScheduler(SubmitterScheduler scheduler,
int maxTasksPerCycle,
boolean accurateQueueSize)
Constructor to use a provided executor implementation for running tasks.
|
Modifier and Type | Method and Description |
---|---|
SubmitterScheduler |
getSchedulerForKey(java.lang.Object threadKey)
Returns a scheduler implementation where all tasks submitted on this scheduler will run on
the provided key.
|
void |
schedule(java.lang.Object threadKey,
java.lang.Runnable task,
long delayInMs)
Schedule a one time task with a given delay that will not run concurrently based off the
thread key.
|
void |
scheduleTaskAtFixedRate(java.lang.Object threadKey,
java.lang.Runnable task,
long initialDelay,
long period)
Schedule a fixed rate recurring task to run.
|
void |
scheduleTaskWithFixedDelay(java.lang.Object threadKey,
java.lang.Runnable task,
long initialDelay,
long recurringDelay)
Schedule a fixed delay recurring task to run.
|
<T> ListenableFuture<T> |
submitScheduled(java.lang.Object threadKey,
java.util.concurrent.Callable<T> task,
long delayInMs)
Schedule a
Callable with a given delay. |
ListenableFuture<?> |
submitScheduled(java.lang.Object threadKey,
java.lang.Runnable task,
long delayInMs)
Schedule a task with a given delay.
|
<T> ListenableFuture<T> |
submitScheduled(java.lang.Object threadKey,
java.lang.Runnable task,
T result,
long delayInMs)
Schedule a task with a given delay.
|
execute, getExecutor, getExecutorForKey, getTaskQueueSize, getTaskQueueSizeMap, submit, submit, submit
public KeyDistributedScheduler(SubmitterScheduler scheduler)
This constructs with a default expected level of concurrency of 16. This also does not
attempt to have an accurate queue size for the KeyDistributedExecutor.getTaskQueueSize(Object)
call (thus
preferring high performance).
scheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.public KeyDistributedScheduler(SubmitterScheduler scheduler, boolean accurateQueueSize)
This constructor allows you to specify if you want accurate queue sizes to be tracked for
given thread keys. There is a performance hit associated with this, so this should only be
enabled if KeyDistributedExecutor.getTaskQueueSize(Object)
calls will be used.
This constructs with a default expected level of concurrency of 16.
scheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.accurateQueueSize
- true
to make KeyDistributedExecutor.getTaskQueueSize(Object)
more accuratepublic KeyDistributedScheduler(SubmitterScheduler scheduler, int maxTasksPerCycle)
This constructor allows you to provide a maximum number of tasks for a key before it yields to another key. This can make it more fair, and make it so no single key can starve other keys from running. The lower this is set however, the less efficient it becomes in part because it has to give up the thread and get it again, but also because it must copy the subset of the task queue which it can run.
This constructs with a default expected level of concurrency of 16. This also does not
attempt to have an accurate queue size for the KeyDistributedExecutor.getTaskQueueSize(Object)
call (thus
preferring high performance).
scheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.maxTasksPerCycle
- maximum tasks run per key before yielding for other keyspublic KeyDistributedScheduler(SubmitterScheduler scheduler, int maxTasksPerCycle, boolean accurateQueueSize)
This constructor allows you to provide a maximum number of tasks for a key before it yields to another key. This can make it more fair, and make it so no single key can starve other keys from running. The lower this is set however, the less efficient it becomes in part because it has to give up the thread and get it again, but also because it must copy the subset of the task queue which it can run.
This also allows you to specify if you want accurate queue sizes to be tracked for given
thread keys. There is a performance hit associated with this, so this should only be enabled
if KeyDistributedExecutor.getTaskQueueSize(Object)
calls will be used.
This constructs with a default expected level of concurrency of 16.
scheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.maxTasksPerCycle
- maximum tasks run per key before yielding for other keysaccurateQueueSize
- true
to make KeyDistributedExecutor.getTaskQueueSize(Object)
more accurate@Deprecated public KeyDistributedScheduler(int expectedParallism, SubmitterScheduler scheduler)
KeyDistributedScheduler(SubmitterScheduler)
This constructor does not attempt to have an accurate queue size for the
KeyDistributedExecutor.getTaskQueueSize(Object)
call (thus preferring high performance).
expectedParallism
- IGNORED AND DEPRECATEDscheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.@Deprecated public KeyDistributedScheduler(int expectedParallism, SubmitterScheduler scheduler, boolean accurateQueueSize)
KeyDistributedScheduler(SubmitterScheduler, boolean)
This constructor allows you to specify if you want accurate queue sizes to be tracked for
given thread keys. There is a performance hit associated with this, so this should only be
enabled if KeyDistributedExecutor.getTaskQueueSize(Object)
calls will be used.
expectedParallism
- IGNORED AND DEPRECATEDscheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.accurateQueueSize
- true
to make KeyDistributedExecutor.getTaskQueueSize(Object)
more accurate@Deprecated public KeyDistributedScheduler(int expectedParallism, SubmitterScheduler scheduler, int maxTasksPerCycle)
KeyDistributedScheduler(SubmitterScheduler, int)
This constructor allows you to provide a maximum number of tasks for a key before it yields to another key. This can make it more fair, and make it so no single key can starve other keys from running. The lower this is set however, the less efficient it becomes in part because it has to give up the thread and get it again, but also because it must copy the subset of the task queue which it can run.
This constructor does not attempt to have an accurate queue size for the
KeyDistributedExecutor.getTaskQueueSize(Object)
call (thus preferring high performance).
expectedParallism
- IGNORED AND DEPRECATEDscheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.maxTasksPerCycle
- maximum tasks run per key before yielding for other keys@Deprecated public KeyDistributedScheduler(int expectedParallism, SubmitterScheduler scheduler, int maxTasksPerCycle, boolean accurateQueueSize)
KeyDistributedScheduler(SubmitterScheduler, int, boolean)
This constructor allows you to provide a maximum number of tasks for a key before it yields to another key. This can make it more fair, and make it so no single key can starve other keys from running. The lower this is set however, the less efficient it becomes in part because it has to give up the thread and get it again, but also because it must copy the subset of the task queue which it can run.
This also allows you to specify if you want accurate queue sizes to be tracked for given
thread keys. There is a performance hit associated with this, so this should only be enabled
if KeyDistributedExecutor.getTaskQueueSize(Object)
calls will be used.
expectedParallism
- IGNORED AND DEPRECATEDscheduler
- A multi-threaded scheduler to distribute tasks to. Ideally has as many
possible threads as keys that will be used in parallel.maxTasksPerCycle
- maximum tasks run per key before yielding for other keysaccurateQueueSize
- true
to make KeyDistributedExecutor.getTaskQueueSize(Object)
more accuratepublic SubmitterScheduler getSchedulerForKey(java.lang.Object threadKey)
threadKey
- object key where equals()
will be used to determine execution threadpublic void schedule(java.lang.Object threadKey, java.lang.Runnable task, long delayInMs)
threadKey
- object key where equals()
will be used to determine execution threadtask
- Task to executedelayInMs
- Time to wait to execute taskpublic ListenableFuture<?> submitScheduled(java.lang.Object threadKey, java.lang.Runnable task, long delayInMs)
submitScheduled(Object, Runnable, long)
over
schedule(Object, Runnable, long)
. So this should only be used when the future
is necessary.
The Future.get()
method will return null
once the runnable has completed.
threadKey
- object key where equals()
will be used to determine execution threadtask
- runnable to executedelayInMs
- time in milliseconds to wait to execute taskpublic <T> ListenableFuture<T> submitScheduled(java.lang.Object threadKey, java.lang.Runnable task, T result, long delayInMs)
Future.get()
method will
return null once the runnable has completed.T
- type of result returned from the futurethreadKey
- object key where equals()
will be used to determine execution threadtask
- runnable to executeresult
- result to be returned from resulting Future.get()
when runnable completesdelayInMs
- time in milliseconds to wait to execute taskpublic <T> ListenableFuture<T> submitScheduled(java.lang.Object threadKey, java.util.concurrent.Callable<T> task, long delayInMs)
Callable
with a given delay. This is needed when a result needs to be
consumed from the callable.T
- type of result returned from the futurethreadKey
- object key where equals()
will be used to determine execution threadtask
- callable to be executeddelayInMs
- time in milliseconds to wait to execute taskpublic void scheduleTaskWithFixedDelay(java.lang.Object threadKey, java.lang.Runnable task, long initialDelay, long recurringDelay)
recurringDelay + runtime
for the provided task.threadKey
- object key where equals()
will be used to determine execution threadtask
- Task to be executed.initialDelay
- Delay in milliseconds until first run.recurringDelay
- Delay in milliseconds for running task after last finish.public void scheduleTaskAtFixedRate(java.lang.Object threadKey, java.lang.Runnable task, long initialDelay, long period)
threadKey
- object key where equals()
will be used to determine execution threadtask
- runnable to be executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executions