diff --git a/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java b/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java index aa798747..04e7d37f 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java +++ b/src/main/java/org/openhab/automation/jrule/internal/engine/JRuleEngine.java @@ -414,6 +414,11 @@ public synchronized void reset() { ruleProvider.reset(); } + public void removeDynamic(Method method, JRule jRule) { + contextList.removeIf((executionContext) -> executionContext.getMethod().equals(method)); + ruleProvider.remove(jRule, method); + } + public boolean watchingForItem(String itemName) { if (itemRegistry == null) { // JRuleEngine not completely initialized diff --git a/src/main/java/org/openhab/automation/jrule/internal/module/JRuleRuleProvider.java b/src/main/java/org/openhab/automation/jrule/internal/module/JRuleRuleProvider.java index bcf18306..28b707c8 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/module/JRuleRuleProvider.java +++ b/src/main/java/org/openhab/automation/jrule/internal/module/JRuleRuleProvider.java @@ -85,6 +85,14 @@ public void reset() { rules.clear(); } + public void remove(JRule rule, Method method) { + JRuleModuleEntry entry = rules.get(JRuleModuleEntry.createUid(rule, method)); + if (entry != null) { + listeners.stream().forEach(e -> e.removed(this, entry)); + entry.dispose(); + } + } + public void add(JRuleModuleEntry entry) { rules.put(entry.getUID(), entry); listeners.stream().forEach(e -> e.added(this, entry));