diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/delegates/SimpleTriggerHandlerCallbackDelegate.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/delegates/SimpleTriggerHandlerCallbackDelegate.java index b102e8844e8..097ce1e0f45 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/delegates/SimpleTriggerHandlerCallbackDelegate.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/delegates/SimpleTriggerHandlerCallbackDelegate.java @@ -13,6 +13,7 @@ package org.openhab.core.automation.module.script.rulesupport.internal.delegates; import java.util.Map; +import java.util.concurrent.ScheduledExecutorService; import org.openhab.core.automation.RuleStatus; import org.openhab.core.automation.RuleStatusInfo; @@ -44,6 +45,11 @@ public void triggered(Map context) { callback.triggered(this.trigger, context); } + @Override + public ScheduledExecutorService getScheduler() { + return callback.getScheduler(); + } + @Override public Boolean isEnabled(String ruleUID) { return callback.isEnabled(ruleUID); diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/handler/TriggerHandlerCallback.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/handler/TriggerHandlerCallback.java index cb27dfe456a..0c71651d5ca 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/handler/TriggerHandlerCallback.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/handler/TriggerHandlerCallback.java @@ -13,6 +13,7 @@ package org.openhab.core.automation.handler; import java.util.Map; +import java.util.concurrent.ScheduledExecutorService; import org.openhab.core.automation.ModuleHandlerCallback; import org.openhab.core.automation.Rule; @@ -27,6 +28,7 @@ * * @author Yordan Mihaylov - Initial contribution * @author Kai Kreuzer - made it a sub-interface of ModuleHandlerCallback + * @author Fabian Wolter - Add method for retrieving the handler's scheduler */ public interface TriggerHandlerCallback extends ModuleHandlerCallback { @@ -45,4 +47,9 @@ public interface TriggerHandlerCallback extends ModuleHandlerCallback { * */ public void triggered(Trigger trigger, Map context); + + /** + * @return the scheduler of this rule + */ + public ScheduledExecutorService getScheduler(); } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/TriggerHandlerCallbackImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/TriggerHandlerCallbackImpl.java index b449eb2ea05..33f62c54315 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/TriggerHandlerCallbackImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/TriggerHandlerCallbackImpl.java @@ -15,9 +15,9 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Map; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.ScheduledExecutorService; import org.openhab.core.automation.RuleStatus; import org.openhab.core.automation.RuleStatusInfo; @@ -32,12 +32,13 @@ * * @author Yordan Mihaylov - Initial contribution * @author Kai Kreuzer - improved stability + * @author Fabian Wolter - Change executor to ScheduledExecutorService and expose it */ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback { private final String ruleUID; - private ExecutorService executor; + private ScheduledExecutorService executor; private Future future; @@ -46,7 +47,7 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback { protected TriggerHandlerCallbackImpl(RuleEngineImpl re, String ruleUID) { this.re = re; this.ruleUID = ruleUID; - executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("rule-" + ruleUID)); + executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("rule-" + ruleUID)); } @Override @@ -129,4 +130,9 @@ public void runNow(String uid) { public void runNow(String uid, boolean considerConditions, Map context) { re.runNow(uid, considerConditions, context); } + + @Override + public ScheduledExecutorService getScheduler() { + return executor; + } } diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java index a54cdb7cf4b..6804f4c1613 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeTriggerHandler.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; +import java.util.concurrent.ScheduledExecutorService; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.automation.ModuleHandlerCallback; @@ -104,6 +105,11 @@ public void triggered(Trigger trigger, Map context) { } } + @Override + public ScheduledExecutorService getScheduler() { + return callback.getScheduler(); + } + /** * The {@link CompositeTriggerHandler} sets itself as callback to the child triggers and store the callback to the * rule engine. In this way the trigger of composite type will be notified always when some of the child triggers