X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FBeanToOsgiServiceManager.java;h=3d93a9df7dee72bb450af215bd7dea97f24199a5;hb=aebe2884329d666f661be53e2de3a57e4fcf61f1;hp=fbc7eb6cbe7925ef6da5a96ad69e8c1a38433007;hpb=d4e097a03ce5cb23b2418a0bc8fdc182d00da4d0;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java index fbc7eb6cbe..3d93a9df7d 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java @@ -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; @@ -37,7 +36,7 @@ public class BeanToOsgiServiceManager { */ public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier, BundleContext bundleContext, - Map serviceNamesToAnnotations) { + Map serviceNamesToAnnotations) { return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations); } @@ -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; @@ -57,11 +56,11 @@ public class BeanToOsgiServiceManager { @GuardedBy("this") private final Set> serviceRegistrations; @GuardedBy("this") - private final Map serviceNamesToAnnotations; + private final Map serviceNamesToAnnotations; public OsgiRegistration(AutoCloseable instance, ModuleIdentifier moduleIdentifier, BundleContext bundleContext, - Map serviceNamesToAnnotations) { + Map serviceNamesToAnnotations) { this.instance = instance; this.moduleIdentifier = moduleIdentifier; this.serviceNamesToAnnotations = serviceNamesToAnnotations; @@ -69,13 +68,20 @@ public class BeanToOsgiServiceManager { } private static Set> registerToSR(AutoCloseable instance, BundleContext bundleContext, - Map serviceNamesToAnnotations) { + Map serviceNamesToAnnotations) { Set> serviceRegistrations = new HashSet<>(); - for (Entry entry : serviceNamesToAnnotations.entrySet()) { - Class requiredInterface = entry.getValue().osgiRegistrationType(); + for (Entry entry : serviceNamesToAnnotations.entrySet()) { + 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 propertiesForOsgi = createProps(entry.getKey()); + Dictionary propertiesForOsgi = createProps(entry.getValue()); ServiceRegistration serviceRegistration = bundleContext .registerService(requiredInterface.getName(), instance, propertiesForOsgi); serviceRegistrations.add(serviceRegistration); @@ -89,19 +95,19 @@ public class BeanToOsgiServiceManager { try { serviceRegistration.unregister(); } catch(IllegalStateException e) { - logger.trace("Cannot unregister {}", serviceRegistration, e); + LOG.trace("Cannot unregister {}", serviceRegistration, e); } } serviceRegistrations.clear(); } - public synchronized void updateRegistrations(Map newAnnotationMapping, + public synchronized void updateRegistrations(Map newAnnotationMapping, BundleContext bundleContext, AutoCloseable newInstance) { boolean notEquals = this.instance != newInstance; 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;