use of org.openhab.core.scheduler.SchedulerTemporalAdjuster in project openhab-core by openhab.
the class RuleExecutionSimulator method simulateExecutionsForRule.
/**
* Simulates the next executions for the given {@link Rule} until the given {@link Date}.
*
* @param rule {@link Rule} to be simulated.
* @param from {@link ZonedDateTime} earliest time to be contained in the rule simulation.
* @param until {@link ZonedDateTime} latest time to be contained in the rule simulation.
* @return List of expected {@link RuleExecution}.
*/
private List<RuleExecution> simulateExecutionsForRule(Rule rule, ZonedDateTime from, ZonedDateTime until) {
final List<RuleExecution> executions = new ArrayList<>();
for (Trigger trigger : rule.getTriggers()) {
TriggerHandler triggerHandler = (TriggerHandler) this.ruleEngine.getModuleHandler(trigger, rule.getUID());
// Only triggers that are time-based will be considered within the simulation
if (triggerHandler instanceof TimeBasedTriggerHandler) {
SchedulerTemporalAdjuster temporalAdjuster = ((TimeBasedTriggerHandler) triggerHandler).getTemporalAdjuster();
if (temporalAdjuster != null) {
executions.addAll(simulateExecutionsForCronBasedRule(rule, from, until, temporalAdjuster));
}
}
}
logger.debug("Created {} rule simulations for rule {}.", executions.size(), rule.getName());
return executions;
}
use of org.openhab.core.scheduler.SchedulerTemporalAdjuster in project openhab-core by openhab.
the class SchedulerImpl method schedule.
private <T> void schedule(ScheduledCompletableFutureRecurring<T> recurringSchedule, SchedulerRunnable runnable, TemporalAdjuster temporalAdjuster) {
final Temporal newTime = recurringSchedule.getScheduledTime().with(temporalAdjuster);
final ScheduledCompletableFutureOnce<T> deferred = new ScheduledCompletableFutureOnce<>(ZonedDateTime.from(newTime));
deferred.thenAccept(v -> {
if (temporalAdjuster instanceof SchedulerTemporalAdjuster) {
final SchedulerTemporalAdjuster schedulerTemporalAdjuster = (SchedulerTemporalAdjuster) temporalAdjuster;
if (!schedulerTemporalAdjuster.isDone(newTime)) {
schedule(recurringSchedule, runnable, temporalAdjuster);
return;
}
}
recurringSchedule.complete(v);
});
recurringSchedule.setScheduledPromise(deferred);
atInternal(deferred, () -> {
runnable.run();
return null;
});
}
Aggregations