use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class DependencyResolverImpl method getMaxDepth.
private static int getMaxDepth(final DependencyResolverImpl impl, final DependencyResolverManager manager, final LinkedHashSet<ModuleIdentifier> chainForDetectingCycles) {
int maxDepth = 0;
final LinkedHashSet<ModuleIdentifier> chainForDetectingCycles2 = new LinkedHashSet<>(chainForDetectingCycles);
chainForDetectingCycles2.add(impl.getIdentifier());
for (final ModuleIdentifier dependencyName : impl.dependencies) {
final DependencyResolverImpl dependentDRI = manager.getOrCreate(dependencyName);
if (chainForDetectingCycles2.contains(dependencyName)) {
throw new IllegalStateException(String.format("Cycle detected, %s contains %s", chainForDetectingCycles2, dependencyName));
}
int subDepth;
if (dependentDRI.maxDependencyDepth != null) {
subDepth = dependentDRI.maxDependencyDepth;
} else {
subDepth = getMaxDepth(dependentDRI, manager, chainForDetectingCycles2);
dependentDRI.maxDependencyDepth = subDepth;
}
if (subDepth + 1 > maxDepth) {
maxDepth = subDepth + 1;
}
}
impl.maxDependencyDepth = maxDepth;
return maxDepth;
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class DependencyResolverImpl method validateDependency.
/**
* {@inheritDoc}
*/
// TODO: check for cycles
@Override
public void validateDependency(final Class<? extends AbstractServiceInterface> expectedServiceInterface, final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) {
this.transactionStatus.checkNotCommitted();
if (expectedServiceInterface == null) {
throw new NullPointerException("Parameter 'expectedServiceInterface' is null");
}
if (jmxAttribute == null) {
throw new NullPointerException("Parameter 'jmxAttribute' is null");
}
JmxAttributeValidationException.checkNotNull(dependentReadOnlyON, "is null, expected dependency implementing " + expectedServiceInterface, jmxAttribute);
// check that objectName belongs to this transaction - this should be
// stripped
// in DynamicWritableWrapper
final boolean hasTransaction = ObjectNameUtil.getTransactionName(dependentReadOnlyON) != null;
JmxAttributeValidationException.checkCondition(!hasTransaction, String.format("ObjectName should not contain " + "transaction name. %s set to %s. ", jmxAttribute, dependentReadOnlyON), jmxAttribute);
final ObjectName newDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON);
final ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(newDependentReadOnlyON, ObjectNameUtil.TYPE_MODULE);
final ModuleFactory foundFactory = this.modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute);
final boolean implementsSI = foundFactory.isModuleImplementingServiceInterface(expectedServiceInterface);
if (!implementsSI) {
final String message = String.format("Found module factory does not expose expected service interface. " + "Module name is %s : %s, expected service interface %s, dependent module ON %s , " + "attribute %s", foundFactory.getImplementationName(), foundFactory, expectedServiceInterface, newDependentReadOnlyON, jmxAttribute);
throw new JmxAttributeValidationException(message, jmxAttribute);
}
synchronized (this) {
this.dependencies.add(moduleIdentifier);
}
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class DependencyResolverManager method getSortedModuleIdentifiers.
public List<ModuleIdentifier> getSortedModuleIdentifiers() {
List<ModuleIdentifier> result = new ArrayList<>(moduleIdentifiersToDependencyResolverMap.size());
for (DependencyResolverImpl dri : getAllSorted()) {
ModuleIdentifier driName = dri.getIdentifier();
result.add(driName);
}
return result;
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ModulesHolder method getAllModules.
public Map<ModuleIdentifier, Module> getAllModules() {
Map<ModuleIdentifier, Module> result = new HashMap<>();
for (ModuleInternalTransactionalInfo entry : commitMap.values()) {
ModuleIdentifier name = entry.getIdentifier();
result.put(name, entry.getProxiedModule());
}
return result;
}
use of org.opendaylight.controller.config.api.ModuleIdentifier in project controller by opendaylight.
the class ClassBasedModuleFactory method constructModule.
private Module constructModule(final String instanceName, final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old) throws InstantiationException, IllegalAccessException, InvocationTargetException {
Preconditions.checkNotNull(dependencyResolver);
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(implementationName, instanceName);
Constructor<? extends Module> declaredConstructor;
try {
declaredConstructor = configBeanClass.getDeclaredConstructor(DynamicMBeanWithInstance.class, ModuleIdentifier.class);
} catch (final NoSuchMethodException e) {
throw new IllegalStateException("Did not find constructor with parameters (DynamicMBeanWithInstance) in " + configBeanClass, e);
}
Preconditions.checkState(declaredConstructor != null);
return declaredConstructor.newInstance(old, moduleIdentifier);
}
Aggregations