import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import org.slf4j.LoggerFactory;
public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceReadableRegistry, SearchableServiceReferenceWritableRegistry {
import org.slf4j.LoggerFactory;
public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceReadableRegistry, SearchableServiceReferenceWritableRegistry {
private final Map<String, ModuleFactory> factories;
private final Map<String, Set<String>> factoryNamesToQNames;
private final Map<String, ModuleFactory> factories;
private final Map<String, Set<String>> factoryNamesToQNames;
- public static SearchableServiceReferenceWritableRegistry createSRWritableRegistry(ServiceReferenceReadableRegistry oldReadableRegistry,
- ConfigTransactionLookupRegistry txLookupRegistry,
- Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
+ public static SearchableServiceReferenceWritableRegistry createSRWritableRegistry(final ServiceReferenceReadableRegistry oldReadableRegistry,
+ final ConfigTransactionLookupRegistry txLookupRegistry,
+ final Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
- public static CloseableServiceReferenceReadableRegistry createSRReadableRegistry(ServiceReferenceWritableRegistry oldWritableRegistry,
- LookupRegistry lookupRegistry, BaseJMXRegistrator baseJMXRegistrator) {
+ public static CloseableServiceReferenceReadableRegistry createSRReadableRegistry(final ServiceReferenceWritableRegistry oldWritableRegistry,
+ final LookupRegistry lookupRegistry, final BaseJMXRegistrator baseJMXRegistrator) {
ServiceReferenceRegistryImpl old = (ServiceReferenceRegistryImpl) oldWritableRegistry;
// even if factories do change, nothing in the mapping can change between transactions
ServiceReferenceRegistryImpl old = (ServiceReferenceRegistryImpl) oldWritableRegistry;
// even if factories do change, nothing in the mapping can change between transactions
- private static void copy(ServiceReferenceRegistryImpl old, ServiceReferenceRegistryImpl newRegistry, String nullableDstTransactionName) {
+ private static void copy(final ServiceReferenceRegistryImpl old, final ServiceReferenceRegistryImpl newRegistry, final String nullableDstTransactionName) {
for (Entry<ServiceReference, Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration>> refNameEntry : old.mBeans.entrySet()) {
ObjectName currentImplementation;
ObjectName currentImplementationSrc = refNameEntry.getValue().getKey().getCurrentImplementation();
for (Entry<ServiceReference, Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration>> refNameEntry : old.mBeans.entrySet()) {
ObjectName currentImplementation;
ObjectName currentImplementationSrc = refNameEntry.getValue().getKey().getCurrentImplementation();
boolean skipChecks = true;
newRegistry.saveServiceReference(refNameEntry.getKey(), currentImplementation, skipChecks);
} catch (InstanceNotFoundException e) {
boolean skipChecks = true;
newRegistry.saveServiceReference(refNameEntry.getKey(), currentImplementation, skipChecks);
} catch (InstanceNotFoundException e) {
- LOGGER.error("Cannot save service reference({}, {})", refNameEntry.getKey(), currentImplementation);
+ LOG.error("Cannot save service reference({}, {})", refNameEntry.getKey(), currentImplementation);
- private static Map<String, ModuleFactory> extractFactoriesMap(Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
+ private static Map<String, ModuleFactory> extractFactoriesMap(final Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
Map<String, ModuleFactory> result = new HashMap<>();
for (Entry<String, Entry<ModuleFactory, BundleContext>> entry : currentlyRegisteredFactories.entrySet()) {
result.put(entry.getKey(), entry.getValue().getKey());
Map<String, ModuleFactory> result = new HashMap<>();
for (Entry<String, Entry<ModuleFactory, BundleContext>> entry : currentlyRegisteredFactories.entrySet()) {
result.put(entry.getKey(), entry.getValue().getKey());
- private ServiceReferenceRegistryImpl(Map<String, ModuleFactory> factories, LookupRegistry lookupRegistry,
- ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory,
- boolean writable) {
+ 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.factories = factories;
this.writable = writable;
this.lookupRegistry = lookupRegistry;
for (Entry<String, ModuleFactory> entry : factories.entrySet()) {
if (entry.getKey().equals(entry.getValue().getImplementationName()) == false) {
for (Entry<String, ModuleFactory> entry : factories.entrySet()) {
if (entry.getKey().equals(entry.getValue().getImplementationName()) == false) {
throw new IllegalArgumentException("Possible error in code: Mismatch between supplied and actual name of " + entry);
}
Set<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue());
Set<String> qNames = InterfacesHelper.getQNames(siAnnotations);
allAnnotations.addAll(siAnnotations);
allQNameSet.addAll(qNames);
throw new IllegalArgumentException("Possible error in code: Mismatch between supplied and actual name of " + entry);
}
Set<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue());
Set<String> qNames = InterfacesHelper.getQNames(siAnnotations);
allAnnotations.addAll(siAnnotations);
allQNameSet.addAll(qNames);
- this.factoryNamesToQNames = Collections.unmodifiableMap(modifiableFactoryNamesToQNames);
- this.allQNames = Collections.unmodifiableSet(allQNameSet);
+ this.factoryNamesToQNames = ImmutableMap.copyOf(modifiableFactoryNamesToQNames);
+ this.allQNames = ImmutableSet.copyOf(allQNameSet);
// fill namespacesToAnnotations
Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations =
new HashMap<>();
// fill namespacesToAnnotations
Map<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations =
new HashMap<>();
modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace);
}
if (ofNamespace.containsKey(sia.localName())) {
modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace);
}
if (ofNamespace.containsKey(sia.localName())) {
- LOGGER.error("Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}",
+ 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);
}
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 = Collections.unmodifiableMap(modifiableNamespacesToAnnotations);
- this.serviceQNamesToAnnotations = Collections.unmodifiableMap(modifiableServiceQNamesToAnnotations);
- LOGGER.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames);
+ this.namespacesToAnnotations = ImmutableMap.copyOf(modifiableNamespacesToAnnotations);
+ this.serviceQNamesToAnnotations = ImmutableMap.copyOf(modifiableServiceQNamesToAnnotations);
+ LOG.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames);
Map<ServiceInterfaceAnnotation, String /* service ref name */> result = modulesToServiceRef.get(moduleIdentifier);
if (result == null) {
return Collections.emptyMap();
Map<ServiceInterfaceAnnotation, String /* service ref name */> result = modulesToServiceRef.get(moduleIdentifier);
if (result == null) {
return Collections.emptyMap();
lookupRegistry.checkConfigBeanExists(objectName);
String factoryName = ObjectNameUtil.getFactoryName(objectName);
Set<String> serviceInterfaceAnnotations = factoryNamesToQNames.get(factoryName);
if (serviceInterfaceAnnotations == null) {
lookupRegistry.checkConfigBeanExists(objectName);
String factoryName = ObjectNameUtil.getFactoryName(objectName);
Set<String> serviceInterfaceAnnotations = factoryNamesToQNames.get(factoryName);
if (serviceInterfaceAnnotations == null) {
factoryName, objectName, factoryNamesToQNames);
throw new IllegalArgumentException("Cannot find factory with name " + factoryName);
}
factoryName, objectName, factoryNamesToQNames);
throw new IllegalArgumentException("Cannot find factory with name " + factoryName);
}
Map<String /* localName */, ServiceInterfaceAnnotation> ofNamespace = namespacesToAnnotations.get(namespace);
if (ofNamespace == null) {
Map<String /* localName */, ServiceInterfaceAnnotation> ofNamespace = namespacesToAnnotations.get(namespace);
if (ofNamespace == null) {
throw new IllegalArgumentException("Cannot find namespace " + namespace);
}
ServiceInterfaceAnnotation sia = ofNamespace.get(localName);
if (sia == null) {
throw new IllegalArgumentException("Cannot find namespace " + namespace);
}
ServiceInterfaceAnnotation sia = ofNamespace.get(localName);
if (sia == null) {
- LOGGER.error("Cannot find local name {} in namespace {}, found only {}", localName, namespace, ofNamespace);
+ LOG.error("Cannot find local name {} in namespace {}, found only {}", localName, namespace, ofNamespace);
ObjectName on;
try {
on = lookupRegistry.lookupConfigBean(moduleIdentifier.getFactoryName(), moduleIdentifier.getInstanceName());
} catch (InstanceNotFoundException e) {
ObjectName on;
try {
on = lookupRegistry.lookupConfigBean(moduleIdentifier.getFactoryName(), moduleIdentifier.getInstanceName());
} catch (InstanceNotFoundException e) {
ServiceReference serviceReference = new ServiceReference(serviceInterfaceQName, refName);
ModuleIdentifier moduleIdentifier = refNames.get(serviceReference);
if (moduleIdentifier == null) {
ServiceReference serviceReference = new ServiceReference(serviceInterfaceQName, refName);
ModuleIdentifier moduleIdentifier = refNames.get(serviceReference);
if (moduleIdentifier == null) {
- LOGGER.error("Cannot find qname {} and refName {} in {}", serviceInterfaceQName, refName, refName);
+ LOG.error("Cannot find qname {} and refName {} in {}", serviceInterfaceQName, refName, refName);
throw new IllegalArgumentException("Cannot find " + serviceReference);
}
return getObjectName(moduleIdentifier);
}
@Override
throw new IllegalArgumentException("Cannot find " + serviceReference);
}
return getObjectName(moduleIdentifier);
}
@Override
Map<String, Map<String, ObjectName>> serviceMapping = getServiceMapping();
Map<String, ObjectName> innerMap = serviceMapping.get(serviceInterfaceQName);
if (innerMap == null) {
Map<String, Map<String, ObjectName>> serviceMapping = getServiceMapping();
Map<String, ObjectName> innerMap = serviceMapping.get(serviceInterfaceQName);
if (innerMap == null) {
ServiceReference serviceReference = new ServiceReference(serviceInterfaceQName, refName);
if (mBeans.containsKey(serviceReference) == false) {
throw new InstanceNotFoundException("Cannot find " + serviceReference);
ServiceReference serviceReference = new ServiceReference(serviceInterfaceQName, refName);
if (mBeans.containsKey(serviceReference) == false) {
throw new InstanceNotFoundException("Cannot find " + serviceReference);
String actualTransactionName = ObjectNameUtil.getTransactionName(objectName);
String expectedTransactionName = serviceReferenceRegistrator.getNullableTransactionName();
if (writable & actualTransactionName == null || (writable && actualTransactionName.equals(expectedTransactionName) == false)) {
String actualTransactionName = ObjectNameUtil.getTransactionName(objectName);
String expectedTransactionName = serviceReferenceRegistrator.getNullableTransactionName();
if (writable & actualTransactionName == null || (writable && actualTransactionName.equals(expectedTransactionName) == false)) {
String referenceName = ObjectNameUtil.getReferenceName(objectName);
ServiceReference serviceReference = new ServiceReference(serviceQName, referenceName);
if (refNames.containsKey(serviceReference) == false) {
String referenceName = ObjectNameUtil.getReferenceName(objectName);
ServiceReference serviceReference = new ServiceReference(serviceQName, referenceName);
if (refNames.containsKey(serviceReference) == false) {
- public synchronized ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException {
+ public synchronized ObjectName saveServiceReference(final String serviceInterfaceName, final String refName, final ObjectName moduleON) throws InstanceNotFoundException {
assertWritable();
ServiceReference serviceReference = new ServiceReference(serviceInterfaceName, refName);
return saveServiceReference(serviceReference, moduleON);
}
assertWritable();
ServiceReference serviceReference = new ServiceReference(serviceInterfaceName, refName);
return saveServiceReference(serviceReference, moduleON);
}
throws InstanceNotFoundException{
return saveServiceReference(serviceReference, moduleON, false);
}
throws InstanceNotFoundException{
return saveServiceReference(serviceReference, moduleON, false);
}
- private synchronized ObjectName saveServiceReference(ServiceReference serviceReference, ObjectName moduleON,
- boolean skipChecks) throws InstanceNotFoundException {
+ private synchronized ObjectName saveServiceReference(final ServiceReference serviceReference, final ObjectName moduleON,
+ final boolean skipChecks) throws InstanceNotFoundException {
// check that service interface name exist
Set<String> serviceInterfaceQNames = factoryNamesToQNames.get(moduleIdentifier.getFactoryName());
if (serviceInterfaceQNames == null) {
// check that service interface name exist
Set<String> serviceInterfaceQNames = factoryNamesToQNames.get(moduleIdentifier.getFactoryName());
if (serviceInterfaceQNames == null) {
- LOGGER.error("Possible error in code: cannot find factoryName {} in {}, {}", moduleIdentifier.getFactoryName(),
+ LOG.error("Possible error in code: cannot find factoryName {} in {}, {}", moduleIdentifier.getFactoryName(),
factoryNamesToQNames, moduleIdentifier);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + moduleIdentifier.getFactoryName());
}
// supplied serviceInterfaceName must exist in this collection
if (serviceInterfaceQNames.contains(serviceReference.getServiceInterfaceQName()) == false) {
factoryNamesToQNames, moduleIdentifier);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + moduleIdentifier.getFactoryName());
}
// supplied serviceInterfaceName must exist in this collection
if (serviceInterfaceQNames.contains(serviceReference.getServiceInterfaceQName()) == false) {
- LOGGER.error("Cannot find qName {} with factory name {}, found {}", serviceReference.getServiceInterfaceQName(), moduleIdentifier.getFactoryName(), serviceInterfaceQNames);
+ LOG.error("Cannot find qName {} with factory name {}, found {}", serviceReference.getServiceInterfaceQName(), moduleIdentifier.getFactoryName(), serviceInterfaceQNames);
if (writable) {
return ObjectNameUtil.createTransactionServiceON(serviceReferenceRegistrator.getNullableTransactionName(),
serviceReference.getServiceInterfaceQName(), serviceReference.getRefName());
if (writable) {
return ObjectNameUtil.createTransactionServiceON(serviceReferenceRegistrator.getNullableTransactionName(),
serviceReference.getServiceInterfaceQName(), serviceReference.getRefName());
ServiceReference serviceReference = new ServiceReference(serviceInterfaceName, refName);
removeServiceReference(serviceReference);
}
ServiceReference serviceReference = new ServiceReference(serviceInterfaceName, refName);
removeServiceReference(serviceReference);
}
- private synchronized void removeServiceReference(ServiceReference serviceReference) throws InstanceNotFoundException {
- LOGGER.debug("Removing service reference {} from {}", serviceReference, this);
+ private synchronized void removeServiceReference(final ServiceReference serviceReference) throws InstanceNotFoundException {
+ LOG.debug("Removing service reference {} from {}", serviceReference, this);
throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName());
}
ModuleIdentifier removed = refNames.remove(serviceReference);
throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName());
}
ModuleIdentifier removed = refNames.remove(serviceReference);
lookupRegistry.checkConfigBeanExists(moduleObjectName);
String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
// check that service interface name exist
lookupRegistry.checkConfigBeanExists(moduleObjectName);
String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
// check that service interface name exist
ObjectNameUtil.checkType(moduleObjectName, ObjectNameUtil.TYPE_MODULE);
assertWritable();
Set<ServiceReference> serviceReferencesLinkingTo = findServiceReferencesLinkingTo(moduleObjectName, qNames);
ObjectNameUtil.checkType(moduleObjectName, ObjectNameUtil.TYPE_MODULE);
assertWritable();
Set<ServiceReference> serviceReferencesLinkingTo = findServiceReferencesLinkingTo(moduleObjectName, qNames);
String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
if (serviceInterfaceQNames == null) {
String factoryName = ObjectNameUtil.getFactoryName(moduleObjectName);
if (serviceInterfaceQNames == null) {
- LOGGER.warn("Possible error in code: cannot find factoryName {} in {}, object name {}", factoryName, factoryNamesToQNames, moduleObjectName);
+ LOG.warn("Possible error in code: cannot find factoryName {} in {}, object name {}", factoryName, factoryNamesToQNames, moduleObjectName);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + factoryName);
}
String instanceName = ObjectNameUtil.getInstanceName(moduleObjectName);
throw new IllegalStateException("Possible error in code: cannot find annotations of existing factory " + factoryName);
}
String instanceName = ObjectNameUtil.getInstanceName(moduleObjectName);