Removed static imports.
Change-Id: Ife05c6c4fc288c70624880eefbe9c5be8b47b974
Signed-off-by: Dana Kutenicsova <dana.kutenics@gmail.com>
*/
public interface CloseableServiceReferenceReadableRegistry extends AutoCloseable, ServiceReferenceReadableRegistry {
+ @Override
void close();
-
}
*/
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;
@GuardedBy("configTransactionLock")
private List<ModuleFactory> lastListOfFactories = Collections.emptyList();
- @GuardedBy("readableSRRegistryLock") // switched in every 2ndPC
+ // switched in every 2ndPC
+ @GuardedBy("readableSRRegistryLock")
private CloseableServiceReferenceReadableRegistry readableSRRegistry =
ServiceReferenceRegistryImpl.createInitialSRLookupRegistry();
// 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()));
/**
* {@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());
}
// 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);
}
}
// (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());
}
*/
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;
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
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;
List<ModuleFactory> toBeAdded = new ArrayList<>();
List<ModuleFactory> 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);
}
}
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);
}
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);
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);
}
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");
}
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
public synchronized List<ModuleIdentifier> 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");
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);
}
}
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);
}
return txModuleJMXRegistrator;
}
+ @Override
public void close() {
transactionJMXRegistrator.close();
}
@GuardedBy("this")
private final Deque<ModuleIdentifierWithNanos> moduleIdentifierWithNanosStack = new LinkedList<>();
@GuardedBy("this")
- private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.EMPTY;
+ private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.empty;
public DeadlockMonitor(TransactionIdentifier transactionIdentifier) {
this.transactionIdentifier = transactionIdentifier;
if (popping) {
moduleIdentifierWithNanosStack.pop();
if (moduleIdentifierWithNanosStack.isEmpty()) {
- top = ModuleIdentifierWithNanos.EMPTY;
+ top = ModuleIdentifierWithNanos.empty;
} else {
top = moduleIdentifierWithNanosStack.peekLast();
}
@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 {
}
}
-
-
-
private static class ModuleIdentifierWithNanos {
- private static ModuleIdentifierWithNanos EMPTY = new ModuleIdentifierWithNanos();
+ private static ModuleIdentifierWithNanos empty = new ModuleIdentifierWithNanos();
@Nullable
private final ModuleIdentifier moduleIdentifier;
*/
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;
private final boolean writable;
private final Map<ServiceReference, Entry<ServiceReferenceMXBeanImpl, ServiceReferenceJMXRegistration>> mBeans = new HashMap<>();
+ private ServiceReferenceRegistryImpl(final Map<String, ModuleFactory> factories, final LookupRegistry lookupRegistry,
+ final ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory, final boolean writable) {
+ this.factories = factories;
+ this.writable = writable;
+ this.lookupRegistry = lookupRegistry;
+
+ this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create();
+
+ Map<String, Set<String /* QName */>> modifiableFactoryNamesToQNames = new HashMap<>();
+ Set<ServiceInterfaceAnnotation> allAnnotations = new HashSet<>();
+ Set<String /* qName */> allQNameSet = new HashSet<>();
+
+ for (Entry<String, ModuleFactory> 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<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue());
+ Set<String> 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<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations = new HashMap<>();
+ Map<String /* service qName*/, ServiceInterfaceAnnotation> modifiableServiceQNamesToAnnotations = new HashMap<>();
+ for (ServiceInterfaceAnnotation sia : allAnnotations) {
+ Map<String, ServiceInterfaceAnnotation> 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.
return result;
}
- private ServiceReferenceRegistryImpl(final Map<String, ModuleFactory> factories, final LookupRegistry lookupRegistry,
- final ServiceReferenceTransactionRegistratorFactory serviceReferenceRegistratorFactory,
- final boolean writable) {
- this.factories = factories;
- this.writable = writable;
- this.lookupRegistry = lookupRegistry;
-
- this.serviceReferenceRegistrator = serviceReferenceRegistratorFactory.create();
-
- Map<String, Set<String /* QName */>> modifiableFactoryNamesToQNames = new HashMap<>();
- Set<ServiceInterfaceAnnotation> allAnnotations = new HashSet<>();
- Set<String /* qName */> allQNameSet = new HashSet<>();
-
-
- for (Entry<String, ModuleFactory> 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<ServiceInterfaceAnnotation> siAnnotations = InterfacesHelper.getServiceInterfaceAnnotations(entry.getValue());
- Set<String> 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<String /* namespace */, Map<String /* localName */, ServiceInterfaceAnnotation>> modifiableNamespacesToAnnotations =
- new HashMap<>();
- Map<String /* service qName*/, ServiceInterfaceAnnotation> modifiableServiceQNamesToAnnotations = new HashMap<>();
- for (ServiceInterfaceAnnotation sia : allAnnotations) {
- Map<String, ServiceInterfaceAnnotation> 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<ServiceInterfaceAnnotation, String /* service ref name */> findServiceInterfaces(final ModuleIdentifier moduleIdentifier) {
Map<ServiceInterfaceAnnotation, String /* service ref name */> result = modulesToServiceRef.get(moduleIdentifier);
@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);
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");
}
}
final boolean skipChecks) throws InstanceNotFoundException {
// make sure it is found
- if (skipChecks == false) {
+ if (!skipChecks) {
lookupRegistry.checkConfigBeanExists(moduleON);
}
String factoryName = ObjectNameUtil.getFactoryName(moduleON);
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());
}
}
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;
}
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());
}
for (ServiceReference sr : serviceReferencesLinkingTo) {
removeServiceReference(sr);
}
- return serviceReferencesLinkingTo.isEmpty() == false;
+ return !serviceReferencesLinkingTo.isEmpty();
}
private Set<ServiceReference> findServiceReferencesLinkingTo(final ObjectName moduleObjectName, final Set<String> serviceInterfaceQNames) {
}
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");
}
*/
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;
private final BindingContextProvider bindingContextProvider;
private final String transactionName;
private final MBeanServer mBeanServer;
+ private Integer maxDependencyDepth;
DependencyResolverImpl(ModuleIdentifier currentModule,
TransactionStatus transactionStatus, ModulesHolder modulesHolder,
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
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",
}
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
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
o.getMaxDependencyDepth());
}
- private Integer maxDependencyDepth;
-
int getMaxDependencyDepth() {
if (maxDependencyDepth == null) {
throw new IllegalStateException("Dependency depth was not computed");
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));
}
*/
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;
return cachedInstance;
}
- checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
+ Preconditions.checkState(deadlockMonitor.isAlive(), "Deadlock monitor is not alive");
deadlockMonitor.setCurrentlyInstantiatedModule(moduleIdentifier);
}
try {
public class ModuleInternalTransactionalInfo implements Identifiable<ModuleIdentifier> {
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;
*/
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;
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;
}
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;
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<Class<?>> 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);
}
* 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
"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);
return listener;
}
- private static MBeanInfo generateMBeanInfo(final String className, final Module module,
+ private static MBeanInfo generateMBeanInfo(final Module module,
final Map<String, AttributeHolder> attributeHolderMap,
final MBeanOperationInfo[] dOperations, final Set<Class<?>> jmxInterfaces) {
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]);
}
// inspect all exported interfaces ending with MXBean, extract getters &
// setters into attribute holder
- private static Map<String, AttributeHolder> buildMBeanInfo(final Module module,
- final boolean writable, final ModuleIdentifier moduleIdentifier,
- final Set<Class<?>> jmxInterfaces, final MBeanServer internalServer,
+ private Map<String, AttributeHolder> buildMBeanInfo(final boolean writable, final ModuleIdentifier moduleIdentifier,
+ final Set<Class<?>> jmxInterfaces,
final ObjectName internalObjectName) {
// internal variables for describing MBean elements
for (MBeanAttributeInfo a : internalInfo.getAttributes()) {
attributeMap.put(a.getName(), a);
}
- Map<String, AttributeHolder> attributeHolderMap = new HashMap<>();
+ Map<String, AttributeHolder> attributeHolderMapLocal = new HashMap<>();
for (Method method : methods) {
if (method.getParameterTypes().length == 1
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
}
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);
}
private boolean isDependencyListAttr(final String attributeName, final Object attribute) {
- if (attributeHolderMap.containsKey(attributeName) == false) {
+ if (!attributeHolderMap.containsKey(attributeName)) {
return false;
}
} 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));
}
}
// 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 {
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);
private final RequireInterface requireInterfaceAnnotation;
private final String attributeType;
- public static final Set<Class<?>> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>();
+ protected static final Set<Class<?>> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>();
static {
PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName.class);
}
public MBeanAttributeInfo toMBeanAttributeInfo() {
- MBeanAttributeInfo info = new MBeanAttributeInfo(name, attributeType,
+ return new MBeanAttributeInfo(name, attributeType,
description, true, true, false);
- return info;
}
/**
// only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List<ObjectName> 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;
}
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;
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;
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;
}
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");
}
*/
package org.opendaylight.controller.config.manager.impl.factoriesresolver;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
* @throws IllegalArgumentException
* if factory is not found
*/
- public ModuleFactory findByModuleName(String moduleName) throws ModuleFactoryNotFoundException {
+ public ModuleFactory findByModuleName(String moduleName) {
Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
if (result == null) {
throw new ModuleFactoryNotFoundException(moduleName);
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;
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));
this.nullableTransactionName = null;
}
+ @Override
public ServiceReferenceRegistrator create() {
return new ServiceReferenceRegistratorImpl(parentRegistrator, nullableTransactionName);
}
}
@Override
- public void close() { // closes also all child TransactionModuleJMXRegistrator instances
+ public void close() {
+ // closes also all child TransactionModuleJMXRegistrator instances
childJMXRegistrator.close();
}
}
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);
}
return transactionName;
}
+ @Override
public InternalJMXRegistrator createChild() {
return currentJMXRegistrator.createChild();
}
*/
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;
return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations);
}
- private static Dictionary<String, String> createProps(String serviceName) {
- Hashtable<String, String> 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);
continue;
}
- checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
+ Preconditions.checkState(requiredInterface.isInstance(instance), instance.getClass().getName() +
" instance should implement " + requiredInterface.getName());
Dictionary<String, String> propertiesForOsgi = createProps(entry.getValue());
ServiceRegistration<?> serviceRegistration = bundleContext
public synchronized void updateRegistrations(Map<ServiceInterfaceAnnotation, String /* service ref name */> 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,
serviceRegistrations.addAll(newRegs);
}
}
+
+ private static Dictionary<String, String> createProps(String serviceName) {
+ Hashtable<String, String> result = new Hashtable<>();
+ result.put(SERVICE_NAME_OSGI_PROP, serviceName);
+ return result;
+ }
}
}
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) {
}
private void blankTransactionAsync() {
- txExecutor.execute(() -> { blankTransactionSync(); });
+ txExecutor.execute(this::blankTransactionSync);
}
void blankTransactionSync() {
*/
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;
@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();
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);
blankTransactionServiceTracker);
serviceTracker.open();
- AutoCloseable configMgrReg = registerService(context, this, ConfigSystemService.class);
+ AutoCloseable configMgrReg = OsgiRegistrationUtil.registerService(context, this, ConfigSystemService.class);
List<AutoCloseable> 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);
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;
@Override
public Future<T> addingBundle(final Bundle bundle, final BundleEvent event) {
LOG.trace("Submiting AddingBundle for bundle {} and event {} to be processed asynchronously",bundle,event);
- Future<T> future = eventExecutor.submit(new Callable<T>() {
- @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
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);
*/
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;
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);
}
}
*/
package org.opendaylight.controller.config.manager.impl.osgi.mapping;
-import static java.lang.String.format;
import com.google.common.io.Resources;
import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.nio.charset.StandardCharsets;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
public Collection<ObjectRegistration<YangModuleInfo>> 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<ObjectRegistration<YangModuleInfo>> registrations = new LinkedList<>();
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);
}
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);
}
}
final Dictionary<String, Object> 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);
@Override
public ObjectRegistration<YangModuleInfo> registerModuleInfo(final YangModuleInfo yangModuleInfo) {
ObjectRegistration<YangModuleInfo> yangModuleInfoObjectRegistration = moduleInfoRegistry.registerModuleInfo(yangModuleInfo);
- ObjectRegistrationWrapper wrapper = new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration);
- return wrapper;
+ return new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration);
}
@Override
@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
}
// getInterfaces gets interfaces implemented directly by this class
Set<Class<?>> 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();
Iterator<Class<?>> 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()));
Set<Class<? extends AbstractServiceInterface>> 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<? extends AbstractServiceInterface>) clazz);
}
}
Set<Class<? extends AbstractServiceInterface>> result = new HashSet<>();
for(Class<?> ifc: allInterfaces){
if (AbstractServiceInterface.class.isAssignableFrom(ifc) &&
- ifc.equals(AbstractServiceInterface.class) == false) {
+ !ifc.equals(AbstractServiceInterface.class)) {
result.add((Class<? extends AbstractServiceInterface>) ifc);
}
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;
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;
}
/**
public static AutoCloseable aggregate(final List<? extends AutoCloseable> list) {
checkNotNull(list);
- return new AutoCloseable() {
- @Override
- public void close() throws Exception {
- Exception firstException = null;
- for (ListIterator<? extends AutoCloseable> 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<? extends AutoCloseable> 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;
}
};
}
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;
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;
protected AbstractDynamicWrapper getDynamicWrapper(Module module,
ModuleIdentifier moduleIdentifier) {
return new DynamicWritableWrapper(module, moduleIdentifier,
- new TransactionIdentifier("transaction-1"),
+ "transaction-1",
readOnlyAtomicBoolean, MBeanServerFactory.createMBeanServer(),
platformMBeanServer);
}
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;
public class DependentWiringTest extends AbstractParallelAPSPTest {
private final String fixed1 = "fixed1";
- private final String apsp1 = "apsp-parallel";
@Before
public void setUp() {