Class DueDateChecker
- All Implemented Interfaces:
StreamProcessorLifecycleAware
This class is thread safe and can be used concurrently. However, it cannot entirely prevent
that multiple executions are scheduled. See the comment in execute(TaskResultBuilder)
for details.
-
Constructor Summary
ConstructorsConstructorDescriptionDueDateChecker
(long timerResolution, boolean scheduleAsync, Function<TaskResultBuilder, Long> visitor) -
Method Summary
Modifier and TypeMethodDescriptionvoid
onClose()
void
onFailed()
void
onPaused()
void
onRecovered
(ReadonlyStreamProcessorContext processingContext) void
void
schedule
(long dueDate) Schedules the next execution of the checker and stores it innextExecution
.
-
Constructor Details
-
DueDateChecker
public DueDateChecker(long timerResolution, boolean scheduleAsync, Function<TaskResultBuilder, Long> visitor) - Parameters:
timerResolution
- The resolution in ms for the timerscheduleAsync
- Whether to schedule the execution happens asynchronously or notvisitor
- Function that runs the task and returns the next due date or -1 if there is none
-
-
Method Details
-
schedule
public void schedule(long dueDate) Schedules the next execution of the checker and stores it innextExecution
.When called it guarantees that there is an execution scheduled at or before the provided due date within the
timerResolution
.If there is no execution scheduled, it always schedules a new one. If there is already an execution scheduled for a later time (within the timer resolution), that execution is cancelled and replaced by the new one. In all other cases, no new execution is scheduled.
It is guaranteed that the next execution is scheduled at least
timerResolution
ms into the future. For example when the due date is in the past, now or in the very near future. This is to prevent the checker from being immediately rescheduled and thus not giving any other tasks a chance to run.This method is thread safe and can be called concurrently. On concurrent scheduling, this execution is cancelled and rescheduled.
- Parameters:
dueDate
- The due date for the next execution
-
onRecovered
- Specified by:
onRecovered
in interfaceStreamProcessorLifecycleAware
-
onClose
public void onClose()- Specified by:
onClose
in interfaceStreamProcessorLifecycleAware
-
onFailed
public void onFailed()- Specified by:
onFailed
in interfaceStreamProcessorLifecycleAware
-
onPaused
public void onPaused()- Specified by:
onPaused
in interfaceStreamProcessorLifecycleAware
-
onResumed
public void onResumed()- Specified by:
onResumed
in interfaceStreamProcessorLifecycleAware
-