Disable updates when we are stopping 79/83579/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 6 Aug 2019 17:48:05 +0000 (19:48 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 13 Aug 2019 07:27:56 +0000 (07:27 +0000)
We should not be propagating bundle updates when we know we are
stopping. This patch marks that knowledge in the tracker.

JIRA: MDSAL-466
Change-Id: Ie4e8b96907a8909150b4080000888d1d10ce8e54
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 7a739663d766c8ee83fb17e0e4199a3945ad674f)

binding/mdsal-binding-dom-codec-osgi/src/main/java/org/opendaylight/mdsal/binding/dom/codec/osgi/impl/Activator.java
binding/mdsal-binding-dom-codec-osgi/src/main/java/org/opendaylight/mdsal/binding/dom/codec/osgi/impl/ModuleInfoBundleTracker.java

index 0c6ed145fdd1a9d3c58fbdbc4f72d719cdb7613d..a44117f09b1968ff288b0abfa97497b63267a712 100644 (file)
@@ -8,14 +8,10 @@
 package org.opendaylight.mdsal.binding.dom.codec.osgi.impl;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import org.opendaylight.mdsal.binding.dom.codec.osgi.BindingRuntimeContextService;
 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -24,7 +20,7 @@ import org.osgi.util.tracker.BundleTracker;
 public final class Activator implements BundleActivator {
     private final List<ServiceRegistration<?>> registrations = new ArrayList<>(2);
 
-    private BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> moduleInfoResolvedBundleTracker = null;
+    private BundleTracker<?> moduleInfoResolvedBundleTracker = null;
     private SimpleBindingRuntimeContextService service = null;
 
     @Override
@@ -37,11 +33,8 @@ public final class Activator implements BundleActivator {
         final OsgiModuleInfoRegistry registry = new OsgiModuleInfoRegistry(moduleInfoBackedContext,
                 moduleInfoBackedContext, service);
 
-        final ModuleInfoBundleTracker moduleInfoTracker = new ModuleInfoBundleTracker(registry);
-        moduleInfoResolvedBundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING
-                | Bundle.STOPPING | Bundle.ACTIVE, moduleInfoTracker);
+        moduleInfoResolvedBundleTracker = new ModuleInfoBundleTracker(context, registry);
         moduleInfoResolvedBundleTracker.open();
-        moduleInfoTracker.finishStart();
 
         service.open();
         registrations.add(context.registerService(BindingRuntimeContextService.class, service, null));
index aeecbbbb9247b328dcb92cd5f94d7b6eae5edc20..0d9df8e4d332e7d11ccb2b5fff428ec52f6fae53 100644 (file)
@@ -23,15 +23,16 @@ import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
+import org.osgi.util.tracker.BundleTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry.
  */
-final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
+final class ModuleInfoBundleTracker extends BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> {
     private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
     // FIXME: this should be in a place shared with maven-sal-api-gen-plugin
     private static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/";
@@ -43,17 +44,26 @@ final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collectio
 
     private final OsgiModuleInfoRegistry moduleInfoRegistry;
 
-    private volatile boolean starting = true;
+    private volatile boolean deferUpdates = true;
 
-    ModuleInfoBundleTracker(final OsgiModuleInfoRegistry moduleInfoRegistry) {
+    ModuleInfoBundleTracker(final BundleContext context, final OsgiModuleInfoRegistry moduleInfoRegistry) {
+        super(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null);
         this.moduleInfoRegistry = requireNonNull(moduleInfoRegistry);
     }
 
-    void finishStart() {
-        starting = false;
+    @Override
+    public void open() {
+        super.open();
+        deferUpdates = false;
         moduleInfoRegistry.updateService();
     }
 
+    @Override
+    public void close() {
+        deferUpdates = true;
+        super.close();
+    }
+
     @Override
     @SuppressWarnings("checkstyle:illegalCatch")
     public Collection<ObjectRegistration<YangModuleInfo>> addingBundle(final Bundle bundle, final BundleEvent event) {
@@ -91,7 +101,7 @@ final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collectio
             registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
         }
 
-        if (!starting) {
+        if (!deferUpdates) {
             moduleInfoRegistry.updateService();
         }