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 aScheduledCompletableFuturethat will resolve after the given duration.<T> ScheduledCompletableFuture<T> Return aScheduledCompletableFuturethat resolves after delaying with the result of the call that is executed after the delay.Return aScheduledCompletableFuturethat resolves at the given epochTime<T> ScheduledCompletableFuture<T> Return aScheduledCompletableFuturethat resolves at the given epochTime with the result of the call.default ScheduledCompletableFuture<@Nullable Void> at(SchedulerRunnable runnable, Instant instant) Return aScheduledCompletableFuturethat resolves at the given epochTime and runs the runnable.<T> ScheduledCompletableFuture<T> before(CompletableFuture<T> promise, Duration timeout) Return aScheduledCompletableFuturethat fails with aTimeoutExceptionwhen the givenCompletableFutureis 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 aScheduledCompletableFuturethat 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 aScheduledCompletableFuturethat resolves at the given epochTime- Parameters:
instant- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
at
Return aScheduledCompletableFuturethat resolves at the given epochTime with the result of the call.- Parameters:
callable- Provides the resultinstant- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
at
Return aScheduledCompletableFuturethat resolves at the given epochTime and runs the runnable.- Parameters:
runnable- Runs at the given epochTimeinstant- The epoch time- Returns:
- A
ScheduledCompletableFuture
-
before
Return aScheduledCompletableFuturethat fails with aTimeoutExceptionwhen the givenCompletableFutureis not resolved before the given timeout. If the givenCompletableFuturefails or is resolved before the timeout then the returnedScheduledCompletableFuturewill be treated accordingly. The cancellation does not influence the final result of the givenCompletableFuturesince aCompletableFuturecan only be failed or resolved by its creator.If the timeout is in the past then the
CompletableFuturewill be resolved immediately- Parameters:
promise- TheCompletableFutureto base the returnedScheduledCompletableFutureontimeout- The number of milliseconds to wait.- Returns:
- A
ScheduledCompletableFuture
-
after
Return aScheduledCompletableFuturethat will resolve after the given duration. ThisScheduledCompletableFuturecan 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
-