From: Tomas Olvecky Date: Thu, 22 May 2014 08:23:02 +0000 (+0200) Subject: Bug 1062 - Allow multiple service references with same name. X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~26^2~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F7328%2F1;hp=bd98ee34425db52782ebdb0dd7cefcf1763f972c;p=controller.git Bug 1062 - Allow multiple service references with same name. One module should allow multiple service references with same name as long as each reference uses different service interface. Change-Id: I09e448f498ad9bd4fbe005789fa29037e202dd38 Signed-off-by: Tomas Olvecky --- diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java index 8f85972d05..b7cdf94757 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java @@ -359,7 +359,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe } // register services to OSGi - Map annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier); + Map annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier); BundleContext bc = configTransactionController.getModuleFactoryBundleContext( entry.getModuleFactory().getImplementationName()); if (osgiRegistration == null) { diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/SearchableServiceReferenceWritableRegistry.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/SearchableServiceReferenceWritableRegistry.java index 7a41a3bfa2..4c5e391f74 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/SearchableServiceReferenceWritableRegistry.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/SearchableServiceReferenceWritableRegistry.java @@ -21,6 +21,6 @@ public interface SearchableServiceReferenceWritableRegistry extends ServiceRefer * @throws java.lang.IllegalArgumentException if any of service qNames is not found * @throws java.lang.NullPointerException if parameter is null */ - Map findServiceInterfaces(ModuleIdentifier moduleIdentifier); + Map findServiceInterfaces(ModuleIdentifier moduleIdentifier); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java index ceea994154..52bb3f5ed1 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java @@ -50,7 +50,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe private final Map serviceQNamesToAnnotations; // all Service Interface qNames for sanity checking private final Set allQNames; - Map> modulesToServiceRef = new HashMap<>(); + Map> modulesToServiceRef = new HashMap<>(); // actual reference database @@ -241,8 +241,8 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe } @Override - public Map findServiceInterfaces(ModuleIdentifier moduleIdentifier) { - Map result = modulesToServiceRef.get(moduleIdentifier); + public Map findServiceInterfaces(ModuleIdentifier moduleIdentifier) { + Map result = modulesToServiceRef.get(moduleIdentifier); if (result == null) { return Collections.emptyMap(); } @@ -417,7 +417,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe } // save to refNames refNames.put(serviceReference, moduleIdentifier); - Map refNamesToAnnotations = modulesToServiceRef.get(moduleIdentifier); + Map refNamesToAnnotations = modulesToServiceRef.get(moduleIdentifier); if (refNamesToAnnotations == null){ refNamesToAnnotations = new HashMap<>(); modulesToServiceRef.put(moduleIdentifier, refNamesToAnnotations); @@ -425,7 +425,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName()); checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference); - refNamesToAnnotations.put(serviceReference.getRefName(), annotation); + refNamesToAnnotations.put(annotation, serviceReference.getRefName()); return result; } 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..b592fa3c79 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 @@ -37,7 +37,7 @@ public class BeanToOsgiServiceManager { */ public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier, BundleContext bundleContext, - Map serviceNamesToAnnotations) { + Map serviceNamesToAnnotations) { return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations); } @@ -57,11 +57,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 +69,13 @@ 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()) { + Class requiredInterface = entry.getKey().osgiRegistrationType(); 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); @@ -95,7 +95,7 @@ public class BeanToOsgiServiceManager { 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;