From 457df1e853638752621c4b55bf52aede3da1fc53 Mon Sep 17 00:00:00 2001 From: Markus Rathgeb Date: Wed, 15 May 2019 23:03:05 +0200 Subject: [PATCH] rule engine should not depend on specific registry implementation (#819) The current rule registry implementation provides a configuration for the "rule reinitialization delay". That configuration is not used by the rule registry itself but used by the rule engine implementation. This required the rule engine implementation to contain a special code path that checks if the injected rule registry is an instance of that special implementation to access that configuration parameter. As the configuration is not used by the registry itself, it does not make sense that it is a configuration of that component. If the rule engine (at least this special implementation) would like to use a configurable parameter, it should be part of that specific component implementation. Signed-off-by: Markus Rathgeb --- .../automation/internal/RuleEngineImpl.java | 17 ++++--- .../automation/internal/RuleRegistryImpl.java | 47 ++----------------- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java index e9062e6bc..5baff6c57 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java @@ -74,6 +74,7 @@ import org.openhab.core.automation.type.TriggerType; import org.openhab.core.automation.util.ReferenceResolver; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.ComponentPropertyType; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; @@ -103,6 +104,14 @@ import org.slf4j.LoggerFactory; @NonNullByDefault public class RuleEngineImpl implements RuleManager, RegistryChangeListener { + @ComponentPropertyType + public @interface Config { + /** + * Delay between rule's re-initialization tries. + */ + long rule_reinitialization_delay() default 500; + } + /** * Constant defining separator between module id and output name. */ @@ -240,7 +249,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener>(); this.moduleHandlerFactories = new HashMap(20); @@ -255,11 +264,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener() { @Override diff --git a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java index ad38bac31..a4a9d3107 100644 --- a/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java +++ b/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleRegistryImpl.java @@ -49,7 +49,6 @@ import org.osgi.framework.BundleContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Modified; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; @@ -100,28 +99,14 @@ import org.slf4j.LoggerFactory; * @author Benedikt Niehues - added events for rules * @author Victor Toni - return only copies of {@link Rule}s */ -@Component(service = RuleRegistry.class, immediate = true, property = { "rule.reinitialization.delay:Long=500" }) +@Component(service = RuleRegistry.class, immediate = true) public class RuleRegistryImpl extends AbstractRegistry implements RuleRegistry, RegistryChangeListener { - /** - * Default value of delay between rule's re-initialization tries. - */ - static final long DEFAULT_REINITIALIZATION_DELAY = 500; - - /** - * Delay between rule's re-initialization tries. - */ - private static final String CONFIG_PROPERTY_REINITIALIZATION_DELAY = "rule.reinitialization.delay"; - private static final String SOURCE = RuleRegistryImpl.class.getSimpleName(); private final Logger logger = LoggerFactory.getLogger(RuleRegistryImpl.class.getName()); - /** - * Delay between rule's re-initialization tries. - */ - private long scheduleReinitializationDelay; private ModuleTypeRegistry moduleTypeRegistry; private RuleTemplateRegistry templateRegistry; @@ -143,27 +128,12 @@ public class RuleRegistryImpl extends AbstractRegistry properties) throws Exception { - modified(properties); + protected void activate(BundleContext bundleContext) { super.activate(bundleContext); } - /** - * This method is responsible for updating the value of delay between rule's re-initialization tries. - * - * @param config a {@link Map} containing the new value of delay. - */ - @Modified - protected void modified(Map config) { - Object value = config == null ? null : config.get(CONFIG_PROPERTY_REINITIALIZATION_DELAY); - this.scheduleReinitializationDelay = (value != null && value instanceof Number) ? (((Number) value).longValue()) - : DEFAULT_REINITIALIZATION_DELAY; - if (value != null && !(value instanceof Number)) { - logger.warn("Invalid configuration value: {}. It MUST be Number.", value); - } - } - @Override @Deactivate protected void deactivate() { @@ -678,15 +648,4 @@ public class RuleRegistryImpl extends AbstractRegistry