Be sure to shutdown instance when destroyed 85/10185/1
authorRobert Varga <rovarga@cisco.com>
Fri, 22 Aug 2014 14:24:55 +0000 (16:24 +0200)
committerRobert Varga <rovarga@cisco.com>
Fri, 22 Aug 2014 14:24:55 +0000 (16:24 +0200)
This cleans up any resources held by the instance.

Change-Id: I669264d01c5e77b6cd59cab807e15e9bbf24c16d
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java

index 82637327f6b10d719c04e4fa04ad6a7b53b2dafe..c4418c7911a79b6d786c7a47a638e87ceffa59bc 100644 (file)
@@ -10,6 +10,10 @@ package org.opendaylight.controller.sal.dom.broker;
 import static com.google.common.base.Preconditions.checkState;
 
 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 java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -20,7 +24,7 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProvider;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
+import org.opendaylight.yangtools.util.ListenerRegistry;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
@@ -36,10 +40,6 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-
 public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvider, SchemaService, ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(GlobalBundleScanningSchemaServiceImpl.class);
 
@@ -71,7 +71,11 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
 
     @VisibleForTesting
     public static synchronized void destroyInstance() {
-        instance = null;
+        try {
+            instance.close();
+        } finally {
+            instance = null;
+        }
     }
 
     public BundleContext getContext() {
@@ -124,16 +128,18 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
         if (bundleTracker != null) {
             bundleTracker.close();
         }
         if (listenerTracker != null) {
             listenerTracker.close();
         }
-        // FIXME: Add listeners.close();
-    }
 
+        for (ListenerRegistration<SchemaContextListener> l : listeners.getListeners()) {
+            l.close();
+        }
+    }
 
     private synchronized void updateContext(final SchemaContext snapshot) {
         Object[] services = listenerTracker.getServices();