public interface TaskBuilder
Task
.Modifier and Type | Method and Description |
---|---|
TaskBuilder |
async()
Sets whether the task should run asynchronous, outside of the main loop,
and in it's own thread.
|
TaskBuilder |
delay(long delay)
Sets the delay before the task runs, in the default time unit.
|
TaskBuilder |
delay(long delay,
TimeUnit unit)
Sets the delay before the task runs.
|
TaskBuilder |
execute(Runnable runnable)
Sets the
Runnable to run when this task executes. |
TaskBuilder |
interval(long ticks)
Sets the interval in ticks between repetitions of the task, in the
default time unit.
|
TaskBuilder |
interval(long interval,
TimeUnit unit)
Sets the interval between repetitions of the task.
|
TaskBuilder |
name(String name)
Sets the name of the task, the name cannot be blank.
|
Task |
submit(Object plugin)
Submits the task to the scheduler and returns the task that was created.
|
TaskBuilder async()
A synchronous task is ran in alignment with the game's main loop, in the same thread. Each synchronous task is ran in series with the tick cycle. It is safe to manipulate game data when running in this mode.
In contrast, a task set to run asynchronously will run independently of the tick cycle and in it's own thread. Therefore the task is not thread safe with game data and care must be taken. It is strongly advised to not manipulate game data in asynchronous tasks.
It is not possible to schedule a task in unit ticks when running
asynchronously. If the delay or interval has been specified in ticks
(methods delay(long)
and interval(long)
), it will be
converted to the equivalent wall clock time by the implementation. After
this point, calls to the two methods mentioned will set the time in
milliseconds as mentioned in their javadoc.
TaskBuilder execute(Runnable runnable)
Runnable
to run when this task executes.runnable
- The actual task to runTaskBuilder delay(long delay, TimeUnit unit)
delay
- The delay in the given TimeUnit
unit
- The unit the delay is inIllegalArgumentException
- If the delay is below 0TaskBuilder delay(long delay)
async()
has not been called this represents the number of
ticks. Otherwise this will set the delay in milliseconds.delay
- The delay in the default time unitIllegalArgumentException
- If the delay is below 0delay(long, TimeUnit)
TaskBuilder interval(long interval, TimeUnit unit)
If the scheduler detects that two tasks will overlap, the 2nd task will not be started. The next time the task is due to run, the test will be made again to determine if the previous occurrence of the task is still alive (running). As long as a previous occurrence is running no new occurrences of that specific task will start, although the scheduler will never cease in trying to start it a 2nd time.
interval
- The interval in the given TimeUnit
unit
- The unit the interval is inIllegalArgumentException
- If the interval is below 0TaskBuilder interval(long ticks)
async()
has not been called this
represents the number of ticks. Otherwise this will set the interval in
milliseconds.ticks
- The number of ticks between runsIllegalArgumentException
- If the interval is below 0interval(long, TimeUnit)
TaskBuilder name(String name)
If the name is not set in the builder, the name of the task will be
the form:
PLUGIN_ID "-" ( "A-" | "S-" ) SERIAL_ID
Examples of default Task names:
"FooPlugin-A-12"
"BarPlugin-S-4322"
No two active tasks will have the same serial ID for the same
synchronisation type.
i.e APlugin-A-15 and
BPlugin-A-15 is not possible but BPlugin-S-15 is.
name
- The task nameIllegalArgumentException
- If the name is blankTask submit(Object plugin)
plugin
- The owner of the taskTask
IllegalArgumentException
- If the object passed in is not a plugin
instanceIllegalStateException
- If the builder is incomplete