use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.
the class ServiceReferenceRegistryImpl method createSRWritableRegistry.
public static SearchableServiceReferenceWritableRegistry createSRWritableRegistry(final ServiceReferenceReadableRegistry oldReadableRegistry, final ConfigTransactionLookupRegistry txLookupRegistry, final Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories) {
if (txLookupRegistry == null) {
throw new IllegalArgumentException("txLookupRegistry is null");
}
ServiceReferenceRegistryImpl old = (ServiceReferenceRegistryImpl) oldReadableRegistry;
Map<String, ModuleFactory> factories = extractFactoriesMap(currentlyRegisteredFactories);
ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory = new ServiceReferenceTransactionRegistratorFactoryImpl(txLookupRegistry.getTxModuleJMXRegistrator(), txLookupRegistry.getTxModuleJMXRegistrator().getTransactionName());
ServiceReferenceRegistryImpl newRegistry = new ServiceReferenceRegistryImpl(factories, txLookupRegistry, serviceReferenceRegistratorFactory, true);
copy(old, newRegistry, txLookupRegistry.getTransactionIdentifier().getName());
return newRegistry;
}
use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.
the class ConfigTransactionControllerImpl method copyExistingModule.
@SuppressWarnings("IllegalCatch")
private synchronized void copyExistingModule(final ModuleInternalInfo oldConfigBeanInfo) throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
ModuleIdentifier moduleIdentifier = oldConfigBeanInfo.getIdentifier();
dependencyResolverManager.assertNotExists(moduleIdentifier);
ModuleFactory moduleFactory;
BundleContext bc;
try {
moduleFactory = factoriesHolder.findByModuleName(moduleIdentifier.getFactoryName());
bc = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
} catch (final ModuleFactoryNotFoundException e) {
throw new IllegalStateException(e);
}
Module module;
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
try {
module = moduleFactory.createModule(moduleIdentifier.getInstanceName(), dependencyResolver, oldConfigBeanInfo.getReadableModule(), bc);
} catch (final Exception e) {
throw new IllegalStateException(String.format("Error while copying old configuration from %s to %s", oldConfigBeanInfo, moduleFactory), e);
}
putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, oldConfigBeanInfo, dependencyResolver, oldConfigBeanInfo.isDefaultBean(), bc);
}
use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.
the class ConfigTransactionControllerImpl method createModule.
@Override
public synchronized ObjectName createModule(final String factoryName, final String instanceName) throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(factoryName, instanceName);
dependencyResolverManager.assertNotExists(moduleIdentifier);
// find factory
ModuleFactory moduleFactory = factoriesHolder.findByModuleName(factoryName);
DependencyResolver dependencyResolver = dependencyResolverManager.getOrCreate(moduleIdentifier);
BundleContext bundleContext = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
Module module = moduleFactory.createModule(instanceName, dependencyResolver, bundleContext);
boolean defaultBean = false;
return putConfigBeanToJMXAndInternalMaps(moduleIdentifier, module, moduleFactory, null, dependencyResolver, defaultBean, bundleContext);
}
use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.
the class ModuleQNameUtil method getQNames.
public static Set<String> getQNames(final Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
final Set<String> result = new HashSet<>();
for (final Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
Class<?> inspected = entry.getKey().getClass();
if (inspected.isInterface()) {
throw new IllegalArgumentException("Unexpected interface " + inspected);
}
ModuleQName annotation = null;
while (annotation == null && inspected != null) {
annotation = inspected.getAnnotation(ModuleQName.class);
inspected = inspected.getSuperclass();
}
if (annotation != null) {
result.add(QName.create(annotation.namespace(), annotation.revision(), annotation.name()).toString());
}
}
return result;
}
use of org.opendaylight.controller.config.spi.ModuleFactory in project controller by opendaylight.
the class ConfigRegistryImplTest method testFailOnTwoFactoriesExportingSameImpl.
@Test
@SuppressWarnings("IllegalCatch")
public void testFailOnTwoFactoriesExportingSameImpl() {
ModuleFactory factory = new TestingFixedThreadPoolModuleFactory();
BundleContext context = mock(BundleContext.class);
ConfigRegistryImpl configRegistry = null;
try {
ModuleFactoriesResolver resolver = new HardcodedModuleFactoriesResolver(mock(BundleContext.class), factory, factory);
configRegistry = new ConfigRegistryImpl(resolver, ManagementFactory.getPlatformMBeanServer(), null);
configRegistry.beginConfig();
fail();
} catch (final IllegalArgumentException e) {
assertTrue(e.getMessage(), e.getMessage().startsWith("Module name is not unique. Found two conflicting factories with same name " + "'fixed':"));
verifyZeroInteractions(context);
} finally {
try {
configRegistry.close();
} catch (final Exception e) {
// ignore
LOG.warn("Ignoring exception", e);
}
}
}
Aggregations