Interface Task.Builder
-
- All Superinterfaces:
Buildable.Builder<Task>
,Builder<Task,Task.Builder>
,CopyableBuilder<Task,Task.Builder>
,ResettableBuilder<Task,Task.Builder>
- Enclosing interface:
- Task
public static interface Task.Builder extends Builder<Task,Task.Builder>, CopyableBuilder<Task,Task.Builder>
Represents a builder to create aTask
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Task
build()
Builds the task.default Task.Builder
delay(long delay, TemporalUnit unit)
Sets the delay before the task runs.default Task.Builder
delay(long delay, TimeUnit unit)
Sets the delay before the task runs.Task.Builder
delay(Duration delay)
Sets the delay before the task runs.Task.Builder
delay(Ticks ticks)
Sets the delay before the task runs, inTicks
.default Task.Builder
execute(Runnable runnable)
Sets theRunnable
to run when this task executes.Task.Builder
execute(Consumer<ScheduledTask> executor)
Sets the consumer that runs when this task executes.default Task.Builder
interval(long interval, TemporalUnit unit)
Sets the interval between repetitions of the task.default Task.Builder
interval(long interval, TimeUnit unit)
Sets the interval between repetitions of the task.Task.Builder
interval(Duration interval)
Sets the interval between repetitions of the task.Task.Builder
interval(Ticks ticks)
Sets the interval in unit ticks between repetitions of the task.Task.Builder
plugin(org.spongepowered.plugin.PluginContainer plugin)
Sets the plugin of the task.-
Methods inherited from interface org.spongepowered.api.util.CopyableBuilder
from
-
-
-
-
Method Detail
-
execute
default Task.Builder execute(Runnable runnable)
Sets theRunnable
to run when this task executes.- Parameters:
runnable
- The actual task to run- Returns:
- This builder, for chaining
-
execute
Task.Builder execute(Consumer<ScheduledTask> executor)
Sets the consumer that runs when this task executes.- Parameters:
executor
- The executor to run- Returns:
- This builder, for chaining
-
delay
default Task.Builder delay(long delay, TemporalUnit unit)
Sets the delay before the task runs. This delay is an initial offset, subsequent runs (when the interval is not 0) will not be offset. By default, the delay is 0.- Parameters:
delay
- The delay in the givenTemporalUnit
unit
- The unit the delay is in- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the delay is below 0
-
delay
default Task.Builder delay(long delay, TimeUnit unit)
Sets the delay before the task runs. This delay is an initial offset, subsequent runs (when the interval is not 0) will not be offset. By default, the delay is 0.- Parameters:
delay
- The delay in the givenTimeUnit
unit
- The unit the delay is in- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the delay is below 0
-
delay
Task.Builder delay(Ticks ticks)
Sets the delay before the task runs, inTicks
.- Parameters:
ticks
- The delay in ticks- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the delay is below 0
-
delay
Task.Builder delay(Duration delay)
Sets the delay before the task runs. This delay is an initial offset, subsequent runs (when the interval is not 0) will not be offset. By default, the delay is 0.- Parameters:
delay
- The delay duration- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the delay duration is below 0
-
interval
Task.Builder interval(Duration interval)
Sets the interval between repetitions of the task. The task will not repeat if the interval is 0. By default, the interval is 0.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.
- Parameters:
interval
- The interval duration- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the interval is below 0
-
interval
default Task.Builder interval(long interval, TemporalUnit unit)
Sets the interval between repetitions of the task. The task will not repeat if the interval is 0. By default, the interval is 0.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.
- Parameters:
interval
- The interval in the givenTemporalUnit
unit
- The unit the interval is in- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the interval is below 0
-
interval
default Task.Builder interval(long interval, TimeUnit unit)
Sets the interval between repetitions of the task. The task will not repeat if the interval is 0. By default, the interval is 0.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.
- Parameters:
interval
- The interval in the givenTimeUnit
unit
- The unit the interval is in- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the interval is below 0
-
interval
Task.Builder interval(Ticks ticks)
Sets the interval in unit ticks between repetitions of the task.- Parameters:
ticks
- TheTicks
between runs.- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the interval is below 0
-
plugin
Task.Builder plugin(org.spongepowered.plugin.PluginContainer plugin)
Sets the plugin of the task.- Parameters:
plugin
- The plugin instance- Returns:
- This builder, for chaining
- Throws:
IllegalArgumentException
- If the given object isn't a valid plugin
-
build
Task build()
Builds the task.- Specified by:
build
in interfaceBuildable.Builder<Task>
- Returns:
- A new instance of a
Task
- Throws:
IllegalStateException
- If theexecute(Runnable)
isn't set or in the case thatplugin(PluginContainer)
isn't set.
-
-