Search in sources :

Example 1 with ServiceReferenceMXBeanImpl

use of org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl in project controller by opendaylight.

the class ServiceReferenceRegistryImpl method createInitialSRLookupRegistry.

/**
 * Static constructor for config registry. Since only transaction can write to
 * this registry, it will return blank state.
 *
 * @return service reference registry
 */
public static CloseableServiceReferenceReadableRegistry createInitialSRLookupRegistry() {
    // since this is initial state, just throw exception:
    LookupRegistry lookupRegistry = new LookupRegistry() {

        @Override
        public Set<ObjectName> lookupConfigBeans() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<ObjectName> lookupConfigBeans(final String moduleName) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<ObjectName> lookupConfigBeans(final String moduleName, final String instanceName) {
            throw new UnsupportedOperationException();
        }

        @Override
        public ObjectName lookupConfigBean(final String moduleName, final String instanceName) throws InstanceNotFoundException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void checkConfigBeanExists(final ObjectName objectName) throws InstanceNotFoundException {
            throw new InstanceNotFoundException("Cannot find " + objectName + " - Tried to use mocking registry");
        }

        @Override
        public Set<String> getAvailableModuleFactoryQNames() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<ObjectName> lookupRuntimeBeans() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<ObjectName> lookupRuntimeBeans(final String moduleName, final String instanceName) {
            throw new UnsupportedOperationException();
        }

        @Override
        public String toString() {
            return "initial";
        }
    };
    ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory = () -> new ServiceReferenceRegistrator() {

        @Override
        public String getNullableTransactionName() {
            throw new UnsupportedOperationException();
        }

        @Override
        public ServiceReferenceJMXRegistration registerMBean(final ServiceReferenceMXBeanImpl object, final ObjectName on) throws InstanceAlreadyExistsException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void close() {
        }
    };
    return new ServiceReferenceRegistryImpl(Collections.<String, ModuleFactory>emptyMap(), lookupRegistry, serviceReferenceRegistratorFactory, false);
}
Also used : ServiceReferenceMXBeanImpl(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl) InstanceNotFoundException(javax.management.InstanceNotFoundException) LookupRegistry(org.opendaylight.controller.config.api.LookupRegistry) ServiceReferenceTransactionRegistratorFactory(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceTransactionRegistratorFactory) ServiceReferenceRegistrator(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator) ObjectName(javax.management.ObjectName)

Example 2 with ServiceReferenceMXBeanImpl

use of org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl 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();
}
Also used : ServiceReferenceMXBeanImpl(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl) InstanceNotFoundException(javax.management.InstanceNotFoundException) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ServiceReferenceJMXRegistration(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration)

Example 3 with ServiceReferenceMXBeanImpl

use of org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl 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;
}
Also used : ServiceReferenceMXBeanImpl(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ServiceInterfaceAnnotation(org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation) ObjectName(javax.management.ObjectName) ModuleIdentifier(org.opendaylight.controller.config.api.ModuleIdentifier) ServiceReferenceJMXRegistration(org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration)

Aggregations

ServiceReferenceMXBeanImpl (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceMXBeanImpl)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ObjectName (javax.management.ObjectName)2 ModuleIdentifier (org.opendaylight.controller.config.api.ModuleIdentifier)2 ServiceReferenceJMXRegistration (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceJMXRegistration)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 LookupRegistry (org.opendaylight.controller.config.api.LookupRegistry)1 ServiceInterfaceAnnotation (org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation)1 ServiceReferenceRegistrator (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator)1 ServiceReferenceTransactionRegistratorFactory (org.opendaylight.controller.config.manager.impl.jmx.ServiceReferenceRegistrator.ServiceReferenceTransactionRegistratorFactory)1