Interface TaskHandle
public interface TaskHandle
Represents a scheduled task that can be controlled at runtime.
-
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Cancels the task.Returns the period of a repeating task.Returns the remaining delay before the next run.id()booleanbooleanisPaused()booleanbooleanbooleanpause()Pauses the task.booleanToggles between paused and unpaused.booleanresume()Resumes the task if paused.booleanrunNow()Runs the task immediately if possible.
-
Method Details
-
cancel
boolean cancel()Cancels the task.- Returns:
- true if the task was canceled, false otherwise
-
pause
boolean pause()Pauses the task.
Note: Returns false if the task is already paused or canceled.- Returns:
- true if the task was paused, false otherwise
-
resume
boolean resume()Resumes the task if paused.
Note: Returns false if the task is not paused or is canceled.- Returns:
- true if resumed, false otherwise
-
pauseOrUnpause
boolean pauseOrUnpause()Toggles between paused and unpaused.- Returns:
- true if the state changed, false otherwise
-
isCancelled
boolean isCancelled()- Returns:
- true if the task has been canceled
-
isPaused
boolean isPaused() -
isRunning
boolean isRunning() -
isScheduled
boolean isScheduled()- Returns:
- true if the task is scheduled for execution
-
getRemainingDelay
Returns the remaining delay before the next run.- Returns:
- remaining delay, or empty if canceled
-
getPeriod
Returns the period of a repeating task.- Returns:
- the period, or empty if not repeating
-
runNow
boolean runNow()Runs the task immediately if possible.- Returns:
- true if the task was executed
-
id
String id()- Returns:
- unique ID of this task
-