Package org.openhab.core.scheduler
Interface Scheduler
@NonNullByDefault
public interface Scheduler
A Scheduler service provides timed semantics to CompletableFutures. A Scheduler can
delay a CompletableFutures, it can resolve a CompletableFutures at a certain time, or it can
provide a timeout to a CompletableFutures.
This scheduler has a millisecond resolution.
- Author:
- Peter Kriens - Initial contribution, Simon Kaufmann - adapted to CompletableFutures, Hilbrand Bouwkamp - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionReturn aScheduledCompletableFuture
that will resolve after the given duration.<T> ScheduledCompletableFuture<T>
Return aScheduledCompletableFuture
that resolves after delaying with the result of the call that is executed after the delay.Return aScheduledCompletableFuture
that resolves at the given epochTime<T> ScheduledCompletableFuture<T>
Return aScheduledCompletableFuture
that resolves at the given epochTime with the result of the call.default ScheduledCompletableFuture<@Nullable Void>
at
(SchedulerRunnable runnable, Instant instant) Return aScheduledCompletableFuture
that resolves at the given epochTime and runs the runnable.<T> ScheduledCompletableFuture<T>
before
(CompletableFuture<T> promise, Duration timeout) Return aScheduledCompletableFuture
that fails with aTimeoutException
when the givenCompletableFuture
is not resolved before the given timeout.<T> ScheduledCompletableFuture<T>
schedule
(SchedulerRunnable callable, @Nullable String identifier, TemporalAdjuster temporalAdjuster) Schedules the callable once or repeating using the temporalAdjuster to determine the time the callable should run.<T> ScheduledCompletableFuture<T>
schedule
(SchedulerRunnable callable, TemporalAdjuster temporalAdjuster) Schedules the callable once or repeating using the temporalAdjuster to determine the time the callable should run.
-
Method Details
-
after
Return aScheduledCompletableFuture
that resolves after delaying with the result of the call that is executed after the delay.- Parameters:
callable
- Provides the resultdelay
- The duration to wait- Returns:
- A
ScheduledCompletableFuture
-
at
Return aScheduledCompletableFuture
that resolves at the given epochTime- Parameters:
instant
- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
at
Return aScheduledCompletableFuture
that resolves at the given epochTime with the result of the call.- Parameters:
callable
- Provides the resultinstant
- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
at
Return aScheduledCompletableFuture
that resolves at the given epochTime and runs the runnable.- Parameters:
runnable
- Runs at the given epochTimeinstant
- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
before
Return aScheduledCompletableFuture
that fails with aTimeoutException
when the givenCompletableFuture
is not resolved before the given timeout. If the givenCompletableFuture
fails or is resolved before the timeout then the returnedScheduledCompletableFuture
will be treated accordingly. The cancellation does not influence the final result of the givenCompletableFuture
since aCompletableFuture
can only be failed or resolved by its creator.If the timeout is in the past then the
CompletableFuture
will be resolved immediately- Parameters:
promise
- TheCompletableFuture
to base the returnedScheduledCompletableFuture
ontimeout
- The number of milliseconds to wait.- Returns:
- A
ScheduledCompletableFuture
-
after
Return aScheduledCompletableFuture
that will resolve after the given duration. ThisScheduledCompletableFuture
can be cancelled.- Parameters:
delay
- The delay to wait- Returns:
- A
ScheduledCompletableFuture
-
schedule
<T> ScheduledCompletableFuture<T> schedule(SchedulerRunnable callable, TemporalAdjuster temporalAdjuster) Schedules the callable once or repeating using the temporalAdjuster to determine the time the callable should run. Runs until the job is cancelled or if the temporalAdjuster methodSchedulerTemporalAdjuster.isDone(java.time.temporal.Temporal)
returns true.- Parameters:
callable
- Provides the resulttemporalAdjuster
- the temperalAdjuster to return the time the callable should run- Returns:
- A
ScheduledCompletableFuture
-
schedule
<T> ScheduledCompletableFuture<T> schedule(SchedulerRunnable callable, @Nullable String identifier, TemporalAdjuster temporalAdjuster) Schedules the callable once or repeating using the temporalAdjuster to determine the time the callable should run. Runs until the job is cancelled or if the temporalAdjuster methodSchedulerTemporalAdjuster.isDone(java.time.temporal.Temporal)
returns true.- Parameters:
callable
- Provides the resultidentifier
- an optional identifier for this jobtemporalAdjuster
- the temperalAdjuster to return the time the callable should run- Returns:
- A
ScheduledCompletableFuture
-