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=51f99403148ba7b40301e52b63b391ae98c0134e;hb=refs%2Fchanges%2F73%2F46573%2F5;hp=b592fa3c79736d09b22f0b133bef142702783dbb;hpb=aae09dbf11186d2cd30fe87692f746519b0958f9;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 b592fa3c79..51f9940314 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 @@ -7,8 +7,7 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; -import static com.google.common.base.Preconditions.checkState; - +import com.google.common.base.Preconditions; import java.util.Dictionary; import java.util.HashSet; import java.util.Hashtable; @@ -41,15 +40,8 @@ public class BeanToOsgiServiceManager { return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations); } - private static Dictionary createProps(String serviceName) { - Hashtable result = new Hashtable<>(); - result.put(SERVICE_NAME_OSGI_PROP, serviceName); - return result; - } - - 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,8 +64,15 @@ public class BeanToOsgiServiceManager { Map serviceNamesToAnnotations) { Set> serviceRegistrations = new HashSet<>(); for (Entry entry : serviceNamesToAnnotations.entrySet()) { - Class requiredInterface = entry.getKey().osgiRegistrationType(); - checkState(requiredInterface.isInstance(instance), instance.getClass().getName() + + ServiceInterfaceAnnotation annotation = entry.getKey(); + Class requiredInterface = annotation.osgiRegistrationType(); + + if(!annotation.registerToOsgi()) { + LOG.debug("registerToOsgi for service interface {} is false - not registering", requiredInterface); + continue; + } + + Preconditions.checkState(requiredInterface.isInstance(instance), instance.getClass().getName() + " instance should implement " + requiredInterface.getName()); Dictionary propertiesForOsgi = createProps(entry.getValue()); ServiceRegistration serviceRegistration = bundleContext @@ -89,7 +88,7 @@ public class BeanToOsgiServiceManager { try { serviceRegistration.unregister(); } catch(IllegalStateException e) { - logger.trace("Cannot unregister {}", serviceRegistration, e); + LOG.trace("Cannot unregister {}", serviceRegistration, e); } } serviceRegistrations.clear(); @@ -97,11 +96,11 @@ public class BeanToOsgiServiceManager { public synchronized void updateRegistrations(Map newAnnotationMapping, BundleContext bundleContext, AutoCloseable newInstance) { - boolean notEquals = this.instance != newInstance; - notEquals |= newAnnotationMapping.equals(serviceNamesToAnnotations) == false; + boolean notEquals = !this.instance.equals(newInstance); + notEquals |= !newAnnotationMapping.equals(serviceNamesToAnnotations); 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; @@ -110,5 +109,11 @@ public class BeanToOsgiServiceManager { serviceRegistrations.addAll(newRegs); } } + + private static Dictionary createProps(String serviceName) { + Hashtable result = new Hashtable<>(); + result.put(SERVICE_NAME_OSGI_PROP, serviceName); + return result; + } } }