+ private final Map<ServiceReference, Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration>>
+ managementBeans = new HashMap<>();
+
+ private ServiceReferenceRegistryImpl(final Map<String, ModuleFactory> factories,
+ final LookupRegistry lookupRegistry,
+ final ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory,
+ final boolean writable) {
+ this.factories = factories;
+ this.writable = writable;
+ this.lookupRegistry = lookupRegistry;
+
+ this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create();
+
+ Map<String, Set<String /* QName */>> modifiableFactoryNamesToQNames = new HashMap<>();
+ Set<ServiceInterfaceAnnotation> allAnnotations = new HashSet<>();
+ Set<String /* qName */> allQNameSet = new HashSet<>();
+
+ for (Entry<String, ModuleFactory> entry : factories.entrySet()) {
+ if (!entry.getKey().equals(entry.getValue().getImplementationName())) {
+ LOG.error("Possible error in code: Mismatch between supplied and actual name of {}", entry);
+ throw new IllegalArgumentException(
+ "Possible error in code: Mismatch between supplied and actual name of " + entry);
+ }
+ Set<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper
+ .getServiceInterfaceAnnotations(entry.getValue());
+ Set<String> names = InterfacesHelper.getQNames(siAnnotations);
+ allAnnotations.addAll(siAnnotations);
+ allQNameSet.addAll(names);
+ modifiableFactoryNamesToQNames.put(entry.getKey(), names);
+ }
+ this.factoryNamesToQNames = ImmutableMap.copyOf(modifiableFactoryNamesToQNames);
+ this.allQNames = ImmutableSet.copyOf(allQNameSet);
+ // fill namespacesToAnnotations
+ Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>>
+ modifiableNamespacesToAnnotations = new HashMap<>();
+ Map<String /* service qName */, ServiceInterfaceAnnotation>
+ modifiableServiceQNamesToAnnotations = new HashMap<>();
+ for (ServiceInterfaceAnnotation sia : allAnnotations) {
+ Map<String, ServiceInterfaceAnnotation> ofNamespace = modifiableNamespacesToAnnotations
+ .computeIfAbsent(sia.namespace(), k -> new HashMap<>());
+ if (ofNamespace.containsKey(sia.localName())) {
+ LOG.error(
+ "Cannot construct namespacesToAnnotations map, conflict between local names in {},"
+ + " offending local name: {}, map so far {}",
+ sia.namespace(), sia.localName(), modifiableNamespacesToAnnotations);
+ throw new IllegalArgumentException(
+ "Conflict between local names in " + sia.namespace() + " : " + sia.localName());
+ }
+ ofNamespace.put(sia.localName(), sia);
+ modifiableServiceQNamesToAnnotations.put(sia.value(), sia);
+ }
+ this.namespacesToAnnotations = ImmutableMap.copyOf(modifiableNamespacesToAnnotations);
+ this.serviceQNamesToAnnotations = ImmutableMap.copyOf(modifiableServiceQNamesToAnnotations);
+ LOG.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames);
+ }