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 <tolvecky@cisco.com>
}
// register services to OSGi
}
// register services to OSGi
- Map<String, ServiceInterfaceAnnotation> annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier);
+ Map<ServiceInterfaceAnnotation, String /* service ref name */> annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier);
BundleContext bc = configTransactionController.getModuleFactoryBundleContext(
entry.getModuleFactory().getImplementationName());
if (osgiRegistration == null) {
BundleContext bc = configTransactionController.getModuleFactoryBundleContext(
entry.getModuleFactory().getImplementationName());
if (osgiRegistration == null) {
* @throws java.lang.IllegalArgumentException if any of service qNames is not found
* @throws java.lang.NullPointerException if parameter is null
*/
* @throws java.lang.IllegalArgumentException if any of service qNames is not found
* @throws java.lang.NullPointerException if parameter is null
*/
- Map<String /* service ref */, ServiceInterfaceAnnotation> findServiceInterfaces(ModuleIdentifier moduleIdentifier);
+ Map<ServiceInterfaceAnnotation, String /* service ref name */> findServiceInterfaces(ModuleIdentifier moduleIdentifier);
private final Map<String /* service qName */, ServiceInterfaceAnnotation> serviceQNamesToAnnotations;
// all Service Interface qNames for sanity checking
private final Set<String /* qName */> allQNames;
private final Map<String /* service qName */, ServiceInterfaceAnnotation> serviceQNamesToAnnotations;
// all Service Interface qNames for sanity checking
private final Set<String /* qName */> allQNames;
- Map<ModuleIdentifier, Map<String /* service ref name */, ServiceInterfaceAnnotation >> modulesToServiceRef = new HashMap<>();
+ Map<ModuleIdentifier, Map<ServiceInterfaceAnnotation, String /* service ref name */>> modulesToServiceRef = new HashMap<>();
// actual reference database
// actual reference database
- public Map<String /* service ref */, ServiceInterfaceAnnotation> findServiceInterfaces(ModuleIdentifier moduleIdentifier) {
- Map<String, ServiceInterfaceAnnotation> result = modulesToServiceRef.get(moduleIdentifier);
+ public Map<ServiceInterfaceAnnotation, String /* service ref name */> findServiceInterfaces(ModuleIdentifier moduleIdentifier) {
+ Map<ServiceInterfaceAnnotation, String /* service ref name */> result = modulesToServiceRef.get(moduleIdentifier);
if (result == null) {
return Collections.emptyMap();
}
if (result == null) {
return Collections.emptyMap();
}
}
// save to refNames
refNames.put(serviceReference, moduleIdentifier);
}
// save to refNames
refNames.put(serviceReference, moduleIdentifier);
- Map<String, ServiceInterfaceAnnotation> refNamesToAnnotations = modulesToServiceRef.get(moduleIdentifier);
+ Map<ServiceInterfaceAnnotation, String /* service ref name */> refNamesToAnnotations = modulesToServiceRef.get(moduleIdentifier);
if (refNamesToAnnotations == null){
refNamesToAnnotations = new HashMap<>();
modulesToServiceRef.put(moduleIdentifier, refNamesToAnnotations);
if (refNamesToAnnotations == null){
refNamesToAnnotations = new HashMap<>();
modulesToServiceRef.put(moduleIdentifier, refNamesToAnnotations);
ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName());
checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference);
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());
*/
public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
BundleContext bundleContext,
*/
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);
}
return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations);
}
@GuardedBy("this")
private final Set<ServiceRegistration<?>> serviceRegistrations;
@GuardedBy("this")
@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,
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;
this.instance = instance;
this.moduleIdentifier = moduleIdentifier;
this.serviceNamesToAnnotations = serviceNamesToAnnotations;
}
private static Set<ServiceRegistration<?>> registerToSR(AutoCloseable instance, BundleContext bundleContext,
}
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<>();
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());
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);
ServiceRegistration<?> serviceRegistration = bundleContext
.registerService(requiredInterface.getName(), instance, propertiesForOsgi);
serviceRegistrations.add(serviceRegistration);
serviceRegistrations.clear();
}
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;
BundleContext bundleContext, AutoCloseable newInstance) {
boolean notEquals = this.instance != newInstance;
notEquals |= newAnnotationMapping.equals(serviceNamesToAnnotations) == false;