Class TaskRecord
- All Implemented Interfaces:
TaskHandle
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) final classEach delivery publishes its own handle so an early callback cannot overwrite its successor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Consumer<? super TaskHandle> private final Contextprivate final CompletableFuture<Void> private final Set<TaskRecord.Delivery> private final longprivate final Objectprivate final AtomicReference<TaskState> private final @Nullable CompletableFuture<?> -
Constructor Summary
ConstructorsConstructorDescriptionTaskRecord(Context context, Consumer<? super TaskHandle> body, long period, @Nullable CompletableFuture<?> supplyFuture) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidbodyFailed(Throwable failure) booleancancel()Prevents every run that has not started.Completes when the task will never run again: normally after a successful one-shot; exceptionally with its thrown exception forTaskState.FAILED,CancellationExceptionforTaskState.CANCELLED(including owner unload), orTaskRetiredExceptionforTaskState.RETIRED.private voidprivate voidprivate voidprivate voidfinishPending(TaskState terminal, Throwable failure) booleanReturns whether this task was submitted withTaskContext.runRepeating(Duration, Duration, Consumer).private booleanprivate void(package private) voidschedule(long delay) private booleanstate()Returns the current lifecycle state.(package private) voidsubmissionFailed(Throwable failure) private void
-
Field Details
-
context
-
body
-
period
private final long period -
supplyFuture
-
state
-
done
-
pending
-
repeatLock
-
-
Constructor Details
-
TaskRecord
TaskRecord(Context context, Consumer<? super TaskHandle> body, long period, @Nullable @Nullable CompletableFuture<?> supplyFuture)
-
-
Method Details
-
state
Description copied from interface:TaskHandleReturns the current lifecycle state.- Specified by:
statein interfaceTaskHandle
-
isRepeating
public boolean isRepeating()Description copied from interface:TaskHandleReturns whether this task was submitted withTaskContext.runRepeating(Duration, Duration, Consumer).- Specified by:
isRepeatingin interfaceTaskHandle
-
completion
Description copied from interface:TaskHandleCompletes when the task will never run again: normally after a successful one-shot; exceptionally with its thrown exception forTaskState.FAILED,CancellationExceptionforTaskState.CANCELLED(including owner unload), orTaskRetiredExceptionforTaskState.RETIRED.A one-shot body failure from
TaskContext.run(Runnable),TaskContext.runLater(java.time.Duration, Runnable)orTaskContext.execute(Runnable)is also logged exactly once at WARNING with its owner's name and original throwable. ATaskContext.supply(java.util.function.Supplier)failure is reported only through its future unless that future was cancelled after the body started.This is a minimal stage: callers cannot complete or cancel the task through it. Non-async dependent actions run on the thread completing the stage.
- Specified by:
completionin interfaceTaskHandle
-
cancel
public boolean cancel()Description copied from interface:TaskHandlePrevents every run that has not started. Never interrupts a run in progress. Idempotent.A one-shot task that is already
TaskState.RUNNINGcannot be cancelled: this returnsfalseand the task still endsTaskState.COMPLETEDorTaskState.FAILED(as Paper'sScheduledTask#cancel()reportsRUNNING). For a repeating task whose run is in progress this returnstrue, the state becomesTaskState.CANCELLEDat once andTaskHandle.completion()completes with aCancellationException; the current run finishes, and an exception it throws is logged with the owner's name like any other repeating failure.- Specified by:
cancelin interfaceTaskHandle- Returns:
trueonly for the call that moved the task toTaskState.CANCELLED
-
schedule
void schedule(long delay) -
executeBody
private void executeBody() -
executeClaimed
private void executeClaimed() -
bodyFailed
-
scheduleNext
private boolean scheduleNext() -
retireEntity
private void retireEntity() -
submissionFailed
-
finishPending
-
isTerminal
private boolean isTerminal() -
finish
-
warn
-