From 6227570f6482136b72a26675d43c8bb88279503e Mon Sep 17 00:00:00 2001 From: Dana Kutenicsova Date: Tue, 4 Oct 2016 22:02:55 +0200 Subject: [PATCH] Fixed few sonar warnings. Removed static imports. Change-Id: Ife05c6c4fc288c70624880eefbe9c5be8b47b974 Signed-off-by: Dana Kutenicsova --- ...eableServiceReferenceReadableRegistry.java | 2 +- .../manager/impl/ConfigRegistryImpl.java | 23 ++-- .../impl/ConfigTransactionControllerImpl.java | 32 ++--- .../impl/ConfigTransactionLookupRegistry.java | 3 +- .../config/manager/impl/DeadlockMonitor.java | 16 ++- .../impl/ServiceReferenceRegistryImpl.java | 119 +++++++++--------- .../manager/impl/TransactionStatus.java | 10 +- .../DependencyResolverImpl.java | 19 ++- .../DependencyResolverManager.java | 3 +- .../ModuleInternalTransactionalInfo.java | 3 +- .../dynamicmbean/AbstractDynamicWrapper.java | 72 +++++------ .../impl/dynamicmbean/AnnotationsHelper.java | 9 +- .../impl/dynamicmbean/AttributeHolder.java | 11 +- .../dynamicmbean/DynamicWritableWrapper.java | 9 +- ...ierarchicalConfigMBeanFactoriesHolder.java | 3 +- .../manager/impl/jmx/ServiceReference.java | 3 +- .../impl/jmx/ServiceReferenceRegistrator.java | 7 +- .../impl/jmx/TransactionJMXRegistrator.java | 3 +- .../jmx/TransactionModuleJMXRegistrator.java | 3 +- .../impl/osgi/BeanToOsgiServiceManager.java | 21 ++-- .../osgi/BlankTransactionServiceTracker.java | 14 +-- .../impl/osgi/ConfigManagerActivator.java | 17 ++- .../impl/osgi/ExtensibleBundleTracker.java | 35 ++---- .../impl/osgi/ModuleFactoryBundleTracker.java | 3 +- .../osgi/mapping/ModuleInfoBundleTracker.java | 12 +- .../RefreshingSCPModuleInfoRegistry.java | 9 +- .../manager/impl/util/InterfacesHelper.java | 8 +- .../impl/util/OsgiRegistrationUtil.java | 55 +++----- .../DynamicWritableWrapperTest.java | 4 +- .../test/DependentWiringTest.java | 2 - 30 files changed, 236 insertions(+), 294 deletions(-) diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/CloseableServiceReferenceReadableRegistry.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/CloseableServiceReferenceReadableRegistry.java index bf010bb3a6..87067e8324 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/CloseableServiceReferenceReadableRegistry.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/CloseableServiceReferenceReadableRegistry.java @@ -15,6 +15,6 @@ import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry; */ public interface CloseableServiceReferenceReadableRegistry extends AutoCloseable, ServiceReferenceReadableRegistry { + @Override void close(); - } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java index b58d2afd24..763ed66cb1 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.config.manager.impl; +import com.google.common.base.Throwables; import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.Collection; @@ -113,7 +114,8 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe @GuardedBy("configTransactionLock") private List lastListOfFactories = Collections.emptyList(); - @GuardedBy("readableSRRegistryLock") // switched in every 2ndPC + // switched in every 2ndPC + @GuardedBy("readableSRRegistryLock") private CloseableServiceReferenceReadableRegistry readableSRRegistry = ServiceReferenceRegistryImpl.createInitialSRLookupRegistry(); @@ -207,7 +209,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // add all factories that disappeared from SR but are still committed for (ModuleInternalInfo moduleInternalInfo : currentConfig.getEntries()) { String name = moduleInternalInfo.getModuleFactory().getImplementationName(); - if (allCurrentFactories.containsKey(name) == false) { + if (!allCurrentFactories.containsKey(name)) { LOG.trace("Factory {} not found in SR, using reference from previous commit", name); allCurrentFactories.put(name, Maps.immutableEntry(moduleInternalInfo.getModuleFactory(), moduleInternalInfo.getBundleContext())); @@ -237,11 +239,12 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe /** * {@inheritDoc} + * @throws ConflictingVersionException */ @Override public CommitStatus commitConfig(ObjectName transactionControllerON) - throws ConflictingVersionException, ValidationException { - if(transactionControllerON == NOOP_TX_NAME || closed.get()) { + throws ValidationException, ConflictingVersionException { + if(NOOP_TX_NAME.equals(transactionControllerON) || closed.get()) { return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); } @@ -283,15 +286,12 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // non recoverable from here: try { return secondPhaseCommit(configTransactionController, commitInfo, configTransactionControllerEntry.getValue()); - } catch (Error | RuntimeException t) { // some libs throw Errors: e.g. + // some libs throw Errors: e.g. // javax.xml.ws.spi.FactoryFinder$ConfigurationError + } catch (Throwable t) { isHealthy = false; LOG.error("Configuration Transaction failed on 2PC, server is unhealthy", t); - if (t instanceof RuntimeException) { - throw (RuntimeException) t; - } else { - throw (Error) t; - } + throw Throwables.propagate(t); } } @@ -303,10 +303,11 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe // (hopefully) runtime beans for (DestroyedModule toBeDestroyed : commitInfo .getDestroyedFromPreviousTransactions()) { - toBeDestroyed.close(); // closes instance (which should close + // closes instance (which should close // runtime jmx registrator), // also closes osgi registration and ModuleJMXRegistrator // registration + toBeDestroyed.close(); currentConfig.remove(toBeDestroyed.getIdentifier()); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java index e426d70df7..ad64288ab2 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java @@ -7,8 +7,7 @@ */ package org.opendaylight.controller.config.manager.impl; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Collection; @@ -48,6 +47,7 @@ import org.opendaylight.yangtools.concepts.Identifiable; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** * This is a JMX bean representing current transaction. It contains * transaction identifier, unique version and parent version for @@ -62,7 +62,8 @@ class ConfigTransactionControllerImpl implements private final ConfigTransactionLookupRegistry txLookupRegistry; private final ObjectName controllerON; - private final long parentVersion, currentVersion; + private final long parentVersion; + private final long currentVersion; private final HierarchicalConfigMBeanFactoriesHolder factoriesHolder; private final DependencyResolverManager dependencyResolverManager; private final TransactionStatus transactionStatus; @@ -129,12 +130,12 @@ class ConfigTransactionControllerImpl implements List toBeAdded = new ArrayList<>(); List toBeRemoved = new ArrayList<>(); for (ModuleFactory moduleFactory : factoriesHolder.getModuleFactories()) { - if (oldSet.contains(moduleFactory) == false) { + if (!oldSet.contains(moduleFactory)) { toBeAdded.add(moduleFactory); } } for (ModuleFactory moduleFactory : lastListOfFactories) { - if (newSet.contains(moduleFactory) == false) { + if (!newSet.contains(moduleFactory)) { toBeRemoved.add(moduleFactory); } } @@ -214,7 +215,7 @@ class ConfigTransactionControllerImpl implements moduleIdentifier.getInstanceName(), dependencyResolver, oldConfigBeanInfo.getReadableModule(), bc); } catch (Exception e) { - throw new IllegalStateException(format( + throw new IllegalStateException(String.format( "Error while copying old configuration from %s to %s", oldConfigBeanInfo, moduleFactory), e); } @@ -266,16 +267,16 @@ class ConfigTransactionControllerImpl implements throws InstanceAlreadyExistsException { LOG.debug("Adding module {} to transaction {}", moduleIdentifier, this); - if (moduleIdentifier.equals(module.getIdentifier()) == false) { + if (!moduleIdentifier.equals(module.getIdentifier())) { throw new IllegalStateException("Incorrect name reported by module. Expected " + moduleIdentifier + ", got " + module.getIdentifier()); } - if (dependencyResolver.getIdentifier().equals(moduleIdentifier) == false) { + if (!dependencyResolver.getIdentifier().equals(moduleIdentifier)) { throw new IllegalStateException("Incorrect name reported by dependency resolver. Expected " + moduleIdentifier + ", got " + dependencyResolver.getIdentifier()); } DynamicMBean writableDynamicWrapper = new DynamicWritableWrapper( - module, moduleIdentifier, getTransactionIdentifier(), + module, moduleIdentifier, getTransactionIdentifier().getName(), readOnlyAtomicBoolean, transactionsMBeanServer, configMBeanServer); @@ -303,7 +304,7 @@ class ConfigTransactionControllerImpl implements private void checkTransactionName(ObjectName objectName) { String foundTransactionName = ObjectNameUtil .getTransactionName(objectName); - if (getTransactionIdentifier().getName().equals(foundTransactionName) == false) { + if (!getTransactionIdentifier().getName().equals(foundTransactionName)) { throw new IllegalArgumentException("Wrong transaction name " + objectName); } @@ -314,7 +315,7 @@ class ConfigTransactionControllerImpl implements transactionStatus.checkNotAborted(); ModuleInternalTransactionalInfo found = dependencyResolverManager.findModuleInternalTransactionalInfo(moduleIdentifier); - if (blankTransaction == false && + if (!blankTransaction && found.isDefaultBean()) { LOG.warn("Warning: removing default bean. This will be forbidden in next version of config-subsystem"); } @@ -398,7 +399,8 @@ class ConfigTransactionControllerImpl implements validateNoLocks(); } catch (ValidationException e) { LOG.trace("Commit failed on validation"); - configBeanModificationDisabled.set(false); // recoverable error + // recoverable error + configBeanModificationDisabled.set(false); throw e; } // errors in this state are not recoverable. modules are not mutable @@ -414,7 +416,7 @@ class ConfigTransactionControllerImpl implements public synchronized List secondPhaseCommit() { transactionStatus.checkNotAborted(); transactionStatus.checkCommitStarted(); - if (configBeanModificationDisabled.get() == false) { + if (!configBeanModificationDisabled.get()) { throw new IllegalStateException( "Internal error - validateBeforeCommitAndLockTransaction should be called " + "to obtain a lock"); @@ -435,13 +437,13 @@ class ConfigTransactionControllerImpl implements LOG.debug("About to commit {} in transaction {}", moduleIdentifier, getTransactionIdentifier()); AutoCloseable instance = module.getInstance(); - checkNotNull(instance, "Instance is null:{} in transaction {}", moduleIdentifier, getTransactionIdentifier()); + Preconditions.checkNotNull(instance, "Instance is null:{} in transaction {}", moduleIdentifier, getTransactionIdentifier()); } catch (Exception e) { LOG.error("Commit failed on {} in transaction {}", moduleIdentifier, getTransactionIdentifier(), e); internalAbort(); throw new IllegalStateException( - format("Error - getInstance() failed for %s in transaction %s", + String.format("Error - getInstance() failed for %s in transaction %s", moduleIdentifier, getTransactionIdentifier()), e); } } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionLookupRegistry.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionLookupRegistry.java index a0138b2d9d..79bffb49da 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionLookupRegistry.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionLookupRegistry.java @@ -44,7 +44,7 @@ class ConfigTransactionLookupRegistry implements LookupRegistry, Closeable { private void checkTransactionName(ObjectName objectName) { String foundTransactionName = ObjectNameUtil .getTransactionName(objectName); - if (transactionIdentifier.getName().equals(foundTransactionName) == false) { + if (!transactionIdentifier.getName().equals(foundTransactionName)) { throw new IllegalArgumentException("Wrong transaction name " + objectName); } @@ -103,6 +103,7 @@ class ConfigTransactionLookupRegistry implements LookupRegistry, Closeable { return txModuleJMXRegistrator; } + @Override public void close() { transactionJMXRegistrator.close(); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java index 9882b4662c..20e5fe6584 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java @@ -27,7 +27,7 @@ public class DeadlockMonitor implements AutoCloseable { @GuardedBy("this") private final Deque moduleIdentifierWithNanosStack = new LinkedList<>(); @GuardedBy("this") - private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.EMPTY; + private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.empty; public DeadlockMonitor(TransactionIdentifier transactionIdentifier) { this.transactionIdentifier = transactionIdentifier; @@ -41,7 +41,7 @@ public class DeadlockMonitor implements AutoCloseable { if (popping) { moduleIdentifierWithNanosStack.pop(); if (moduleIdentifierWithNanosStack.isEmpty()) { - top = ModuleIdentifierWithNanos.EMPTY; + top = ModuleIdentifierWithNanos.empty; } else { top = moduleIdentifierWithNanosStack.peekLast(); } @@ -75,14 +75,15 @@ public class DeadlockMonitor implements AutoCloseable { @Override public void run() { - ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); // null moduleId - while (this.isInterrupted() == false) { + // null moduleId + ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); + while (!this.isInterrupted()) { ModuleIdentifierWithNanos copy; synchronized(this) { copy = new ModuleIdentifierWithNanos(DeadlockMonitor.this.top); } - if (old.moduleIdentifier == null || old.equals(copy) == false) { + if (old.moduleIdentifier == null || !old.equals(copy)) { // started old = copy; } else { @@ -107,11 +108,8 @@ public class DeadlockMonitor implements AutoCloseable { } } - - - private static class ModuleIdentifierWithNanos { - private static ModuleIdentifierWithNanos EMPTY = new ModuleIdentifierWithNanos(); + private static ModuleIdentifierWithNanos empty = new ModuleIdentifierWithNanos(); @Nullable private final ModuleIdentifier moduleIdentifier; diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java index 53e9d47300..4e89a653b8 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.config.manager.impl; -import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.AbstractMap.SimpleImmutableEntry; @@ -60,6 +60,54 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe private final boolean writable; private final Map> mBeans = new HashMap<>(); + private ServiceReferenceRegistryImpl(final Map factories, final LookupRegistry lookupRegistry, + final ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory, final boolean writable) { + this.factories = factories; + this.writable = writable; + this.lookupRegistry = lookupRegistry; + + this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create(); + + Map> modifiableFactoryNamesToQNames = new HashMap<>(); + Set allAnnotations = new HashSet<>(); + Set allQNameSet = new HashSet<>(); + + for (Entry entry : factories.entrySet()) { + if (!entry.getKey().equals(entry.getValue().getImplementationName())) { + LOG.error("Possible error in code: Mismatch between supplied and actual name of {}", entry); + throw new IllegalArgumentException("Possible error in code: Mismatch between supplied and actual name of " + entry); + } + Set siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue()); + Set qNames = InterfacesHelper.getQNames(siAnnotations); + allAnnotations.addAll(siAnnotations); + allQNameSet.addAll(qNames); + modifiableFactoryNamesToQNames.put(entry.getKey(), qNames); + } + this.factoryNamesToQNames = ImmutableMap.copyOf(modifiableFactoryNamesToQNames); + this.allQNames = ImmutableSet.copyOf(allQNameSet); + // fill namespacesToAnnotations + Map> modifiableNamespacesToAnnotations = new HashMap<>(); + Map modifiableServiceQNamesToAnnotations = new HashMap<>(); + for (ServiceInterfaceAnnotation sia : allAnnotations) { + Map ofNamespace = modifiableNamespacesToAnnotations.get(sia.namespace()); + if (ofNamespace == null) { + ofNamespace = new HashMap<>(); + modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace); + } + if (ofNamespace.containsKey(sia.localName())) { + LOG.error( + "Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}", + sia.namespace(), sia.localName(), modifiableNamespacesToAnnotations); + throw new IllegalArgumentException("Conflict between local names in " + sia.namespace() + " : " + sia.localName()); + } + ofNamespace.put(sia.localName(), sia); + modifiableServiceQNamesToAnnotations.put(sia.value(), sia); + } + this.namespacesToAnnotations = ImmutableMap.copyOf(modifiableNamespacesToAnnotations); + this.serviceQNamesToAnnotations = ImmutableMap.copyOf(modifiableServiceQNamesToAnnotations); + LOG.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames); + } + /** * Static constructor for config registry. Since only transaction can write to this registry, it will * return blank state. @@ -202,56 +250,6 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe return result; } - private ServiceReferenceRegistryImpl(final Map factories, final LookupRegistry lookupRegistry, - final ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory, - final boolean writable) { - this.factories = factories; - this.writable = writable; - this.lookupRegistry = lookupRegistry; - - this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create(); - - Map> modifiableFactoryNamesToQNames = new HashMap<>(); - Set allAnnotations = new HashSet<>(); - Set allQNameSet = new HashSet<>(); - - - for (Entry entry : factories.entrySet()) { - if (entry.getKey().equals(entry.getValue().getImplementationName()) == false) { - LOG.error("Possible error in code: Mismatch between supplied and actual name of {}", entry); - throw new IllegalArgumentException("Possible error in code: Mismatch between supplied and actual name of " + entry); - } - Set siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue()); - Set qNames = InterfacesHelper.getQNames(siAnnotations); - allAnnotations.addAll(siAnnotations); - allQNameSet.addAll(qNames); - modifiableFactoryNamesToQNames.put(entry.getKey(), qNames); - } - this.factoryNamesToQNames = ImmutableMap.copyOf(modifiableFactoryNamesToQNames); - this.allQNames = ImmutableSet.copyOf(allQNameSet); - // fill namespacesToAnnotations - Map> modifiableNamespacesToAnnotations = - new HashMap<>(); - Map modifiableServiceQNamesToAnnotations = new HashMap<>(); - for (ServiceInterfaceAnnotation sia : allAnnotations) { - Map ofNamespace = modifiableNamespacesToAnnotations.get(sia.namespace()); - if (ofNamespace == null) { - ofNamespace = new HashMap<>(); - modifiableNamespacesToAnnotations.put(sia.namespace(), ofNamespace); - } - if (ofNamespace.containsKey(sia.localName())) { - LOG.error("Cannot construct namespacesToAnnotations map, conflict between local names in {}, offending local name: {}, map so far {}", - sia.namespace(), sia.localName(), modifiableNamespacesToAnnotations); - throw new IllegalArgumentException("Conflict between local names in " + sia.namespace() + " : " + sia.localName()); - } - ofNamespace.put(sia.localName(), sia); - modifiableServiceQNamesToAnnotations.put(sia.value(), sia); - } - this.namespacesToAnnotations = ImmutableMap.copyOf(modifiableNamespacesToAnnotations); - this.serviceQNamesToAnnotations = ImmutableMap.copyOf(modifiableServiceQNamesToAnnotations); - LOG.trace("factoryNamesToQNames:{}", this.factoryNamesToQNames); - } - @Override public Map findServiceInterfaces(final ModuleIdentifier moduleIdentifier) { Map result = modulesToServiceRef.get(moduleIdentifier); @@ -343,7 +341,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe @Override public synchronized ObjectName getServiceReference(final String serviceInterfaceQName, final String refName) throws InstanceNotFoundException { ServiceReference serviceReference = new ServiceReference(serviceInterfaceQName, refName); - if (mBeans.containsKey(serviceReference) == false) { + if (!mBeans.containsKey(serviceReference)) { throw new InstanceNotFoundException("Cannot find " + serviceReference); } return getServiceON(serviceReference); @@ -353,22 +351,21 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe public synchronized void checkServiceReferenceExists(final ObjectName objectName) throws InstanceNotFoundException { String actualTransactionName = ObjectNameUtil.getTransactionName(objectName); String expectedTransactionName = serviceReferenceRegistrator.getNullableTransactionName(); - if (writable & actualTransactionName == null || (writable && actualTransactionName.equals(expectedTransactionName) == false)) { + if (writable && actualTransactionName == null || (writable && !actualTransactionName.equals(expectedTransactionName))) { throw new IllegalArgumentException("Mismatched transaction name in " + objectName); } String serviceQName = ObjectNameUtil.getServiceQName(objectName); String referenceName = ObjectNameUtil.getReferenceName(objectName); ServiceReference serviceReference = new ServiceReference(serviceQName, referenceName); - if (refNames.containsKey(serviceReference) == false) { + if (!refNames.containsKey(serviceReference)) { LOG.warn("Cannot find {} in {}", serviceReference, refNames); throw new InstanceNotFoundException("Service reference not found:" + objectName); } } // writing: - private void assertWritable() { - if (writable == false) { + if (!writable) { throw new IllegalStateException("Cannot write to readable registry"); } } @@ -389,7 +386,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe final boolean skipChecks) throws InstanceNotFoundException { // make sure it is found - if (skipChecks == false) { + if (!skipChecks) { lookupRegistry.checkConfigBeanExists(moduleON); } String factoryName = ObjectNameUtil.getFactoryName(moduleON); @@ -404,7 +401,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe 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()) == false) { + 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()); } @@ -436,7 +433,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe } ServiceInterfaceAnnotation annotation = serviceQNamesToAnnotations.get(serviceReference.getServiceInterfaceQName()); - checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference); + Preconditions.checkNotNull(annotation, "Possible error in code, cannot find annotation for " + serviceReference); refNamesToAnnotations.put(annotation, serviceReference.getRefName()); return result; } @@ -460,7 +457,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe LOG.debug("Removing service reference {} from {}", serviceReference, this); assertWritable(); // is the qName known? - if (allQNames.contains(serviceReference.getServiceInterfaceQName()) == false) { + if (!allQNames.contains(serviceReference.getServiceInterfaceQName())) { LOG.error("Cannot find qname {} in {}", serviceReference.getServiceInterfaceQName(), allQNames); throw new IllegalArgumentException("Cannot find service interface " + serviceReference.getServiceInterfaceQName()); } @@ -504,7 +501,7 @@ public class ServiceReferenceRegistryImpl implements CloseableServiceReferenceRe for (ServiceReference sr : serviceReferencesLinkingTo) { removeServiceReference(sr); } - return serviceReferencesLinkingTo.isEmpty() == false; + return !serviceReferencesLinkingTo.isEmpty(); } private Set findServiceReferencesLinkingTo(final ObjectName moduleObjectName, final Set serviceInterfaceQNames) { diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionStatus.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionStatus.java index f86d6b1d81..af333c3893 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionStatus.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/TransactionStatus.java @@ -48,32 +48,32 @@ public class TransactionStatus { } public synchronized void checkNotCommitStarted() { - if (secondPhaseCommitStarted == true) { + if (secondPhaseCommitStarted) { throw new IllegalStateException("Commit was triggered"); } } public synchronized void checkCommitStarted() { - if (secondPhaseCommitStarted == false) { + if (!secondPhaseCommitStarted) { throw new IllegalStateException("Commit was not triggered"); } } public synchronized void checkNotAborted() { - if (aborted == true) { + if (aborted) { throw new IllegalStateException("Configuration was aborted"); } } public synchronized void checkNotCommitted() { - if (committed == true) { + if (committed) { throw new IllegalStateException( "Cannot use this method after second phase commit"); } } public synchronized void checkCommitted() { - if (committed == false) { + if (!committed) { throw new IllegalStateException( "Cannot use this method before second phase commit"); } 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..d667f13ec6 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,6 +54,7 @@ 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, @@ -100,8 +99,8 @@ final class DependencyResolverImpl implements DependencyResolver, 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 @@ -116,8 +115,8 @@ final class DependencyResolverImpl implements DependencyResolver, boolean implementsSI = foundFactory .isModuleImplementingServiceInterface(expectedServiceInterface); - if (implementsSI == false) { - String message = format( + if (!implementsSI) { + 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", @@ -158,7 +157,7 @@ final class DependencyResolverImpl implements DependencyResolver, } AutoCloseable instance = module.getInstance(); if (instance == null) { - String message = format( + String message = String.format( "Error while %s resolving instance %s. getInstance() returned null. " + "Expected type %s , attribute %s", name, module.getIdentifier(), expectedType, jmxAttribute @@ -168,7 +167,7 @@ final class DependencyResolverImpl implements DependencyResolver, try { return expectedType.cast(instance); } catch (ClassCastException e) { - String message = format( + String message = String.format( "Instance cannot be cast to expected type. Instance class is %s , " + "expected type %s , attribute %s", instance.getClass(), expectedType, jmxAttribute @@ -240,8 +239,6 @@ final class DependencyResolverImpl implements DependencyResolver, o.getMaxDependencyDepth()); } - private Integer maxDependencyDepth; - int getMaxDependencyDepth() { if (maxDependencyDepth == null) { throw new IllegalStateException("Dependency depth was not computed"); @@ -272,7 +269,7 @@ final class DependencyResolverImpl implements DependencyResolver, 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)); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManager.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManager.java index 231022f34a..f8906735b6 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManager.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManager.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.dependencyresolver; -import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Preconditions; import com.google.common.reflect.AbstractInvocationHandler; import com.google.common.reflect.Reflection; @@ -142,7 +141,7 @@ public class DependencyResolverManager implements DependencyResolverFactory, Aut return cachedInstance; } - checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive"); + Preconditions.checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive"); deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier); } try { diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/ModuleInternalTransactionalInfo.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/ModuleInternalTransactionalInfo.java index 771cddd442..b8d6c26f35 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/ModuleInternalTransactionalInfo.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/ModuleInternalTransactionalInfo.java @@ -21,7 +21,8 @@ import org.osgi.framework.BundleContext; public class ModuleInternalTransactionalInfo implements Identifiable { private final ModuleIdentifier name; - private final Module proxiedModule, realModule; + private final Module proxiedModule; + private final Module realModule; private final ModuleFactory moduleFactory; private final TransactionModuleJMXRegistration transactionModuleJMXRegistration; diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java index 0346bdd19c..23a4424a0b 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java @@ -7,8 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.dynamicmbean; -import static java.lang.String.format; - import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; @@ -59,14 +57,12 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { private static final class ModuleNotificationListener implements NotificationListener { private final ObjectName objectNameInternal; private final MBeanServer internalServer; - private final ObjectName thisWrapperObjectName; private final MBeanServer configMBeanServer; private ModuleNotificationListener(final ObjectName objectNameInternal, final MBeanServer internalServer, - final ObjectName thisWrapperObjectName, final MBeanServer configMBeanServer) { + final MBeanServer configMBeanServer) { this.objectNameInternal = objectNameInternal; this.internalServer = internalServer; - this.thisWrapperObjectName = thisWrapperObjectName; this.configMBeanServer = configMBeanServer; } @@ -74,25 +70,23 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { public void handleNotification(final Notification n, final Object handback) { if (n instanceof MBeanServerNotification && n.getType() - .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { - if (((MBeanServerNotification) n).getMBeanName().equals( - thisWrapperObjectName)) { - try { - internalServer.unregisterMBean(objectNameInternal); - configMBeanServer.removeNotificationListener( - MBeanServerDelegate.DELEGATE_NAME, this); - } catch (MBeanRegistrationException - | ListenerNotFoundException - | InstanceNotFoundException e) { - throw new IllegalStateException(e); - } + .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION) + && ((MBeanServerNotification) n).getMBeanName().equals( + objectNameInternal)) { + try { + internalServer.unregisterMBean(objectNameInternal); + configMBeanServer.removeNotificationListener( + MBeanServerDelegate.DELEGATE_NAME, this); + } catch (MBeanRegistrationException + | ListenerNotFoundException + | InstanceNotFoundException e) { + throw new IllegalStateException(e); } } } } private static final Logger LOG = LoggerFactory.getLogger(AbstractDynamicWrapper.class); - protected final boolean writable; protected final Module module; private final MBeanInfo mbeanInfo; @@ -106,20 +100,17 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { final ObjectName thisWrapperObjectName, final MBeanOperationInfo[] dOperations, final MBeanServer internalServer, final MBeanServer configMBeanServer) { - this.writable = writable; this.module = module; this.moduleIdentifier = moduleIdentifier; this.internalServer = internalServer; this.objectNameInternal = thisWrapperObjectName; // register the actual instance into an mbean server. - registerActualModule(module, thisWrapperObjectName, objectNameInternal, - internalServer, configMBeanServer); + registerActualModule(objectNameInternal, configMBeanServer); Set> jmxInterfaces = InterfacesHelper.getMXInterfaces(module .getClass()); - this.attributeHolderMap = buildMBeanInfo(module, writable, - moduleIdentifier, jmxInterfaces, internalServer, - objectNameInternal); - this.mbeanInfo = generateMBeanInfo(module.getClass().getName(), module, + this.attributeHolderMap = buildMBeanInfo(writable, + moduleIdentifier, jmxInterfaces, objectNameInternal); + this.mbeanInfo = generateMBeanInfo(module, attributeHolderMap, dOperations, jmxInterfaces); } @@ -128,12 +119,8 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { * platform mbean server. Wait until this wrapper gets unregistered, in that * case unregister the module and remove listener. */ - private final NotificationListener registerActualModule(final Module module, - final ObjectName thisWrapperObjectName, - final ObjectName objectNameInternal, - final MBeanServer internalServer, + private final NotificationListener registerActualModule(final ObjectName objectNameInternal, final MBeanServer configMBeanServer) { - try { internalServer.registerMBean(module, objectNameInternal); } catch (InstanceAlreadyExistsException | MBeanRegistrationException @@ -142,7 +129,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { "Error occured during mbean registration with name " + objectNameInternal, e); } - NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, thisWrapperObjectName, configMBeanServer); + NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, configMBeanServer); try { configMBeanServer.addNotificationListener( MBeanServerDelegate.DELEGATE_NAME, listener, null, null); @@ -152,7 +139,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { return listener; } - private static MBeanInfo generateMBeanInfo(final String className, final Module module, + private static MBeanInfo generateMBeanInfo(final Module module, final Map attributeHolderMap, final MBeanOperationInfo[] dOperations, final Set> jmxInterfaces) { @@ -163,7 +150,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { for (AttributeHolder attributeHolder : attributeHolderMap.values()) { attributes.add(attributeHolder.toMBeanAttributeInfo()); } - return new MBeanInfo(className, dDescription, + return new MBeanInfo(module.getClass().getName(), dDescription, attributes.toArray(new MBeanAttributeInfo[0]), dConstructors, dOperations, new MBeanNotificationInfo[0]); } @@ -180,9 +167,8 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { // inspect all exported interfaces ending with MXBean, extract getters & // setters into attribute holder - private static Map buildMBeanInfo(final Module module, - final boolean writable, final ModuleIdentifier moduleIdentifier, - final Set> jmxInterfaces, final MBeanServer internalServer, + private Map buildMBeanInfo(final boolean writable, final ModuleIdentifier moduleIdentifier, + final Set> jmxInterfaces, final ObjectName internalObjectName) { // internal variables for describing MBean elements @@ -205,7 +191,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { for (MBeanAttributeInfo a : internalInfo.getAttributes()) { attributeMap.put(a.getName(), a); } - Map attributeHolderMap = new HashMap<>(); + Map attributeHolderMapLocal = new HashMap<>(); for (Method method : methods) { if (method.getParameterTypes().length == 1 @@ -229,10 +215,10 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { AttributeHolder attributeHolder = new AttributeHolder( attribName, module, attributeMap.get(attribName) .getType(), writable, ifc, description); - attributeHolderMap.put(attribName, attributeHolder); + attributeHolderMapLocal.put(attribName, attributeHolder); } } - return attributeHolderMap; + return attributeHolderMapLocal; } // DynamicMBean methods @@ -276,14 +262,14 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } private Object fixDependencyListAttribute(final Object attribute) { - if (attribute.getClass().isArray() == false) { + if (!attribute.getClass().isArray()) { throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass()); } for (int i = 0; i < Array.getLength(attribute); i++) { Object on = Array.get(attribute, i); - if (on instanceof ObjectName == false) { + if (!(on instanceof ObjectName)) { throw new IllegalArgumentException("Unexpected attribute type, should be an ObjectName, but was " + on.getClass()); } on = fixObjectName((ObjectName) on); @@ -295,7 +281,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } private boolean isDependencyListAttr(final String attributeName, final Object attribute) { - if (attributeHolderMap.containsKey(attributeName) == false) { + if (!attributeHolderMap.containsKey(attributeName)) { return false; } @@ -356,7 +342,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper { } else { LOG.debug("Operation not found {} ", actionName); throw new UnsupportedOperationException( - format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) " + String.format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) " + "method, got actionName %s, params %s, signature %s ", moduleIdentifier, actionName, params, signature)); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java index 7fa70ca10a..6859e4caf3 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AnnotationsHelper.java @@ -45,14 +45,15 @@ public class AnnotationsHelper { } // we need to go deeper inspectedClass = inspectedClass.getSuperclass(); + // no need to go further } catch (NoSuchMethodException e) { - inspectedClass = Object.class; // no need to go further + inspectedClass = Object.class; } } while (!inspectedClass.equals(Object.class)); // inspect interfaces for (Class ifc : inspectedInterfaces) { - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " is not an interface"); } try { @@ -86,10 +87,10 @@ public class AnnotationsHelper { result.add(annotation); } declaringClass = declaringClass.getSuperclass(); - } while (declaringClass.equals(Object.class) == false); + } while (!declaringClass.equals(Object.class)); // inspect interfaces for (Class ifc : interfaces) { - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " is not an interface"); } T annotation = ifc.getAnnotation(annotationType); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java index 8618456cf8..1a61922907 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AttributeHolder.java @@ -30,7 +30,7 @@ class AttributeHolder { private final RequireInterface requireInterfaceAnnotation; private final String attributeType; - public static final Set> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>(); + protected static final Set> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>(); static { PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName.class); @@ -57,9 +57,8 @@ class AttributeHolder { } public MBeanAttributeInfo toMBeanAttributeInfo() { - MBeanAttributeInfo info = new MBeanAttributeInfo(name, attributeType, + return new MBeanAttributeInfo(name, attributeType, description, true, true, false); - return info; } /** @@ -120,10 +119,8 @@ class AttributeHolder { // only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List y) to continue - if (setter.getParameterTypes().length > 1) { - return null; - } - if (PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false) { + if (setter.getParameterTypes().length > 1 || + !PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0])) { return null; } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java index 01ebdbdf94..894858d9d0 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapper.java @@ -12,6 +12,7 @@ import javax.annotation.concurrent.ThreadSafe; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; import javax.management.InstanceNotFoundException; import javax.management.InvalidAttributeValueException; import javax.management.MBeanException; @@ -21,8 +22,8 @@ import javax.management.ObjectName; import javax.management.ReflectionException; import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.annotations.RequireInterface; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.manager.impl.TransactionIdentifier; import org.opendaylight.controller.config.spi.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,11 +54,11 @@ public class DynamicWritableWrapper extends AbstractDynamicWrapper { public DynamicWritableWrapper(Module module, ModuleIdentifier moduleIdentifier, - TransactionIdentifier transactionIdentifier, + String transactionIdentifier, ReadOnlyAtomicBoolean configBeanModificationDisabled, MBeanServer internalServer, MBeanServer configMBeanServer) { super(module, true, moduleIdentifier, ObjectNameUtil - .createTransactionModuleON(transactionIdentifier.getName(), moduleIdentifier), getOperations(moduleIdentifier), + .createTransactionModuleON(transactionIdentifier, moduleIdentifier), getOperations(moduleIdentifier), internalServer, configMBeanServer); this.configBeanModificationDisabled = configBeanModificationDisabled; } @@ -77,7 +78,7 @@ public class DynamicWritableWrapper extends AbstractDynamicWrapper { public synchronized void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Attribute newAttribute = attribute; - if (configBeanModificationDisabled.get() == true) { + if (configBeanModificationDisabled.get()) { throw new IllegalStateException("Operation is not allowed now"); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java index 65e185e616..02d1d97677 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.factoriesresolver; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -55,7 +54,7 @@ public class HierarchicalConfigMBeanFactoriesHolder { * @throws IllegalArgumentException * if factory is not found */ - public ModuleFactory findByModuleName(String moduleName) throws ModuleFactoryNotFoundException { + public ModuleFactory findByModuleName(String moduleName) { Map.Entry result = moduleNamesToConfigBeanFactories.get(moduleName); if (result == null) { throw new ModuleFactoryNotFoundException(moduleName); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReference.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReference.java index 3ad35ac5b5..3455569ee8 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReference.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReference.java @@ -8,7 +8,8 @@ package org.opendaylight.controller.config.manager.impl.jmx; public class ServiceReference { - private final String serviceInterfaceName, refName; + private final String serviceInterfaceName; + private final String refName; public ServiceReference(String serviceInterfaceName, String refName) { this.serviceInterfaceName = serviceInterfaceName; diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReferenceRegistrator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReferenceRegistrator.java index eafe760ddc..fa0c52699a 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReferenceRegistrator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/ServiceReferenceRegistrator.java @@ -47,22 +47,24 @@ public interface ServiceReferenceRegistrator extends AutoCloseable { this.nullableTransactionName = nullableTransactionName; } + @Override public String getNullableTransactionName() { return nullableTransactionName; } + @Override public ServiceReferenceJMXRegistration registerMBean(ServiceReferenceMXBeanImpl object, ObjectName on) throws InstanceAlreadyExistsException { String actualTransactionName = ObjectNameUtil.getTransactionName(on); boolean broken = false; broken |= (nullableTransactionName == null) != (actualTransactionName == null); - broken |= (nullableTransactionName != null) && nullableTransactionName.equals(actualTransactionName) == false; + broken |= (nullableTransactionName != null) && !nullableTransactionName.equals(actualTransactionName); if (broken) { throw new IllegalArgumentException("Transaction name mismatch between expected " + nullableTransactionName + ", got " + actualTransactionName + " in " + on); } - if (ObjectNameUtil.isServiceReference(on) == false) { + if (!ObjectNameUtil.isServiceReference(on)) { throw new IllegalArgumentException("Invalid type of " + on); } return new ServiceReferenceJMXRegistration(currentJMXRegistrator.registerMBean(object, on)); @@ -94,6 +96,7 @@ public interface ServiceReferenceRegistrator extends AutoCloseable { this.nullableTransactionName = null; } + @Override public ServiceReferenceRegistrator create() { return new ServiceReferenceRegistratorImpl(parentRegistrator, nullableTransactionName); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionJMXRegistrator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionJMXRegistrator.java index cf2c553f6b..ceba1c8905 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionJMXRegistrator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionJMXRegistrator.java @@ -64,7 +64,8 @@ public class TransactionJMXRegistrator implements Closeable { } @Override - public void close() { // closes also all child TransactionModuleJMXRegistrator instances + public void close() { + // closes also all child TransactionModuleJMXRegistrator instances childJMXRegistrator.close(); } } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionModuleJMXRegistrator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionModuleJMXRegistrator.java index b5c59918f6..81e5ae6e22 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionModuleJMXRegistrator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/jmx/TransactionModuleJMXRegistrator.java @@ -41,7 +41,7 @@ public class TransactionModuleJMXRegistrator implements Closeable, NestableJMXRe public TransactionModuleJMXRegistration registerMBean(Object object, ObjectName on) throws InstanceAlreadyExistsException { - if (transactionName.equals(ObjectNameUtil.getTransactionName(on)) == false) { + if (!transactionName.equals(ObjectNameUtil.getTransactionName(on))) { throw new IllegalArgumentException("Transaction name mismatch between expected " + transactionName + " " + "and " + on); } @@ -63,6 +63,7 @@ public class TransactionModuleJMXRegistrator implements Closeable, NestableJMXRe return transactionName; } + @Override public InternalJMXRegistrator createChild() { return currentJMXRegistrator.createChild(); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java index 3d93a9df7d..51f9940314 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BeanToOsgiServiceManager.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; -import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Preconditions; import java.util.Dictionary; import java.util.HashSet; import java.util.Hashtable; @@ -40,13 +40,6 @@ public class BeanToOsgiServiceManager { return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations); } - private static Dictionary createProps(String serviceName) { - Hashtable result = new Hashtable<>(); - result.put(SERVICE_NAME_OSGI_PROP, serviceName); - return result; - } - - public static class OsgiRegistration implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(OsgiRegistration.class); @@ -79,7 +72,7 @@ public class BeanToOsgiServiceManager { continue; } - checkState(requiredInterface.isInstance(instance), instance.getClass().getName() + + Preconditions.checkState(requiredInterface.isInstance(instance), instance.getClass().getName() + " instance should implement " + requiredInterface.getName()); Dictionary propertiesForOsgi = createProps(entry.getValue()); ServiceRegistration serviceRegistration = bundleContext @@ -103,8 +96,8 @@ public class BeanToOsgiServiceManager { public synchronized void updateRegistrations(Map newAnnotationMapping, BundleContext bundleContext, AutoCloseable newInstance) { - boolean notEquals = this.instance != newInstance; - notEquals |= newAnnotationMapping.equals(serviceNamesToAnnotations) == false; + boolean notEquals = !this.instance.equals(newInstance); + notEquals |= !newAnnotationMapping.equals(serviceNamesToAnnotations); if (notEquals) { // FIXME: changing from old state to new state can be improved by computing the diff LOG.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier, @@ -116,5 +109,11 @@ public class BeanToOsgiServiceManager { serviceRegistrations.addAll(newRegs); } } + + private static Dictionary createProps(String serviceName) { + Hashtable result = new Hashtable<>(); + result.put(SERVICE_NAME_OSGI_PROP, serviceName); + return result; + } } } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java index 6c7f38b87d..a15820556c 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/BlankTransactionServiceTracker.java @@ -37,14 +37,10 @@ public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer< private final int maxAttempts; public BlankTransactionServiceTracker(final ConfigRegistryImpl configRegistry) { - this(new BlankTransaction() { - @Override - public CommitStatus hit() - throws ValidationException, ConflictingVersionException { - ObjectName tx = configRegistry.beginConfig(true); - return configRegistry.commitConfig(tx); - } - }); + this(() -> { + ObjectName tx = configRegistry.beginConfig(true); + return configRegistry.commitConfig(tx); + }); } public BlankTransactionServiceTracker(final BlankTransaction blankTransaction) { @@ -67,7 +63,7 @@ public class BlankTransactionServiceTracker implements ServiceTrackerCustomizer< } private void blankTransactionAsync() { - txExecutor.execute(() -> { blankTransactionSync(); }); + txExecutor.execute(this::blankTransactionSync); } void blankTransactionSync() { diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java index 781debb256..b2f7a6dd20 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java @@ -7,16 +7,14 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; -import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.registerService; -import static org.opendaylight.controller.config.manager.impl.util.OsgiRegistrationUtil.wrap; import java.lang.management.ManagementFactory; import java.util.Arrays; import java.util.Collection; import java.util.List; import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanServer; -import org.opendaylight.controller.config.api.ConfigSystemService; import org.opendaylight.controller.config.api.ConfigRegistry; +import org.opendaylight.controller.config.api.ConfigSystemService; import org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl; import org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator; import org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry; @@ -54,7 +52,8 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl @Override public void start(final BundleContext context) { try { - ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();// the inner strategy is backed by thread context cl? + // the inner strategy is backed by thread context cl? + ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); BindingContextProvider bindingContextProvider = new BindingContextProvider(); @@ -97,8 +96,8 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl new JMXNotifierConfigRegistry(configRegistry, configMBeanServer); // register config registry to OSGi - AutoCloseable clsReg = registerService(context, moduleInfoBackedContext, ClassLoadingStrategy.class); - AutoCloseable configRegReg = registerService(context, notifyingConfigRegistry, ConfigRegistry.class); + AutoCloseable clsReg = OsgiRegistrationUtil.registerService(context, moduleInfoBackedContext, ClassLoadingStrategy.class); + AutoCloseable configRegReg = OsgiRegistrationUtil.registerService(context, notifyingConfigRegistry, ConfigRegistry.class); // register config registry to jmx ConfigRegistryJMXRegistrator configRegistryJMXRegistrator = new ConfigRegistryJMXRegistrator(configMBeanServer); @@ -124,12 +123,12 @@ public class ConfigManagerActivator implements BundleActivator, SynchronousBundl blankTransactionServiceTracker); serviceTracker.open(); - AutoCloseable configMgrReg = registerService(context, this, ConfigSystemService.class); + AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, ConfigSystemService.class); List list = Arrays.asList(bindingContextProvider, clsReg, - wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker, + OsgiRegistrationUtil.wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker, configRegReg, configRegistryJMXRegistrator, configRegistryJMXRegistratorWithNotifications, - wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, configMgrReg); + OsgiRegistrationUtil.wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry, configMgrReg); autoCloseable = OsgiRegistrationUtil.aggregate(list); context.addBundleListener(this); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ExtensibleBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ExtensibleBundleTracker.java index a0d9122ac6..62215d6626 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ExtensibleBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ExtensibleBundleTracker.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.config.manager.impl.osgi; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -74,27 +73,18 @@ public final class ExtensibleBundleTracker extends BundleTracker> { @Override public Future addingBundle(final Bundle bundle, final BundleEvent event) { LOG.trace("Submiting AddingBundle for bundle {} and event {} to be processed asynchronously",bundle,event); - Future future = eventExecutor.submit(new Callable() { - @Override - public T call() throws Exception { - try { - T primaryTrackerRetVal = primaryTracker.addingBundle(bundle, event); + return eventExecutor.submit(() -> { + try { + T primaryTrackerRetVal = primaryTracker.addingBundle(bundle, event); - forEachAdditionalBundle(new BundleStrategy() { - @Override - public void execute(final BundleTrackerCustomizer tracker) { - tracker.addingBundle(bundle, event); - } - }); - LOG.trace("AddingBundle for {} and event {} finished successfully",bundle,event); - return primaryTrackerRetVal; - } catch (Exception e) { - LOG.error("Failed to add bundle {}", bundle, e); - throw e; - } + forEachAdditionalBundle(tracker -> tracker.addingBundle(bundle, event)); + LOG.trace("AddingBundle for {} and event {} finished successfully",bundle,event); + return primaryTrackerRetVal; + } catch (Exception e) { + LOG.error("Failed to add bundle {}", bundle, e); + throw e; } }); - return future; } @Override @@ -114,12 +104,7 @@ public final class ExtensibleBundleTracker extends BundleTracker> { try { LOG.trace("Invoking removedBundle event for {}",bundle); primaryTracker.removedBundle(bundle, event, object.get()); - forEachAdditionalBundle(new BundleStrategy() { - @Override - public void execute(final BundleTrackerCustomizer tracker) { - tracker.removedBundle(bundle, event, null); - } - }); + forEachAdditionalBundle(tracker -> tracker.removedBundle(bundle, event, null)); LOG.trace("Removed bundle event for {} finished successfully.",bundle); } catch (Exception e) { LOG.error("Failed to remove bundle {}", bundle, e); diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java index 83d144d4ae..8ca5da2825 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTracker.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.config.manager.impl.osgi; -import static java.lang.String.format; import com.google.common.annotations.VisibleForTesting; import com.google.common.io.Resources; import java.io.IOException; @@ -114,6 +113,6 @@ public class ModuleFactoryBundleTracker implements BundleTrackerCustomizer> addingBundle(Bundle bundle, BundleEvent event) { URL resource = bundle.getEntry(MODULE_INFO_PROVIDER_PATH_PREFIX + YangModelBindingProvider.class.getName()); LOG.debug("Got addingBundle({}) with YangModelBindingProvider resource {}", bundle, resource); - if(resource==null) { - return null; + if(resource == null) { + return Collections.emptyList(); } List> registrations = new LinkedList<>(); @@ -121,7 +121,7 @@ public final class ModuleInfoBundleTracker implements AutoCloseable, String errorMessage; Class clazz = loadClass(moduleInfoClass, bundle); - if (YangModelBindingProvider.class.isAssignableFrom(clazz) == false) { + if (!YangModelBindingProvider.class.isAssignableFrom(clazz)) { errorMessage = logMessage("Class {} does not implement {} in bundle {}", clazz, YangModelBindingProvider.class, bundle); throw new IllegalStateException(errorMessage); } @@ -157,6 +157,6 @@ public final class ModuleInfoBundleTracker implements AutoCloseable, public static String logMessage(String slfMessage, Object... params) { LOG.info(slfMessage, params); String formatMessage = slfMessage.replaceAll("\\{\\}", "%s"); - return format(formatMessage, params); + return String.format(formatMessage, params); } } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java index 8001169771..59c4d9fa3d 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/mapping/RefreshingSCPModuleInfoRegistry.java @@ -59,7 +59,8 @@ public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, Auto final Dictionary props = new Hashtable<>(); props.put(BindingRuntimeContext.class.getName(), bindingContextProvider.getBindingContext()); props.put(SchemaSourceProvider.class.getName(), sourceProvider); - osgiReg.setProperties(props); // send modifiedService event + // send modifiedService event + osgiReg.setProperties(props); } catch (RuntimeException e) { // The ModuleInfoBackedContext throws a RuntimeException if it can't create the schema context. LOG.warn("Error updating the BindingContextProvider", e); @@ -70,8 +71,7 @@ public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, Auto @Override public ObjectRegistration registerModuleInfo(final YangModuleInfo yangModuleInfo) { ObjectRegistration yangModuleInfoObjectRegistration = moduleInfoRegistry.registerModuleInfo(yangModuleInfo); - ObjectRegistrationWrapper wrapper = new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration); - return wrapper; + return new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration); } @Override @@ -98,7 +98,8 @@ public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, Auto @Override public void close() throws Exception { inner.close(); - updateService();// send modify event when a bundle disappears + // send modify event when a bundle disappears + updateService(); } @Override diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java index f4d732c65c..8538e3f84d 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java @@ -31,7 +31,7 @@ public final class InterfacesHelper { } // getInterfaces gets interfaces implemented directly by this class Set> toBeInspected = new HashSet<>(); - while (clazz.equals(Object.class) == false) { + while (!clazz.equals(Object.class)) { toBeInspected.addAll(Arrays.asList(clazz.getInterfaces())); // get parent class clazz = clazz.getSuperclass(); @@ -48,7 +48,7 @@ public final class InterfacesHelper { Iterator> iterator = interfaces.iterator(); Class ifc = iterator.next(); iterator.remove(); - if (ifc.isInterface() == false) { + if (!ifc.isInterface()) { throw new IllegalArgumentException(ifc + " should be an interface"); } interfaces.addAll(Arrays.asList(ifc.getInterfaces())); @@ -97,7 +97,7 @@ public final class InterfacesHelper { Set> foundGeneratedSIClasses = new HashSet<>(); for (Class clazz : getAllInterfaces(configBeanClass)) { - if (AbstractServiceInterface.class.isAssignableFrom(clazz) && AbstractServiceInterface.class.equals(clazz) == false) { + if (AbstractServiceInterface.class.isAssignableFrom(clazz) && !AbstractServiceInterface.class.equals(clazz)) { foundGeneratedSIClasses.add((Class) clazz); } } @@ -155,7 +155,7 @@ public final class InterfacesHelper { Set> result = new HashSet<>(); for(Class ifc: allInterfaces){ if (AbstractServiceInterface.class.isAssignableFrom(ifc) && - ifc.equals(AbstractServiceInterface.class) == false) { + !ifc.equals(AbstractServiceInterface.class)) { result.add((Class) ifc); } diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java index fe8e30ee9a..7c02019544 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/OsgiRegistrationUtil.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.config.manager.impl.util; import static com.google.common.base.Preconditions.checkNotNull; - import java.util.ArrayList; import java.util.List; import java.util.ListIterator; @@ -40,32 +39,17 @@ public class OsgiRegistrationUtil { public static AutoCloseable wrap(final ServiceRegistration reg) { checkNotNull(reg); - return new AutoCloseable() { - @Override - public void close() throws Exception { - reg.unregister(); - } - }; + return reg::unregister; } public static AutoCloseable wrap(final BundleTracker bundleTracker) { checkNotNull(bundleTracker); - return new AutoCloseable() { - @Override - public void close() throws Exception { - bundleTracker.close(); - } - }; + return bundleTracker::close; } public static AutoCloseable wrap(final ServiceTracker serviceTracker) { checkNotNull(serviceTracker); - return new AutoCloseable() { - @Override - public void close() throws Exception { - serviceTracker.close(); - } - }; + return serviceTracker::close; } /** @@ -74,26 +58,23 @@ public class OsgiRegistrationUtil { public static AutoCloseable aggregate(final List list) { checkNotNull(list); - return new AutoCloseable() { - @Override - public void close() throws Exception { - Exception firstException = null; - for (ListIterator it = list.listIterator(list.size()); it.hasPrevious();) { - AutoCloseable ac = it.previous(); - try { - ac.close(); - } catch (Exception e) { - LOG.warn("Exception while closing {}", ac, e); - if (firstException == null) { - firstException = e; - } else { - firstException.addSuppressed(e); - } + return () -> { + Exception firstException = null; + for (ListIterator it = list.listIterator(list.size()); it.hasPrevious();) { + AutoCloseable ac = it.previous(); + try { + ac.close(); + } catch (Exception e) { + LOG.warn("Exception while closing {}", ac, e); + if (firstException == null) { + firstException = e; + } else { + firstException.addSuppressed(e); } } - if (firstException != null) { - throw firstException; - } + } + if (firstException != null) { + throw firstException; } }; } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapperTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapperTest.java index d453f1e779..bd8211377f 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapperTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/DynamicWritableWrapperTest.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.config.manager.impl.dynamicmbean; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - import java.util.concurrent.atomic.AtomicBoolean; import javax.management.Attribute; import javax.management.AttributeList; @@ -20,7 +19,6 @@ import javax.management.ObjectName; import org.junit.Test; import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.manager.impl.TransactionIdentifier; import org.opendaylight.controller.config.manager.impl.dynamicmbean.ReadOnlyAtomicBoolean.ReadOnlyAtomicBooleanImpl; import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean; import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModule; @@ -38,7 +36,7 @@ public class DynamicWritableWrapperTest extends AbstractDynamicWrapperTest { protected AbstractDynamicWrapper getDynamicWrapper(Module module, ModuleIdentifier moduleIdentifier) { return new DynamicWritableWrapper(module, moduleIdentifier, - new TransactionIdentifier("transaction-1"), + "transaction-1", readOnlyAtomicBoolean, MBeanServerFactory.createMBeanServer(), platformMBeanServer); } diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java index fd8c8d1df0..7b4a9f335a 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/parallelapsp/test/DependentWiringTest.java @@ -12,7 +12,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - import java.util.Map; import javax.management.ObjectName; import org.junit.After; @@ -33,7 +32,6 @@ import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; public class DependentWiringTest extends AbstractParallelAPSPTest { private final String fixed1 = "fixed1"; - private final String apsp1 = "apsp-parallel"; @Before public void setUp() { -- 2.36.6