Ensure CSS modules are closed before blueprint containers on shutdown
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / BeanToOsgiServiceManager.java
index b592fa3c79736d09b22f0b133bef142702783dbb..3d93a9df7dee72bb450af215bd7dea97f24199a5 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.config.manager.impl.osgi;
 
 import static com.google.common.base.Preconditions.checkState;
-
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -49,7 +48,7 @@ public class BeanToOsgiServiceManager {
 
 
     public static class OsgiRegistration implements AutoCloseable {
-        private static final Logger logger = LoggerFactory.getLogger(OsgiRegistration.class);
+        private static final Logger LOG = LoggerFactory.getLogger(OsgiRegistration.class);
 
         @GuardedBy("this")
         private AutoCloseable instance;
@@ -72,7 +71,14 @@ public class BeanToOsgiServiceManager {
                                                                 Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
             Set<ServiceRegistration<?>> serviceRegistrations = new HashSet<>();
             for (Entry<ServiceInterfaceAnnotation, String /* service ref name */> entry : serviceNamesToAnnotations.entrySet()) {
-                Class<?> requiredInterface = entry.getKey().osgiRegistrationType();
+                ServiceInterfaceAnnotation annotation = entry.getKey();
+                Class<?> requiredInterface = annotation.osgiRegistrationType();
+
+                if(!annotation.registerToOsgi()) {
+                    LOG.debug("registerToOsgi for service interface {} is false - not registering", requiredInterface);
+                    continue;
+                }
+
                 checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
                         " instance should implement " + requiredInterface.getName());
                 Dictionary<String, String> propertiesForOsgi = createProps(entry.getValue());
@@ -89,7 +95,7 @@ public class BeanToOsgiServiceManager {
                 try {
                     serviceRegistration.unregister();
                 } catch(IllegalStateException e) {
-                    logger.trace("Cannot unregister {}", serviceRegistration, e);
+                    LOG.trace("Cannot unregister {}", serviceRegistration, e);
                 }
             }
             serviceRegistrations.clear();
@@ -101,7 +107,7 @@ public class BeanToOsgiServiceManager {
             notEquals |= newAnnotationMapping.equals(serviceNamesToAnnotations) == false;
             if (notEquals) {
                 // FIXME: changing from old state to new state can be improved by computing the diff
-                logger.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
+                LOG.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
                         serviceNamesToAnnotations, newAnnotationMapping);
                 close();
                 this.instance = newInstance;