Merge "Add get-config commit edit-config to testtool"
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / osgi / BeanToOsgiServiceManager.java
index fbc7eb6cbe7925ef6da5a96ad69e8c1a38433007..c03bfa450034254360dca663f18abf54d607f83e 100644 (file)
@@ -37,7 +37,7 @@ public class BeanToOsgiServiceManager {
      */
     public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
                                            BundleContext bundleContext,
-                                           Map<String, ServiceInterfaceAnnotation> serviceNamesToAnnotations) {
+                                           Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
         return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations);
     }
 
@@ -49,7 +49,7 @@ public class BeanToOsgiServiceManager {
 
 
     public static class OsgiRegistration implements AutoCloseable {
-        private static final Logger logger = LoggerFactory.getLogger(OsgiRegistration.class);
+        private static final Logger LOGGER = LoggerFactory.getLogger(OsgiRegistration.class);
 
         @GuardedBy("this")
         private AutoCloseable instance;
@@ -57,11 +57,11 @@ public class BeanToOsgiServiceManager {
         @GuardedBy("this")
         private final Set<ServiceRegistration<?>> serviceRegistrations;
         @GuardedBy("this")
-        private final Map<String, ServiceInterfaceAnnotation> serviceNamesToAnnotations;
+        private final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations;
 
         public OsgiRegistration(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
                                 BundleContext bundleContext,
-                                Map<String, ServiceInterfaceAnnotation> serviceNamesToAnnotations) {
+                                Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
             this.instance = instance;
             this.moduleIdentifier = moduleIdentifier;
             this.serviceNamesToAnnotations = serviceNamesToAnnotations;
@@ -69,13 +69,13 @@ public class BeanToOsgiServiceManager {
         }
 
         private static Set<ServiceRegistration<?>> registerToSR(AutoCloseable instance, BundleContext bundleContext,
-                                                                Map<String, ServiceInterfaceAnnotation> serviceNamesToAnnotations) {
+                                                                Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
             Set<ServiceRegistration<?>> serviceRegistrations = new HashSet<>();
-            for (Entry<String, ServiceInterfaceAnnotation> entry : serviceNamesToAnnotations.entrySet()) {
-                Class<?> requiredInterface = entry.getValue().osgiRegistrationType();
+            for (Entry<ServiceInterfaceAnnotation, String /* service ref name */> entry : serviceNamesToAnnotations.entrySet()) {
+                Class<?> requiredInterface = entry.getKey().osgiRegistrationType();
                 checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
                         " instance should implement " + requiredInterface.getName());
-                Dictionary<String, String> propertiesForOsgi = createProps(entry.getKey());
+                Dictionary<String, String> propertiesForOsgi = createProps(entry.getValue());
                 ServiceRegistration<?> serviceRegistration = bundleContext
                         .registerService(requiredInterface.getName(), instance, propertiesForOsgi);
                 serviceRegistrations.add(serviceRegistration);
@@ -89,19 +89,19 @@ public class BeanToOsgiServiceManager {
                 try {
                     serviceRegistration.unregister();
                 } catch(IllegalStateException e) {
-                    logger.trace("Cannot unregister {}", serviceRegistration, e);
+                    LOGGER.trace("Cannot unregister {}", serviceRegistration, e);
                 }
             }
             serviceRegistrations.clear();
         }
 
-        public synchronized void updateRegistrations(Map<String, ServiceInterfaceAnnotation> newAnnotationMapping,
+        public synchronized void updateRegistrations(Map<ServiceInterfaceAnnotation, String /* service ref name */> 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,
+                LOGGER.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
                         serviceNamesToAnnotations, newAnnotationMapping);
                 close();
                 this.instance = newInstance;