X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDependencyResolverImpl.java;h=eb3676ccebff5625db2f68b64b9f834488433ea2;hp=10128a2f5532563dc278a38d18d47322b1d4bd09;hb=db89afdefb3cfa4454dfdc6008e1d54d3ede66fb;hpb=3314dddc5692bed5eb837b0739ac3bb5ed1962ab diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java index 10128a2f55..eb3676cceb 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverImpl.java @@ -7,8 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.dependencyresolver; -import static java.lang.String.format; - import com.google.common.base.Preconditions; import java.util.HashSet; import java.util.LinkedHashSet; @@ -56,11 +54,12 @@ final class DependencyResolverImpl implements DependencyResolver, private final BindingContextProvider bindingContextProvider; private final String transactionName; private final MBeanServer mBeanServer; + private Integer maxDependencyDepth; - DependencyResolverImpl(ModuleIdentifier currentModule, - TransactionStatus transactionStatus, ModulesHolder modulesHolder, - ServiceReferenceReadableRegistry readableRegistry, BindingContextProvider bindingContextProvider, - String transactionName, MBeanServer mBeanServer) { + DependencyResolverImpl(final ModuleIdentifier currentModule, + final TransactionStatus transactionStatus, final ModulesHolder modulesHolder, + final ServiceReferenceReadableRegistry readableRegistry, final BindingContextProvider bindingContextProvider, + final String transactionName, final MBeanServer mBeanServer) { this.bindingContextProvider = bindingContextProvider; this.name = currentModule; this.transactionStatus = transactionStatus; @@ -76,10 +75,10 @@ final class DependencyResolverImpl implements DependencyResolver, //TODO: check for cycles @Override public void validateDependency( - Class expectedServiceInterface, - ObjectName dependentReadOnlyON, JmxAttribute jmxAttribute) { + final Class expectedServiceInterface, + final ObjectName dependentReadOnlyON, final JmxAttribute jmxAttribute) { - transactionStatus.checkNotCommitted(); + this.transactionStatus.checkNotCommitted(); if (expectedServiceInterface == null) { throw new NullPointerException( "Parameter 'expectedServiceInterface' is null"); @@ -97,27 +96,27 @@ final class DependencyResolverImpl implements DependencyResolver, // check that objectName belongs to this transaction - this should be // stripped // in DynamicWritableWrapper - boolean hasTransaction = ObjectNameUtil + final boolean hasTransaction = ObjectNameUtil .getTransactionName(dependentReadOnlyON) != null; JmxAttributeValidationException.checkCondition( - hasTransaction == false, - format("ObjectName should not contain " + !hasTransaction, + String.format("ObjectName should not contain " + "transaction name. %s set to %s. ", jmxAttribute, dependentReadOnlyON ), jmxAttribute ); - ObjectName newDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); + final ObjectName newDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); - ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(newDependentReadOnlyON, ObjectNameUtil + final ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(newDependentReadOnlyON, ObjectNameUtil .TYPE_MODULE); - ModuleFactory foundFactory = modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute); + final ModuleFactory foundFactory = this.modulesHolder.findModuleFactory(moduleIdentifier, jmxAttribute); - boolean implementsSI = foundFactory + final boolean implementsSI = foundFactory .isModuleImplementingServiceInterface(expectedServiceInterface); - if (implementsSI == false) { - String message = format( + 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", @@ -128,18 +127,18 @@ final class DependencyResolverImpl implements DependencyResolver, throw new JmxAttributeValidationException(message, jmxAttribute); } synchronized (this) { - dependencies.add(moduleIdentifier); + this.dependencies.add(moduleIdentifier); } } // translate from serviceref to module ON - private ObjectName translateServiceRefIfPossible(ObjectName dependentReadOnlyON) { + private ObjectName translateServiceRefIfPossible(final ObjectName dependentReadOnlyON) { ObjectName translatedDependentReadOnlyON = dependentReadOnlyON; if (ObjectNameUtil.isServiceReference(translatedDependentReadOnlyON)) { - String serviceQName = ObjectNameUtil.getServiceQName(translatedDependentReadOnlyON); - String refName = ObjectNameUtil.getReferenceName(translatedDependentReadOnlyON); + final String serviceQName = ObjectNameUtil.getServiceQName(translatedDependentReadOnlyON); + final String refName = ObjectNameUtil.getReferenceName(translatedDependentReadOnlyON); translatedDependentReadOnlyON = ObjectNameUtil.withoutTransactionName( // strip again of transaction name - readableRegistry.lookupConfigBeanByServiceInterfaceName(serviceQName, refName)); + this.readableRegistry.lookupConfigBeanByServiceInterfaceName(serviceQName, refName)); } return translatedDependentReadOnlyON; } @@ -149,26 +148,26 @@ final class DependencyResolverImpl implements DependencyResolver, */ //TODO: check for cycles @Override - public T resolveInstance(Class expectedType, ObjectName dependentReadOnlyON, - JmxAttribute jmxAttribute) { - Module module = resolveModuleInstance(dependentReadOnlyON, jmxAttribute); + public T resolveInstance(final Class expectedType, final ObjectName dependentReadOnlyON, + final JmxAttribute jmxAttribute) { + final Module module = resolveModuleInstance(dependentReadOnlyON, jmxAttribute); synchronized (this) { - dependencies.add(module.getIdentifier()); + this.dependencies.add(module.getIdentifier()); } - AutoCloseable instance = module.getInstance(); + final AutoCloseable instance = module.getInstance(); if (instance == null) { - String message = format( + final String message = String.format( "Error while %s resolving instance %s. getInstance() returned null. " - + "Expected type %s , attribute %s", name, + + "Expected type %s , attribute %s", this.name, module.getIdentifier(), expectedType, jmxAttribute ); throw new JmxAttributeValidationException(message, jmxAttribute); } try { return expectedType.cast(instance); - } catch (ClassCastException e) { - String message = format( + } catch (final ClassCastException e) { + final String message = String.format( "Instance cannot be cast to expected type. Instance class is %s , " + "expected type %s , attribute %s", instance.getClass(), expectedType, jmxAttribute @@ -177,43 +176,43 @@ final class DependencyResolverImpl implements DependencyResolver, } } - private Module resolveModuleInstance(ObjectName dependentReadOnlyON, - JmxAttribute jmxAttribute) { + private Module resolveModuleInstance(final ObjectName dependentReadOnlyON, + final JmxAttribute jmxAttribute) { Preconditions.checkArgument(dependentReadOnlyON != null ,"dependentReadOnlyON"); Preconditions.checkArgument(jmxAttribute != null, "jmxAttribute"); - ObjectName translatedDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); - transactionStatus.checkCommitStarted(); - transactionStatus.checkNotCommitted(); + final ObjectName translatedDependentReadOnlyON = translateServiceRefIfPossible(dependentReadOnlyON); + this.transactionStatus.checkCommitStarted(); + this.transactionStatus.checkNotCommitted(); - ModuleIdentifier dependentModuleIdentifier = ObjectNameUtil.fromON( + final ModuleIdentifier dependentModuleIdentifier = ObjectNameUtil.fromON( translatedDependentReadOnlyON, ObjectNameUtil.TYPE_MODULE); - return Preconditions.checkNotNull(modulesHolder.findModule(dependentModuleIdentifier, jmxAttribute)); + return Preconditions.checkNotNull(this.modulesHolder.findModule(dependentModuleIdentifier, jmxAttribute)); } @Override - public boolean canReuseDependency(ObjectName objectName, JmxAttribute jmxAttribute) { + public boolean canReuseDependency(final ObjectName objectName, final JmxAttribute jmxAttribute) { Preconditions.checkNotNull(objectName); Preconditions.checkNotNull(jmxAttribute); - Module currentModule = resolveModuleInstance(objectName, jmxAttribute); - ModuleIdentifier identifier = currentModule.getIdentifier(); - ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = modulesHolder.findModuleInternalTransactionalInfo(identifier); + final Module currentModule = resolveModuleInstance(objectName, jmxAttribute); + final ModuleIdentifier identifier = currentModule.getIdentifier(); + final ModuleInternalTransactionalInfo moduleInternalTransactionalInfo = this.modulesHolder.findModuleInternalTransactionalInfo(identifier); if(moduleInternalTransactionalInfo.hasOldModule()) { - Module oldModule = moduleInternalTransactionalInfo.getOldInternalInfo().getReadableModule().getModule(); + final Module oldModule = moduleInternalTransactionalInfo.getOldInternalInfo().getReadableModule().getModule(); return currentModule.canReuse(oldModule); } return false; } @Override - public Class resolveIdentity(IdentityAttributeRef identityRef, Class expectedBaseClass) { + public Class resolveIdentity(final IdentityAttributeRef identityRef, final Class expectedBaseClass) { final QName qName = QName.create(identityRef.getqNameOfIdentity()); - Class deserialized = bindingContextProvider.getBindingContext().getIdentityClass(qName); + final Class deserialized = this.bindingContextProvider.getBindingContext().getIdentityClass(qName); if (deserialized == null) { throw new IllegalStateException("Unable to retrieve identity class for " + qName + ", null response from " - + bindingContextProvider.getBindingContext()); + + this.bindingContextProvider.getBindingContext()); } if (expectedBaseClass.isAssignableFrom(deserialized)) { return (Class) deserialized; @@ -225,54 +224,52 @@ final class DependencyResolverImpl implements DependencyResolver, } @Override - public void validateIdentity(IdentityAttributeRef identityRef, Class expectedBaseClass, JmxAttribute jmxAttribute) { + public void validateIdentity(final IdentityAttributeRef identityRef, final Class expectedBaseClass, final JmxAttribute jmxAttribute) { try { resolveIdentity(identityRef, expectedBaseClass); - } catch (Exception e) { + } catch (final Exception e) { throw JmxAttributeValidationException.wrap(e, jmxAttribute); } } @Override - public int compareTo(DependencyResolverImpl o) { - transactionStatus.checkCommitStarted(); + public int compareTo(final DependencyResolverImpl o) { + this.transactionStatus.checkCommitStarted(); return Integer.compare(getMaxDependencyDepth(), o.getMaxDependencyDepth()); } - private Integer maxDependencyDepth; - int getMaxDependencyDepth() { - if (maxDependencyDepth == null) { + if (this.maxDependencyDepth == null) { throw new IllegalStateException("Dependency depth was not computed"); } - return maxDependencyDepth; + return this.maxDependencyDepth; } - void countMaxDependencyDepth(DependencyResolverManager manager) { + void countMaxDependencyDepth(final DependencyResolverManager manager) { // We can calculate the dependency after second phase commit was started // Second phase commit starts after validation and validation adds the dependencies into the dependency resolver, which are necessary for the calculation // FIXME generated code for abstract module declares validate method as non-final // Overriding the validate would cause recreate every time instead of reuse + also possibly wrong close order if there is another module depending - transactionStatus.checkCommitStarted(); - if (maxDependencyDepth == null) { - maxDependencyDepth = getMaxDepth(this, manager, + this.transactionStatus.checkCommitStarted(); + if (this.maxDependencyDepth == null) { + this.maxDependencyDepth = getMaxDepth(this, manager, new LinkedHashSet<>()); } } - private static int getMaxDepth(DependencyResolverImpl impl, - DependencyResolverManager manager, - LinkedHashSet chainForDetectingCycles) { + private static int getMaxDepth(final DependencyResolverImpl impl, + final DependencyResolverManager manager, + final LinkedHashSet chainForDetectingCycles) { int maxDepth = 0; - LinkedHashSet chainForDetectingCycles2 = new LinkedHashSet<>( + final LinkedHashSet chainForDetectingCycles2 = new LinkedHashSet<>( chainForDetectingCycles); chainForDetectingCycles2.add(impl.getIdentifier()); - for (ModuleIdentifier dependencyName : impl.dependencies) { - DependencyResolverImpl dependentDRI = manager + for (final ModuleIdentifier dependencyName : impl.dependencies) { + final DependencyResolverImpl dependentDRI = manager .getOrCreate(dependencyName); if (chainForDetectingCycles2.contains(dependencyName)) { - throw new IllegalStateException(format( + throw new IllegalStateException(String.format( "Cycle detected, %s contains %s", chainForDetectingCycles2, dependencyName)); } @@ -284,7 +281,7 @@ final class DependencyResolverImpl implements DependencyResolver, chainForDetectingCycles2); dependentDRI.maxDependencyDepth = subDepth; } - if (subDepth + 1 > maxDepth) { + if ((subDepth + 1) > maxDepth) { maxDepth = subDepth + 1; } } @@ -294,23 +291,23 @@ final class DependencyResolverImpl implements DependencyResolver, @Override public ModuleIdentifier getIdentifier() { - return name; + return this.name; } @Override - public Object getAttribute(ObjectName name, String attribute) + public Object getAttribute(final ObjectName name, final String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { ObjectName newName = translateServiceRefIfPossible(name); // add transaction name - newName = ObjectNameUtil.withTransactionName(newName, transactionName); - return mBeanServer.getAttribute(newName, attribute); + newName = ObjectNameUtil.withTransactionName(newName, this.transactionName); + return this.mBeanServer.getAttribute(newName, attribute); } @Override - public T newMXBeanProxy(ObjectName name, Class interfaceClass) { + public T newMXBeanProxy(final ObjectName name, final Class interfaceClass) { ObjectName newName = translateServiceRefIfPossible(name); // add transaction name - newName = ObjectNameUtil.withTransactionName(newName, transactionName); - return JMX.newMXBeanProxy(mBeanServer, newName, interfaceClass); + newName = ObjectNameUtil.withTransactionName(newName, this.transactionName); + return JMX.newMXBeanProxy(this.mBeanServer, newName, interfaceClass); } }