Merge "Bug 716: Errors on controller shutdown"
authorTony Tkacik <ttkacik@cisco.com>
Fri, 23 May 2014 12:42:54 +0000 (12:42 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 23 May 2014 12:42:54 +0000 (12:42 +0000)
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/SchemaServiceImplSingletonModule.java

index 750defc0e95ac17ad535b299bfad52e4c4a489f2..0f0ce0dc9dd24fb41bc54bde70c196ba2d4d511e 100644 (file)
@@ -26,6 +26,8 @@ import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -36,6 +38,8 @@ import com.google.common.base.Preconditions;
 public final class RuntimeMappingModule extends
         org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractRuntimeMappingModule {
 
+    private static final Logger LOG = LoggerFactory.getLogger(RuntimeMappingModule.class);
+
     private BundleContext bundleContext;
 
     public RuntimeMappingModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
@@ -163,10 +167,17 @@ public final class RuntimeMappingModule extends
         }
 
         @Override
-        public void close() throws Exception {
+        public void close() {
             if(delegate != null) {
                 delegate = null;
-                bundleContext.ungetService(reference);
+
+                try {
+                    bundleContext.ungetService(reference);
+                } catch (IllegalStateException e) {
+                    // Indicates the BundleContext is no longer valid which can happen normally on shutdown.
+                    LOG.debug( "Error unregistering service", e );
+                }
+
                 bundleContext= null;
                 reference = null;
             }
index ba7414d42e26cbac61eb97a836cf89343f461969..93284c98e1032f0030fff3c21d2c6c3dfc2ba1f2 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
 *
@@ -23,6 +25,8 @@ import org.osgi.framework.ServiceReference;
 public final class SchemaServiceImplSingletonModule extends
         org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
 
+    private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
+
     BundleContext bundleContext;
 
     public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
@@ -83,28 +87,41 @@ public final class SchemaServiceImplSingletonModule extends
         public void close() throws Exception {
             if (delegate != null) {
                 delegate = null;
-                bundleContext.ungetService(reference);
+
+                try {
+                    bundleContext.ungetService(reference);
+                } catch (IllegalStateException e) {
+                    // Indicates the service was already unregistered which can happen normally
+                    // on shutdown.
+                    LOG.debug( "Error unregistering service", e );
+                }
+
                 reference = null;
                 bundleContext = null;
             }
         }
 
+        @Override
         public void addModule(Module arg0) {
             delegate.addModule(arg0);
         }
 
+        @Override
         public SchemaContext getGlobalContext() {
             return delegate.getGlobalContext();
         }
 
+        @Override
         public SchemaContext getSessionContext() {
             return delegate.getSessionContext();
         }
 
+        @Override
         public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(SchemaServiceListener arg0) {
             return delegate.registerSchemaServiceListener(arg0);
         }
 
+        @Override
         public void removeModule(Module arg0) {
             delegate.removeModule(arg0);
         }