Reduce SchemaContext updates on shutdown
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / GlobalBundleScanningSchemaServiceImpl.java
index 68edea7d754657927936d8cc28eae8f573855e44..34c11ddc9240c3f3305ff62814d7cd59101b3985 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -81,13 +82,20 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
 
     public void start() {
         checkState(context != null);
+        LOG.debug("start() starting");
 
         listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class, GlobalBundleScanningSchemaServiceImpl.this);
-        bundleTracker = new BundleTracker<>(context, BundleEvent.RESOLVED | BundleEvent.UNRESOLVED, scanner);
+        bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING |
+                Bundle.STOPPING | Bundle.ACTIVE, scanner);
         bundleTracker.open();
+
+        LOG.debug("BundleTracker.open() complete");
+
         listenerTracker.open();
         starting = false;
         tryToUpdateSchemaContext();
+
+        LOG.debug("start() complete");
     }
 
     @Override
@@ -184,7 +192,8 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
             }
 
             if (!urls.isEmpty()) {
-                LOG.debug("Loaded {} new URLs, rebuilding schema context", urls.size());
+                LOG.debug("Loaded {} new URLs from bundle {}, attempting to rebuild schema context",
+                        urls.size(), bundle.getSymbolicName());
                 tryToUpdateSchemaContext();
             }
 
@@ -193,7 +202,6 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
 
         @Override
         public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable<Registration> object) {
-            LOG.debug("Modified bundle {} {} {}", bundle, event, object);
         }
 
         /**
@@ -211,7 +219,15 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
                     LOG.warn("Failed do unregister URL {}, proceeding", url, e);
                 }
             }
-            tryToUpdateSchemaContext();
+
+            int numUrls = Iterables.size(urls);
+            if(numUrls > 0 ) {
+                if(LOG.isDebugEnabled()) {
+                    LOG.debug("removedBundle: {}, state: {}, # urls: {}", bundle.getSymbolicName(), bundle.getState(), numUrls);
+                }
+
+                tryToUpdateSchemaContext();
+            }
         }
     }
 
@@ -232,6 +248,10 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
         }
         Optional<SchemaContext> schema = contextResolver.getSchemaContext();
         if(schema.isPresent()) {
+            if(LOG.isDebugEnabled()) {
+                LOG.debug("Got new SchemaContext: # of modules {}", schema.get().getAllModuleIdentifiers().size());
+            }
+
             updateContext(schema.get());
         }
     }