diff --git a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/ConfigXmlConfigDescriptionProvider.java b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/ConfigXmlConfigDescriptionProvider.java index 25d232c23..56d06b468 100644 --- a/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/ConfigXmlConfigDescriptionProvider.java +++ b/bundles/org.openhab.core.config.xml/src/main/java/org/eclipse/smarthome/config/xml/ConfigXmlConfigDescriptionProvider.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.ConfigDescription; import org.eclipse.smarthome.config.core.ConfigDescriptionProvider; import org.eclipse.smarthome.config.core.i18n.ConfigI18nLocalizationService; @@ -40,25 +42,30 @@ import org.osgi.service.component.annotations.Reference; * @author Simon Kaufmann - Initial contribution */ @Component(service = ConfigDescriptionProvider.class, immediate = true, property = { "esh.scope=core.xml.config" }) +@NonNullByDefault public class ConfigXmlConfigDescriptionProvider extends AbstractXmlConfigDescriptionProvider implements XmlDocumentProviderFactory> { private static final String XML_DIRECTORY = "/ESH-INF/config/"; public static final String READY_MARKER = "esh.xmlConfig"; - private XmlDocumentBundleTracker> configDescriptionTracker; - - private ConfigI18nLocalizationService configI18nLocalizerService; - private ReadyService readyService; - - private ScheduledExecutorService scheduler = ThreadPoolManager + private final ConfigI18nLocalizationService configI18nService; + private @Nullable XmlDocumentBundleTracker> configDescriptionTracker; + private final ReadyService readyService; + private final ScheduledExecutorService scheduler = ThreadPoolManager .getScheduledPool(XmlDocumentBundleTracker.THREAD_POOL_NAME); - private Future trackerJob; + private @Nullable Future trackerJob; + + @Activate + public ConfigXmlConfigDescriptionProvider(final @Reference ConfigI18nLocalizationService configI18nService, + final @Reference ReadyService readyService) { + this.configI18nService = configI18nService; + this.readyService = readyService; + } @Activate public void activate(ComponentContext componentContext) { XmlDocumentReader> configDescriptionReader = new ConfigDescriptionReader(); - configDescriptionTracker = new XmlDocumentBundleTracker<>(componentContext.getBundleContext(), XML_DIRECTORY, configDescriptionReader, this, READY_MARKER, readyService); trackerJob = scheduler.submit(() -> { @@ -68,40 +75,25 @@ public class ConfigXmlConfigDescriptionProvider extends AbstractXmlConfigDescrip @Deactivate public void deactivate() { - if (trackerJob != null && !trackerJob.isDone()) { - trackerJob.cancel(true); + Future localTrackerJob = trackerJob; + if (localTrackerJob != null && !localTrackerJob.isDone()) { + localTrackerJob.cancel(true); trackerJob = null; } - configDescriptionTracker.close(); - configDescriptionTracker = null; - } - - @Reference - public void setConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) { - this.configI18nLocalizerService = configI18nLocalizerService; - } - - public void unsetConfigI18nLocalizerService(ConfigI18nLocalizationService configI18nLocalizerService) { - this.configI18nLocalizerService = null; - } - - @Reference - public void setReadyService(ReadyService readyService) { - this.readyService = readyService; - } - - public void unsetReadyService(ReadyService readyService) { - this.readyService = null; + XmlDocumentBundleTracker> localConfigDescriptionTracker = configDescriptionTracker; + if (localConfigDescriptionTracker != null) { + localConfigDescriptionTracker.close(); + configDescriptionTracker = null; + } } @Override protected ConfigI18nLocalizationService getConfigI18nLocalizerService() { - return configI18nLocalizerService; + return configI18nService; } @Override public XmlDocumentProvider> createDocumentProvider(Bundle bundle) { return new ConfigDescriptionXmlProvider(bundle, this); } - }