use of org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration in project controller by opendaylight.
the class ServiceReferenceRegistryImpl method removeServiceReference.
private synchronized void removeServiceReference(final ServiceReference serviceReference) throws InstanceNotFoundException {
LOG.debug("Removing service reference {} from {}", serviceReference, this);
assertWritable();
// is the qName known?
if (!allQNames.contains(serviceReference.getServiceInterfaceQName())) {
LOG.error("Cannot find qname {} in {}", serviceReference.getServiceInterfaceQName(), allQNames);
throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName());
}
ModuleIdentifier removed = refNames.remove(serviceReference);
if (removed == null) {
throw new InstanceNotFoundException("Cannot find " + serviceReference.getServiceInterfaceQName());
}
Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration> entry = managementBeans.remove(serviceReference);
if (entry == null) {
throw new IllegalStateException("Possible code error: cannot remove from mBeans: " + serviceReference);
}
entry.getValue().close();
}
use of org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration in project controller by opendaylight.
the class ServiceReferenceRegistryImpl method saveServiceReference.
private synchronized ObjectName saveServiceReference(final ServiceReference serviceReference, final ObjectName moduleON, final boolean skipChecks) throws InstanceNotFoundException {
// make sure it is found
if (!skipChecks) {
lookupRegistry.checkConfigBeanExists(moduleON);
}
String factoryName = ObjectNameUtil.getFactoryName(moduleON);
String instanceName = ObjectNameUtil.getInstanceName(moduleON);
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
// check that service interface name exist
Set<String> serviceInterfaceQNames = factoryNamesToQNames.get(moduleIdentifier.getFactoryName());
if (serviceInterfaceQNames == null) {
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())) {
LOG.error("Cannot find qName {} with factory name {}, found {}", serviceReference.getServiceInterfaceQName(), moduleIdentifier.getFactoryName(), serviceInterfaceQNames);
throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName() + " within factory " + moduleIdentifier.getFactoryName());
}
// create service reference object name, put to mBeans
ObjectName result = getServiceON(serviceReference);
Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration> mxBeanEntry = managementBeans.get(serviceReference);
if (mxBeanEntry == null) {
// create dummy mx bean
ServiceReferenceMXBeanImpl dummyMXBean = new ServiceReferenceMXBeanImpl(moduleON);
ServiceReferenceJMXRegistration dummyMXBeanRegistration;
try {
dummyMXBeanRegistration = serviceReferenceRegistrator.registerMBean(dummyMXBean, result);
} catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException("Possible error in code. Cannot register " + result, e);
}
managementBeans.put(serviceReference, new SimpleImmutableEntry<>(dummyMXBean, dummyMXBeanRegistration));
} else {
// update
mxBeanEntry.getKey().setCurrentImplementation(moduleON);
}
// save to refNames
refNames.put(serviceReference, moduleIdentifier);
Map<ServiceInterfaceAnnotation, String> /* service ref name */
refNamesToAnnotations = modulesToServiceRef.computeIfAbsent(moduleIdentifier, k -> new HashMap<>());
ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName());
Preconditions.checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference);
refNamesToAnnotations.put(annotation, serviceReference.getRefName());
return result;
}
Aggregations