private final List<DestroyedModule> destroyedFromPreviousTransactions;
private final Map<ModuleIdentifier, ModuleInternalTransactionalInfo> commitMap;
- public CommitInfo(List<DestroyedModule> destroyedFromPreviousTransactions,
- Map<ModuleIdentifier, ModuleInternalTransactionalInfo> commitMap) {
+ public CommitInfo(final List<DestroyedModule> destroyedFromPreviousTransactions,
+ final Map<ModuleIdentifier, ModuleInternalTransactionalInfo> commitMap) {
this.destroyedFromPreviousTransactions = Collections
.unmodifiableList(destroyedFromPreviousTransactions);
this.commitMap = Collections.unmodifiableMap(commitMap);
ServiceReferenceRegistryImpl.createInitialSRLookupRegistry();
// constructor
- public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
- MBeanServer configMBeanServer, BindingContextProvider bindingContextProvider) {
+ public ConfigRegistryImpl(final ModuleFactoriesResolver resolver,
+ final MBeanServer configMBeanServer, final BindingContextProvider bindingContextProvider) {
this(resolver, configMBeanServer,
new BaseJMXRegistrator(configMBeanServer), bindingContextProvider);
}
// constructor
- public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
- MBeanServer configMBeanServer,
- BaseJMXRegistrator baseJMXRegistrator, BindingContextProvider bindingContextProvider) {
+ public ConfigRegistryImpl(final ModuleFactoriesResolver resolver,
+ final MBeanServer configMBeanServer,
+ final BaseJMXRegistrator baseJMXRegistrator, final BindingContextProvider bindingContextProvider) {
this.resolver = resolver;
this.beanToOsgiServiceManager = new BeanToOsgiServiceManager();
this.configMBeanServer = configMBeanServer;
* @param blankTransaction true if this transaction is created automatically by
* org.opendaylight.controller.config.manager.impl.osgi.BlankTransactionServiceTracker
*/
- public ObjectName beginConfig(boolean blankTransaction) {
+ public ObjectName beginConfig(final boolean blankTransaction) {
// If we're closed or in the process of closing then all modules are destroyed or being destroyed
// so there's no point in trying to acquire the lock and beginning an actual transaction. Also we want
// to avoid trying to lock as it may block the shutdown process if there is an outstanding transaction
LOG.debug("Timed out trying to obtain configTransactionLock");
return NOOP_TX_NAME;
}
- } catch(InterruptedException e) {
+ } catch(final InterruptedException e) {
LOG.debug("Interrupted trying to obtain configTransactionLock", e);
Thread.currentThread().interrupt();
return NOOP_TX_NAME;
}
@GuardedBy("configTransactionLock")
- private ConfigTransactionControllerInternal beginConfigSafe(boolean blankTransaction) {
+ private ConfigTransactionControllerInternal beginConfigSafe(final boolean blankTransaction) {
versionCounter++;
final String transactionName = "ConfigTransaction-" + version + "-" + versionCounter;
configMBeanServer, blankTransaction, writableRegistry);
try {
txLookupRegistry.registerMBean(transactionController, transactionController.getControllerObjectName());
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException(e);
}
transactionController.copyExistingModulesAndProcessFactoryDiff(currentConfig.getEntries(), lastListOfFactories);
* @throws ConflictingVersionException
*/
@Override
- public CommitStatus commitConfig(ObjectName transactionControllerON)
+ public CommitStatus commitConfig(final ObjectName transactionControllerON)
throws ValidationException, ConflictingVersionException {
if(NOOP_TX_NAME.equals(transactionControllerON) || closed.get()) {
return new CommitStatus(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}
@GuardedBy("configTransactionLock")
- private CommitStatus commitConfigSafe(ObjectName transactionControllerON)
+ private CommitStatus commitConfigSafe(final ObjectName transactionControllerON)
throws ConflictingVersionException, ValidationException {
final String transactionName = ObjectNameUtil
.getTransactionName(transactionControllerON);
return secondPhaseCommit(configTransactionController, commitInfo, configTransactionControllerEntry.getValue());
// some libs throw Errors: e.g.
// javax.xml.ws.spi.FactoryFinder$ConfigurationError
- } catch (Throwable t) {
+ } catch (final Throwable t) {
isHealthy = false;
LOG.error("Configuration Transaction failed on 2PC, server is unhealthy", t);
throw Throwables.propagate(t);
}
@GuardedBy("configTransactionLock")
- private CommitStatus secondPhaseCommit(ConfigTransactionControllerInternal configTransactionController,
- CommitInfo commitInfo, ConfigTransactionLookupRegistry txLookupRegistry) {
+ private CommitStatus secondPhaseCommit(final ConfigTransactionControllerInternal configTransactionController,
+ final CommitInfo commitInfo, final ConfigTransactionLookupRegistry txLookupRegistry) {
// close instances which were destroyed by the user, including
// (hopefully) runtime beans
// register to JMX
try {
newModuleJMXRegistrator.registerMBean(newReadableConfigBean, primaryReadOnlyON);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException("Possible code error, already registered:" + primaryReadOnlyON,e);
}
try {
configTransactionControllerEntry.getValue().close();
configTransactionController.abortConfig();
- } catch (RuntimeException e) {
+ } catch (final RuntimeException e) {
LOG.debug("Ignoring exception while aborting {}", configTransactionController, e);
}
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName) {
return lookupConfigBeans(moduleName, "*");
}
* {@inheritDoc}
*/
@Override
- public ObjectName lookupConfigBean(String moduleName, String instanceName)
+ public ObjectName lookupConfigBean(final String moduleName, final String instanceName)
throws InstanceNotFoundException {
return LookupBeansUtil.lookupConfigBean(this, moduleName, instanceName);
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName,
- String instanceName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName,
+ final String instanceName) {
ObjectName namePattern = ObjectNameUtil.createModulePattern(moduleName,
instanceName);
return baseJMXRegistrator.queryNames(namePattern, null);
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupRuntimeBeans(String moduleName,
- String instanceName) {
+ public Set<ObjectName> lookupRuntimeBeans(final String moduleName,
+ final String instanceName) {
String finalModuleName = moduleName == null ? "*" : moduleName;
String finalInstanceName = instanceName == null ? "*" : instanceName;
ObjectName namePattern = ObjectNameUtil.createRuntimeBeanPattern(
}
@Override
- public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
+ public void checkConfigBeanExists(final ObjectName objectName) throws InstanceNotFoundException {
ObjectNameUtil.checkDomain(objectName);
ObjectNameUtil.checkType(objectName, ObjectNameUtil.TYPE_MODULE);
String transactionName = ObjectNameUtil.getTransactionName(objectName);
// service reference functionality:
@Override
- public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
+ public ObjectName lookupConfigBeanByServiceInterfaceName(final String serviceInterfaceQName, final String refName) {
synchronized(readableSRRegistryLock) {
return readableSRRegistry.lookupConfigBeanByServiceInterfaceName(serviceInterfaceQName, refName);
}
}
@Override
- public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
+ public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(final String serviceInterfaceQName) {
synchronized(readableSRRegistryLock) {
return readableSRRegistry.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceQName);
}
}
@Override
- public Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
+ public Set<String> lookupServiceInterfaceNames(final ObjectName objectName) throws InstanceNotFoundException {
synchronized(readableSRRegistryLock) {
return readableSRRegistry.lookupServiceInterfaceNames(objectName);
}
}
@Override
- public String getServiceInterfaceName(String namespace, String localName) {
+ public String getServiceInterfaceName(final String namespace, final String localName) {
synchronized(readableSRRegistryLock) {
return readableSRRegistry.getServiceInterfaceName(namespace, localName);
}
}
@Override
- public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
+ public void checkServiceReferenceExists(final ObjectName objectName) throws InstanceNotFoundException {
synchronized(readableSRRegistryLock) {
readableSRRegistry.checkServiceReferenceExists(objectName);
}
}
@Override
- public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
+ public ObjectName getServiceReference(final String serviceInterfaceQName, final String refName) throws InstanceNotFoundException {
synchronized(readableSRRegistryLock) {
return readableSRRegistry.getServiceReference(serviceInterfaceQName, refName);
}
* Add all modules to the internal map. Also add service instance to OSGi
* Service Registry.
*/
- public void addAll(Collection<ModuleInternalInfo> configInfos) {
+ public void addAll(final Collection<ModuleInternalInfo> configInfos) {
if (!currentConfig.isEmpty()) {
throw new IllegalStateException(
"Error - some config entries were not removed: "
}
}
- private void add(ModuleInternalInfo configInfo) {
+ private void add(final ModuleInternalInfo configInfo) {
ModuleInternalInfo oldValue = currentConfig.putIfAbsent(configInfo.getIdentifier(), configInfo);
if (oldValue != null) {
throw new IllegalStateException(
/**
* Remove entry from current config.
*/
- public void remove(ModuleIdentifier name) {
+ public void remove(final ModuleIdentifier name) {
ModuleInternalInfo removed = currentConfig.remove(name);
if (removed == null) {
throw new IllegalStateException(
private final ConcurrentMap<String /* transactionName */,
Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> transactions = new ConcurrentHashMap<>();
- public void add(String transactionName,
- ConfigTransactionControllerInternal transactionController, ConfigTransactionLookupRegistry txLookupRegistry) {
+ public void add(final String transactionName,
+ final ConfigTransactionControllerInternal transactionController, final ConfigTransactionLookupRegistry txLookupRegistry) {
Object oldValue = transactions.putIfAbsent(transactionName,
Maps.immutableEntry(transactionController, txLookupRegistry));
if (oldValue != null) {
@GuardedBy("this")
private final SearchableServiceReferenceWritableRegistry writableSRRegistry;
- public ConfigTransactionControllerImpl(ConfigTransactionLookupRegistry txLookupRegistry,
- long parentVersion, BindingContextProvider bindingContextProvider, long currentVersion,
- Map<String, Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories,
- MBeanServer transactionsMBeanServer, MBeanServer configMBeanServer,
- boolean blankTransaction, SearchableServiceReferenceWritableRegistry writableSRRegistry) {
+ public ConfigTransactionControllerImpl(final ConfigTransactionLookupRegistry txLookupRegistry,
+ final long parentVersion, final BindingContextProvider bindingContextProvider, final long currentVersion,
+ final Map<String, Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories,
+ final MBeanServer transactionsMBeanServer, final MBeanServer configMBeanServer,
+ final boolean blankTransaction, final SearchableServiceReferenceWritableRegistry writableSRRegistry) {
this.txLookupRegistry = txLookupRegistry;
String transactionName = txLookupRegistry.getTransactionIdentifier().getName();
this.controllerON = ObjectNameUtil.createTransactionControllerON(transactionName);
}
@Override
- public void copyExistingModulesAndProcessFactoryDiff(Collection<ModuleInternalInfo> existingModules, List<ModuleFactory> lastListOfFactories) {
+ public void copyExistingModulesAndProcessFactoryDiff(final Collection<ModuleInternalInfo> existingModules, final List<ModuleFactory> lastListOfFactories) {
// copy old configuration to this server
for (ModuleInternalInfo oldConfigInfo : existingModules) {
try {
copyExistingModule(oldConfigInfo);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException("Error while copying " + oldConfigInfo, e);
}
}
processDefaultBeans(lastListOfFactories);
}
- private synchronized void processDefaultBeans(List<ModuleFactory> lastListOfFactories) {
+ private synchronized void processDefaultBeans(final List<ModuleFactory> lastListOfFactories) {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
boolean defaultBean = true;
objectName = putConfigBeanToJMXAndInternalMaps(module.getIdentifier(), module, moduleFactory, null,
dependencyResolver, defaultBean, bundleContext);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException(e);
}
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
saveServiceReference(qname, module.getIdentifier().getInstanceName(), objectName);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to register default module instance " + module + " as a service of " + qname, e);
}
}
for (String qname : InterfacesHelper.getQNames(serviceInterfaceAnnotations)) {
try {
removeServiceReference(qname, name.getInstanceName());
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Unable to UNregister default module instance " + name + " as a service of " + qname, e);
}
}
}
- private synchronized void copyExistingModule(ModuleInternalInfo oldConfigBeanInfo)
+ private synchronized void copyExistingModule(final ModuleInternalInfo oldConfigBeanInfo)
throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
try {
moduleFactory = factoriesHolder.findByModuleName(moduleIdentifier.getFactoryName());
bc = getModuleFactoryBundleContext(moduleFactory.getImplementationName());
- } catch (ModuleFactoryNotFoundException e) {
+ } catch (final ModuleFactoryNotFoundException e) {
throw new IllegalStateException(e);
}
module = moduleFactory.createModule(
moduleIdentifier.getInstanceName(), dependencyResolver,
oldConfigBeanInfo.getReadableModule(), bc);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException(String.format(
"Error while copying old configuration from %s to %s",
oldConfigBeanInfo, moduleFactory), e);
}
@Override
- public synchronized ObjectName createModule(String factoryName, String instanceName)
+ public synchronized ObjectName createModule(final String factoryName, final String instanceName)
throws InstanceAlreadyExistsException {
transactionStatus.checkNotCommitStarted();
}
@Override
- public synchronized void reCreateModule(ObjectName objectName) throws InstanceNotFoundException {
+ public synchronized void reCreateModule(final ObjectName objectName) throws InstanceNotFoundException {
transactionStatus.checkNotCommitStarted();
transactionStatus.checkNotAborted();
checkTransactionName(objectName);
}
private synchronized ObjectName putConfigBeanToJMXAndInternalMaps(
- ModuleIdentifier moduleIdentifier, Module module,
- ModuleFactory moduleFactory,
- @Nullable ModuleInternalInfo maybeOldConfigBeanInfo, DependencyResolver dependencyResolver,
- boolean isDefaultBean, BundleContext bundleContext)
+ final ModuleIdentifier moduleIdentifier, final Module module,
+ final ModuleFactory moduleFactory,
+ @Nullable final ModuleInternalInfo maybeOldConfigBeanInfo, final DependencyResolver dependencyResolver,
+ final boolean isDefaultBean, final BundleContext bundleContext)
throws InstanceAlreadyExistsException {
LOG.debug("Adding module {} to transaction {}", moduleIdentifier, this);
}
@Override
- public synchronized void destroyModule(ObjectName objectName) throws InstanceNotFoundException {
+ public synchronized void destroyModule(final ObjectName objectName) throws InstanceNotFoundException {
checkTransactionName(objectName);
ObjectNameUtil.checkDomain(objectName);
ModuleIdentifier moduleIdentifier = ObjectNameUtil.fromON(objectName,
destroyModule(moduleIdentifier);
}
- private void checkTransactionName(ObjectName objectName) {
+ private void checkTransactionName(final ObjectName objectName) {
String foundTransactionName = ObjectNameUtil
.getTransactionName(objectName);
if (!getTransactionIdentifier().getName().equals(foundTransactionName)) {
}
}
- private synchronized void destroyModule(ModuleIdentifier moduleIdentifier) {
+ private synchronized void destroyModule(final ModuleIdentifier moduleIdentifier) {
LOG.debug("Destroying module {} in transaction {}", moduleIdentifier, this);
transactionStatus.checkNotAborted();
try {
writableSRRegistry.removeServiceReferences(
ObjectNameUtil.createTransactionModuleON(getTransactionName(), moduleIdentifier));
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
LOG.error("Possible code error: cannot find {} in {}", moduleIdentifier, writableSRRegistry);
throw new IllegalStateException("Possible code error: cannot find " + moduleIdentifier, e);
}
Module module = entry.getValue();
try {
module.validate();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Validation exception in {}", getTransactionName(),
e);
collectedExceptions.add(ValidationException
configBeanModificationDisabled.set(true);
try {
validateNoLocks();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
LOG.trace("Commit failed on validation");
// recoverable error
configBeanModificationDisabled.set(false);
moduleIdentifier, getTransactionIdentifier());
AutoCloseable instance = module.getInstance();
Preconditions.checkNotNull(instance, "Instance is null:{} in transaction {}", moduleIdentifier, getTransactionIdentifier());
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Commit failed on {} in transaction {}", moduleIdentifier,
getTransactionIdentifier(), e);
internalAbort();
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName) {
return txLookupRegistry.lookupConfigBeans(moduleName);
}
* {@inheritDoc}
*/
@Override
- public ObjectName lookupConfigBean(String moduleName, String instanceName)
+ public ObjectName lookupConfigBean(final String moduleName, final String instanceName)
throws InstanceNotFoundException {
return txLookupRegistry.lookupConfigBean(moduleName, instanceName);
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName, String instanceName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName, final String instanceName) {
return txLookupRegistry.lookupConfigBeans(moduleName, instanceName);
}
* {@inheritDoc}
*/
@Override
- public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
+ public void checkConfigBeanExists(final ObjectName objectName) throws InstanceNotFoundException {
txLookupRegistry.checkConfigBeanExists(objectName);
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupRuntimeBeans(String moduleName,
- String instanceName) {
+ public Set<ObjectName> lookupRuntimeBeans(final String moduleName,
+ final String instanceName) {
return txLookupRegistry.lookupRuntimeBeans(moduleName, instanceName);
}
}
@Override
- public BundleContext getModuleFactoryBundleContext(String factoryName) {
+ public BundleContext getModuleFactoryBundleContext(final String factoryName) {
Map.Entry<ModuleFactory, BundleContext> factoryBundleContextEntry = this.currentlyRegisteredFactories.get(factoryName);
if (factoryBundleContextEntry == null || factoryBundleContextEntry.getValue() == null) {
throw new NullPointerException("Bundle context of " + factoryName + " ModuleFactory not found.");
@Override
- public synchronized ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
+ public synchronized ObjectName lookupConfigBeanByServiceInterfaceName(final String serviceInterfaceQName, final String refName) {
return writableSRRegistry.lookupConfigBeanByServiceInterfaceName(serviceInterfaceQName, refName);
}
}
@Override
- public synchronized Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
+ public synchronized Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(final String serviceInterfaceQName) {
return writableSRRegistry.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceQName);
}
@Override
- public synchronized Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
+ public synchronized Set<String> lookupServiceInterfaceNames(final ObjectName objectName) throws InstanceNotFoundException {
return writableSRRegistry.lookupServiceInterfaceNames(objectName);
}
@Override
- public synchronized String getServiceInterfaceName(String namespace, String localName) {
+ public synchronized String getServiceInterfaceName(final String namespace, final String localName) {
return writableSRRegistry.getServiceInterfaceName(namespace, localName);
}
@Override
- public synchronized ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException {
+ public synchronized ObjectName saveServiceReference(final String serviceInterfaceName, final String refName, final ObjectName moduleON) throws InstanceNotFoundException {
return writableSRRegistry.saveServiceReference(serviceInterfaceName, refName, moduleON);
}
@Override
- public synchronized void removeServiceReference(String serviceInterfaceName, String refName) throws InstanceNotFoundException {
+ public synchronized void removeServiceReference(final String serviceInterfaceName, final String refName) throws InstanceNotFoundException {
writableSRRegistry.removeServiceReference(serviceInterfaceName, refName);
}
}
@Override
- public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
+ public boolean removeServiceReferences(final ObjectName objectName) throws InstanceNotFoundException {
return writableSRRegistry.removeServiceReferences(objectName);
}
}
@Override
- public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
+ public void checkServiceReferenceExists(final ObjectName objectName) throws InstanceNotFoundException {
writableSRRegistry.checkServiceReferenceExists(objectName);
}
@Override
- public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
+ public ObjectName getServiceReference(final String serviceInterfaceQName, final String refName) throws InstanceNotFoundException {
return writableSRRegistry.getServiceReference(serviceInterfaceQName, refName);
}
}
private final TransactionModuleJMXRegistrator txModuleJMXRegistrator;
private final Map<String, Map.Entry<ModuleFactory, BundleContext>> allCurrentFactories;
- ConfigTransactionLookupRegistry(TransactionIdentifier transactionIdentifier,
- TransactionJMXRegistratorFactory factory, Map<String, Entry<ModuleFactory, BundleContext>> allCurrentFactories) {
+ ConfigTransactionLookupRegistry(final TransactionIdentifier transactionIdentifier,
+ final TransactionJMXRegistratorFactory factory, final Map<String, Entry<ModuleFactory, BundleContext>> allCurrentFactories) {
this.transactionIdentifier = transactionIdentifier;
this.transactionJMXRegistrator = factory.create();
this.txModuleJMXRegistrator = transactionJMXRegistrator.createTransactionModuleJMXRegistrator();
this.allCurrentFactories = allCurrentFactories;
}
- private void checkTransactionName(ObjectName objectName) {
+ private void checkTransactionName(final ObjectName objectName) {
String foundTransactionName = ObjectNameUtil
.getTransactionName(objectName);
if (!transactionIdentifier.getName().equals(foundTransactionName)) {
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName) {
return lookupConfigBeans(moduleName, "*");
}
* {@inheritDoc}
*/
@Override
- public ObjectName lookupConfigBean(String moduleName, String instanceName)
+ public ObjectName lookupConfigBean(final String moduleName, final String instanceName)
throws InstanceNotFoundException {
return LookupBeansUtil.lookupConfigBean(this, moduleName, instanceName);
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupConfigBeans(String moduleName,
- String instanceName) {
+ public Set<ObjectName> lookupConfigBeans(final String moduleName,
+ final String instanceName) {
ObjectName namePattern = ObjectNameUtil.createModulePattern(moduleName,
instanceName, transactionIdentifier.getName());
return txModuleJMXRegistrator.queryNames(namePattern, null);
}
@Override
- public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
+ public void checkConfigBeanExists(final ObjectName objectName) throws InstanceNotFoundException {
ObjectNameUtil.checkDomain(objectName);
ObjectNameUtil.checkType(objectName, ObjectNameUtil.TYPE_MODULE);
checkTransactionName(objectName);
transactionJMXRegistrator.close();
}
- public void registerMBean(ConfigTransactionControllerInternal transactionController, ObjectName controllerObjectName) throws InstanceAlreadyExistsException {
+ public void registerMBean(final ConfigTransactionControllerInternal transactionController, final ObjectName controllerObjectName) throws InstanceAlreadyExistsException {
transactionJMXRegistrator.registerMBean(transactionController, controllerObjectName);
}
* {@inheritDoc}
*/
@Override
- public Set<ObjectName> lookupRuntimeBeans(String moduleName,
- String instanceName) {
+ public Set<ObjectName> lookupRuntimeBeans(final String moduleName,
+ final String instanceName) {
String finalModuleName = moduleName == null ? "*" : moduleName;
String finalInstanceName = instanceName == null ? "*" : instanceName;
ObjectName namePattern = ObjectNameUtil.createRuntimeBeanPattern(
@GuardedBy("this")
private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.empty;
- public DeadlockMonitor(TransactionIdentifier transactionIdentifier) {
+ public DeadlockMonitor(final TransactionIdentifier transactionIdentifier) {
this.transactionIdentifier = transactionIdentifier;
thread = new DeadlockMonitorRunnable();
thread.start();
}
- public synchronized void setCurrentlyInstantiatedModule(ModuleIdentifier currentlyInstantiatedModule) {
+ public synchronized void setCurrentlyInstantiatedModule(final ModuleIdentifier currentlyInstantiatedModule) {
boolean popping = currentlyInstantiatedModule == null;
if (popping) {
}
try {
sleep(WARN_AFTER_MILLIS);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
interrupt();
}
}
this((ModuleIdentifier)null);
}
- private ModuleIdentifierWithNanos(ModuleIdentifier moduleIdentifier) {
+ private ModuleIdentifierWithNanos(final ModuleIdentifier moduleIdentifier) {
this.moduleIdentifier = moduleIdentifier;
nanoTime = System.nanoTime();
}
- private ModuleIdentifierWithNanos(ModuleIdentifierWithNanos copy) {
+ private ModuleIdentifierWithNanos(final ModuleIdentifierWithNanos copy) {
moduleIdentifier = copy.moduleIdentifier;
nanoTime = copy.nanoTime;
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
private final ModuleFactory moduleFactory;
private final BundleContext bundleContext;
- public ModuleInternalInfo(ModuleIdentifier name,
- @Nullable DynamicReadableWrapper readableModule,
- OsgiRegistration osgiRegistration,
- @Nullable RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
- ModuleJMXRegistrator moduleJMXRegistrator, int orderingIdx,
- boolean isDefaultBean, ModuleFactory moduleFactory, BundleContext bundleContext) {
+ public ModuleInternalInfo(final ModuleIdentifier name,
+ @Nullable final DynamicReadableWrapper readableModule,
+ final OsgiRegistration osgiRegistration,
+ @Nullable final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator,
+ final ModuleJMXRegistrator moduleJMXRegistrator, final int orderingIdx,
+ final boolean isDefaultBean, final ModuleFactory moduleFactory, final BundleContext bundleContext) {
if (osgiRegistration == null) {
throw new IllegalArgumentException(
* Compare using orderingIdx
*/
@Override
- public int compareTo(ModuleInternalInfo o) {
+ public int compareTo(final ModuleInternalInfo o) {
return Integer.compare(orderingIdx, o.orderingIdx);
}
try {
boolean skipChecks = true;
newRegistry.saveServiceReference(refNameEntry.getKey(), currentImplementation, skipChecks);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
LOG.error("Cannot save service reference({}, {})", refNameEntry.getKey(), currentImplementation);
throw new IllegalStateException("Possible code error", e);
}
ObjectName on;
try {
on = lookupRegistry.lookupConfigBean(moduleIdentifier.getFactoryName(), moduleIdentifier.getInstanceName());
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
LOG.error("Cannot find instance {}", moduleIdentifier);
throw new IllegalStateException("Cannot find instance " + moduleIdentifier, e);
}
ServiceReferenceJMXRegistration dummyMXBeanRegistration;
try {
dummyMXBeanRegistration = serviceReferenceRegistrator.registerMBean(dummyMXBean, result);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw new IllegalStateException("Possible error in code. Cannot register " + result, e);
}
mBeans.put(serviceReference, new SimpleImmutableEntry<>(dummyMXBean, dummyMXBeanRegistration));
for (ServiceReference serviceReference: mBeans.keySet()) {
try {
removeServiceReference(serviceReference);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new IllegalStateException("Possible error in code", e);
}
}
private static final long serialVersionUID = 1L;
private final String name;
- public TransactionIdentifier(String name) {
+ public TransactionIdentifier(final String name) {
this.name = name;
}
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
cachedInstance = response;
}
return response;
- } catch(InvocationTargetException e) {
+ } catch(final InvocationTargetException e) {
throw e.getCause();
} finally {
if (isGetInstance) {
private final int orderingIdx;
private RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
- public DestroyedModule(ModuleIdentifier identifier, AutoCloseable instance,
- ModuleJMXRegistrator oldJMXRegistrator,
- OsgiRegistration osgiRegistration, int orderingIdx,
+ public DestroyedModule(final ModuleIdentifier identifier, final AutoCloseable instance,
+ final ModuleJMXRegistrator oldJMXRegistrator,
+ final OsgiRegistration osgiRegistration, final int orderingIdx,
final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator) {
this.identifier = identifier;
this.instance = instance;
LOG.trace("Destroying {}", identifier);
try {
instance.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Error while closing instance of {}", identifier, e);
}
try {
oldJMXRegistrator.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Error while closing jmx registrator of {}", identifier, e);
}
try {
if (runtimeBeanRegistrator != null) {
runtimeBeanRegistrator.close();
}
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Error while closing runtime bean jmx registrator of {}", identifier, e);
}
try {
osgiRegistration.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Error while closing osgi registration of {}", identifier, e);
}
}
@Override
- public int compareTo(DestroyedModule o) {
+ public int compareTo(final DestroyedModule o) {
return Integer.compare(orderingIdx, o.orderingIdx);
}
private final BundleContext bundleContext;
@Nullable private ModuleInternalInfo maybeOldInternalInfo;
- public ModuleInternalTransactionalInfo(ModuleIdentifier name, Module proxiedModule,
- ModuleFactory moduleFactory,
- ModuleInternalInfo maybeOldInternalInfo,
- TransactionModuleJMXRegistration transactionModuleJMXRegistration,
- boolean isDefaultBean, Module realModule, BundleContext bundleContext) {
+ public ModuleInternalTransactionalInfo(final ModuleIdentifier name, final Module proxiedModule,
+ final ModuleFactory moduleFactory,
+ final ModuleInternalInfo maybeOldInternalInfo,
+ final TransactionModuleJMXRegistration transactionModuleJMXRegistration,
+ final boolean isDefaultBean, final Module realModule, final BundleContext bundleContext) {
this.name = name;
this.proxiedModule = proxiedModule;
this.moduleFactory = moduleFactory;
try {
configMBeanServer.addNotificationListener(
MBeanServerDelegate.DELEGATE_NAME, listener, null, null);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new RuntimeException("Could not add notification listener", e);
}
return listener;
try {
setter = module.getClass().getMethod(method.getName(),
method.getParameterTypes());
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
throw new RuntimeException("No such method on "
+ moduleIdentifier, e);
}
try {
obj = internalServer
.getAttribute(objectNameInternal, attributeName);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
new MBeanException(e);
}
Object value = getAttribute(attributeName);
result.add(new Attribute(attributeName, value));
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.debug("Getting attribute {} failed", attributeName, e);
}
}
&& signature[0].equals(String.class.getName())) {
try {
return getAttribute((String) params[0]);
- } catch (AttributeNotFoundException e) {
+ } catch (final AttributeNotFoundException e) {
throw new MBeanException(e, "Attribute not found on "
+ moduleIdentifier);
}
// we need to go deeper
inspectedClass = inspectedClass.getSuperclass();
// no need to go further
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
inspectedClass = Object.class;
}
} while (!inspectedClass.equals(Object.class));
if (annotation != null) {
result.add(annotation);
}
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
}
}
PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(List.class);
}
- public AttributeHolder(String name, Object object, String returnType,
- boolean writable,
- @Nullable RequireInterface requireInterfaceAnnotation,
- String description) {
+ public AttributeHolder(final String name, final Object object, final String returnType,
+ final boolean writable,
+ @Nullable final RequireInterface requireInterfaceAnnotation,
+ final String description) {
if (name == null) {
throw new NullPointerException();
}
* @return empty string if no annotation is found, or list of descriptions
* separated by newline
*/
- static String findDescription(Method setter, Set<Class<?>> jmxInterfaces) {
+ static String findDescription(final Method setter, final Set<Class<?>> jmxInterfaces) {
List<Description> descriptions = AnnotationsHelper
.findMethodAnnotationInSuperClassesAndIfcs(setter, Description.class, jmxInterfaces);
return AnnotationsHelper.aggregateDescriptions(descriptions);
* @throws IllegalArgumentException if set of exported interfaces contains non interface type
*/
static RequireInterface findRequireInterfaceAnnotation(final Method setter,
- Set<Class<?>> inspectedInterfaces) {
+ final Set<Class<?>> inspectedInterfaces) {
// only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List<ObjectName> y) to continue
* for recreating Module.
*
*/
- public DynamicReadableWrapper(Module module, AutoCloseable instance,
- ModuleIdentifier moduleIdentifier, MBeanServer internalServer,
- MBeanServer configMBeanServer) {
+ public DynamicReadableWrapper(final Module module, final AutoCloseable instance,
+ final ModuleIdentifier moduleIdentifier, final MBeanServer internalServer,
+ final MBeanServer configMBeanServer) {
super(module, false, moduleIdentifier, ObjectNameUtil
.createReadOnlyModuleON(moduleIdentifier),
getEmptyOperations(), internalServer, configMBeanServer);
}
@Override
- public Object invoke(String actionName, Object[] params, String[] signature)
+ public Object invoke(final String actionName, final Object[] params, final String[] signature)
throws MBeanException, ReflectionException {
if ("getInstance".equals(actionName)
&& (params == null || params.length == 0)
}
@Override
- public Object getAttribute(String attributeName)
+ public Object getAttribute(final String attributeName)
throws AttributeNotFoundException, MBeanException,
ReflectionException {
if ("getInstance".equals(attributeName)) {
}
@Override
- public void setAttribute(Attribute attribute)
+ public void setAttribute(final Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException {
throw new UnsupportedOperationException(
}
@Override
- public AttributeList setAttributes(AttributeList attributes) {
+ public AttributeList setAttributes(final AttributeList attributes) {
throw new UnsupportedOperationException(
"setAttributes is not supported on " + moduleIdentifier);
}
private final ReadOnlyAtomicBoolean configBeanModificationDisabled;
- public DynamicWritableWrapper(Module module,
- ModuleIdentifier moduleIdentifier,
- String transactionIdentifier,
- ReadOnlyAtomicBoolean configBeanModificationDisabled,
- MBeanServer internalServer, MBeanServer configMBeanServer) {
+ public DynamicWritableWrapper(final Module module,
+ final ModuleIdentifier moduleIdentifier,
+ final String transactionIdentifier,
+ final ReadOnlyAtomicBoolean configBeanModificationDisabled,
+ final MBeanServer internalServer, final MBeanServer configMBeanServer) {
super(module, true, moduleIdentifier, ObjectNameUtil
.createTransactionModuleON(transactionIdentifier, moduleIdentifier), getOperations(moduleIdentifier),
internalServer, configMBeanServer);
}
private static MBeanOperationInfo[] getOperations(
- ModuleIdentifier moduleIdentifier) {
+ final ModuleIdentifier moduleIdentifier) {
Method validationMethod;
try {
validationMethod = DynamicWritableWrapper.class.getMethod("validate");
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
throw new IllegalStateException("No such method exception on " + moduleIdentifier, e);
}
return new MBeanOperationInfo[]{new MBeanOperationInfo("Validation", validationMethod)};
}
@Override
- public synchronized void setAttribute(Attribute attribute)
+ public synchronized void setAttribute(final Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
Attribute newAttribute = attribute;
if (configBeanModificationDisabled.get()) {
}
internalServer.setAttribute(objectNameInternal, newAttribute);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
throw new MBeanException(e);
}
}
- private Attribute fixDependencyListAttribute(Attribute attribute) {
+ private Attribute fixDependencyListAttribute(final Attribute attribute) {
Attribute newAttribute = attribute;
AttributeHolder attributeHolder = attributeHolderMap.get(newAttribute.getName());
if (attributeHolder.getRequireInterfaceOrNull() != null) {
return newAttribute;
}
- private Attribute fixDependencyAttribute(Attribute attribute) {
+ private Attribute fixDependencyAttribute(final Attribute attribute) {
Attribute newAttribute = attribute;
AttributeHolder attributeHolder = attributeHolderMap.get(newAttribute.getName());
if (attributeHolder.getRequireInterfaceOrNull() != null) {
return newAttribute;
}
- private ObjectName[] fixObjectNames(ObjectName[] dependencies) {
+ private ObjectName[] fixObjectNames(final ObjectName[] dependencies) {
int i = 0;
for (ObjectName dependencyOn : dependencies) {
}
@Override
- public AttributeList setAttributes(AttributeList attributes) {
+ public AttributeList setAttributes(final AttributeList attributes) {
AttributeList result = new AttributeList();
for (Object attributeObject : attributes) {
Attribute attribute = (Attribute) attributeObject;
try {
setAttribute(attribute);
result.add(attribute);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e);
throw new IllegalArgumentException(
"Setting attribute failed - " + attribute.getName()
}
@Override
- public Object invoke(String actionName, Object[] params, String[] signature)
+ public Object invoke(final String actionName, final Object[] params, final String[] signature)
throws MBeanException, ReflectionException {
if ("validate".equals(actionName)
&& (params == null || params.length == 0)
&& (signature == null || signature.length == 0)) {
try {
validate();
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new MBeanException(ValidationException.createForSingleException(
moduleIdentifier, e));
ReadOnlyAtomicBoolean {
private final AtomicBoolean atomicBoolean;
- public ReadOnlyAtomicBooleanImpl(AtomicBoolean atomicBoolean) {
+ public ReadOnlyAtomicBooleanImpl(final AtomicBoolean atomicBoolean) {
super();
this.atomicBoolean = atomicBoolean;
}
* if unique constraint on module names is violated
*/
public HierarchicalConfigMBeanFactoriesHolder(
- Map<String, Map.Entry<ModuleFactory, BundleContext>> factoriesMap) {
+ final Map<String, Map.Entry<ModuleFactory, BundleContext>> factoriesMap) {
this.moduleNamesToConfigBeanFactories = Collections
.unmodifiableMap(factoriesMap);
moduleNames = Collections.unmodifiableSet(new TreeSet<>(
* @throws IllegalArgumentException
* if factory is not found
*/
- public ModuleFactory findByModuleName(String moduleName) {
+ public ModuleFactory findByModuleName(final String moduleName) {
Map.Entry<ModuleFactory, BundleContext> result = moduleNamesToConfigBeanFactories.get(moduleName);
if (result == null) {
throw new ModuleFactoryNotFoundException(moduleName);
private final Map<String, String> properties;
public HierarchicalRuntimeBeanRegistrationImpl(
- ModuleIdentifier moduleIdentifier,
- InternalJMXRegistrator internalJMXRegistrator,
- Map<String, String> properties) {
+ final ModuleIdentifier moduleIdentifier,
+ final InternalJMXRegistrator internalJMXRegistrator,
+ final Map<String, String> properties) {
this.moduleIdentifier = moduleIdentifier;
this.internalJMXRegistrator = internalJMXRegistrator;
this.properties = properties;
}
@Override
- public HierarchicalRuntimeBeanRegistrationImpl register(String key,
- String value, RuntimeBean mxBean) {
+ public HierarchicalRuntimeBeanRegistrationImpl register(final String key,
+ final String value, final RuntimeBean mxBean) {
Map<String, String> currentProperties = new HashMap<>(properties);
currentProperties.put(key, value);
ObjectName on = ObjectNameUtil.createRuntimeBeanName(
InternalJMXRegistrator child = internalJMXRegistrator.createChild();
try {
child.registerMBean(mxBean, on);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw RootRuntimeBeanRegistratorImpl.sanitize(e, moduleIdentifier,
on);
}
throws InstanceAlreadyExistsException {
try {
getMBeanServer().registerMBean(object, on);
- } catch (NotCompliantMBeanException e) {
+ } catch (final NotCompliantMBeanException e) {
throw new IllegalArgumentException("Object does not comply to JMX", e);
- } catch (MBeanRegistrationException e) {
+ } catch (final MBeanRegistrationException e) {
throw new IllegalStateException("Failed to register " + on, e);
}
try {
getMBeanServer().unregisterMBean(on);
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
LOG.warn("MBean {} not found on server", on, e);
- } catch (MBeanRegistrationException e) {
+ } catch (final MBeanRegistrationException e) {
throw new IllegalStateException("Failed to unregister MBean " + on, e);
}
}
for (ObjectName on : registeredObjectNames) {
try {
getMBeanServer().unregisterMBean(on);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Ignoring error while unregistering {}", on, e);
}
}
public HierarchicalRuntimeBeanRegistrationImpl registerRoot(final RuntimeBean mxBean) {
try {
internalJMXRegistrator.registerMBean(mxBean, defaultRuntimeON);
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
throw sanitize(e, moduleIdentifier, defaultRuntimeON);
}
return new HierarchicalRuntimeBeanRegistrationImpl(moduleIdentifier,
private final String serviceInterfaceName;
private final String refName;
- public ServiceReference(String serviceInterfaceName, String refName) {
+ public ServiceReference(final String serviceInterfaceName, final String refName) {
this.serviceInterfaceName = serviceInterfaceName;
this.refName = refName;
}
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
public class ServiceReferenceMXBeanImpl implements ServiceReferenceMXBean {
private ObjectName currentImplementation;
- public ServiceReferenceMXBeanImpl(ObjectName currentImplementation) {
+ public ServiceReferenceMXBeanImpl(final ObjectName currentImplementation) {
this.currentImplementation = currentImplementation;
}
return currentImplementation;
}
- public void setCurrentImplementation(ObjectName currentImplementation) {
+ public void setCurrentImplementation(final ObjectName currentImplementation) {
this.currentImplementation = currentImplementation;
}
}
class ServiceReferenceJMXRegistration implements AutoCloseable {
private final InternalJMXRegistration registration;
- ServiceReferenceJMXRegistration(InternalJMXRegistration registration) {
+ ServiceReferenceJMXRegistration(final InternalJMXRegistration registration) {
this.registration = registration;
}
private final InternalJMXRegistrator currentJMXRegistrator;
private final String nullableTransactionName;
- public ServiceReferenceRegistratorImpl(NestableJMXRegistrator parentRegistrator, String nullableTransactionName){
+ public ServiceReferenceRegistratorImpl(final NestableJMXRegistrator parentRegistrator, final String nullableTransactionName){
currentJMXRegistrator = parentRegistrator.createChild();
this.nullableTransactionName = nullableTransactionName;
}
@Override
- public ServiceReferenceJMXRegistration registerMBean(ServiceReferenceMXBeanImpl object,
- ObjectName on) throws InstanceAlreadyExistsException {
+ public ServiceReferenceJMXRegistration registerMBean(final ServiceReferenceMXBeanImpl object,
+ final ObjectName on) throws InstanceAlreadyExistsException {
String actualTransactionName = ObjectNameUtil.getTransactionName(on);
boolean broken = false;
broken |= (nullableTransactionName == null) != (actualTransactionName == null);
private final NestableJMXRegistrator parentRegistrator;
private final String nullableTransactionName;
- public ServiceReferenceTransactionRegistratorFactoryImpl(TransactionModuleJMXRegistrator parentRegistrator,
- String nullableTransactionName) {
+ public ServiceReferenceTransactionRegistratorFactoryImpl(final TransactionModuleJMXRegistrator parentRegistrator,
+ final String nullableTransactionName) {
this.parentRegistrator = parentRegistrator;
this.nullableTransactionName = nullableTransactionName;
}
- public ServiceReferenceTransactionRegistratorFactoryImpl(BaseJMXRegistrator baseJMXRegistrator) {
+ public ServiceReferenceTransactionRegistratorFactoryImpl(final BaseJMXRegistrator baseJMXRegistrator) {
this.parentRegistrator = baseJMXRegistrator;
this.nullableTransactionName = null;
}
private final String transactionName;
public TransactionModuleJMXRegistrator(
- InternalJMXRegistrator internalJMXRegistrator,
- String transactionName) {
+ final InternalJMXRegistrator internalJMXRegistrator,
+ final String transactionName) {
this.currentJMXRegistrator = internalJMXRegistrator.createChild();
this.transactionName = transactionName;
}
AutoCloseable {
private final InternalJMXRegistration registration;
- TransactionModuleJMXRegistration(InternalJMXRegistration registration) {
+ TransactionModuleJMXRegistration(final InternalJMXRegistration registration) {
this.registration = registration;
}
}
}
- public TransactionModuleJMXRegistration registerMBean(Object object,
- ObjectName on) throws InstanceAlreadyExistsException {
+ public TransactionModuleJMXRegistration registerMBean(final Object object,
+ final ObjectName on) throws InstanceAlreadyExistsException {
if (!transactionName.equals(ObjectNameUtil.getTransactionName(on))) {
throw new IllegalArgumentException("Transaction name mismatch between expected "
+ transactionName + " " + "and " + on);
currentJMXRegistrator.registerMBean(object, on));
}
- public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
+ public Set<ObjectName> queryNames(final ObjectName name, final QueryExp query) {
return currentJMXRegistrator.queryNames(name, query);
}
* It is expected that before using this method OSGi service registry will
* be cleaned from previous registrations.
*/
- public OsgiRegistration registerToOsgi(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
- BundleContext bundleContext,
- Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
+ public OsgiRegistration registerToOsgi(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier,
+ final BundleContext bundleContext,
+ final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
return new OsgiRegistration(instance, moduleIdentifier, bundleContext, serviceNamesToAnnotations);
}
@GuardedBy("this")
private final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations;
- public OsgiRegistration(AutoCloseable instance, ModuleIdentifier moduleIdentifier,
- BundleContext bundleContext,
- Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
+ public OsgiRegistration(final AutoCloseable instance, final ModuleIdentifier moduleIdentifier,
+ final BundleContext bundleContext,
+ final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
this.instance = instance;
this.moduleIdentifier = moduleIdentifier;
this.serviceNamesToAnnotations = serviceNamesToAnnotations;
this.serviceRegistrations = registerToSR(instance, bundleContext, serviceNamesToAnnotations);
}
- private static Set<ServiceRegistration<?>> registerToSR(AutoCloseable instance, BundleContext bundleContext,
- Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
+ private static Set<ServiceRegistration<?>> registerToSR(final AutoCloseable instance, final BundleContext bundleContext,
+ final Map<ServiceInterfaceAnnotation, String /* service ref name */> serviceNamesToAnnotations) {
Set<ServiceRegistration<?>> serviceRegistrations = new HashSet<>();
for (Entry<ServiceInterfaceAnnotation, String /* service ref name */> entry : serviceNamesToAnnotations.entrySet()) {
ServiceInterfaceAnnotation annotation = entry.getKey();
for (ServiceRegistration<?> serviceRegistration : serviceRegistrations) {
try {
serviceRegistration.unregister();
- } catch(IllegalStateException e) {
+ } catch(final IllegalStateException e) {
LOG.trace("Cannot unregister {}", serviceRegistration, e);
}
}
serviceRegistrations.clear();
}
- public synchronized void updateRegistrations(Map<ServiceInterfaceAnnotation, String /* service ref name */> newAnnotationMapping,
- BundleContext bundleContext, AutoCloseable newInstance) {
+ public synchronized void updateRegistrations(final Map<ServiceInterfaceAnnotation, String /* service ref name */> newAnnotationMapping,
+ final BundleContext bundleContext, final AutoCloseable newInstance) {
boolean notEquals = !this.instance.equals(newInstance);
notEquals |= !newAnnotationMapping.equals(serviceNamesToAnnotations);
if (notEquals) {
}
}
- private static Dictionary<String, String> createProps(String serviceName) {
+ private static Dictionary<String, String> createProps(final String serviceName) {
Hashtable<String, String> result = new Hashtable<>();
result.put(SERVICE_NAME_OSGI_PROP, serviceName);
return result;
}
@Override
- public Object addingService(ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
+ public Object addingService(final ServiceReference<ModuleFactory> moduleFactoryServiceReference) {
blankTransactionAsync();
return null;
}
CommitStatus commitStatus = blankTransaction.hit();
LOG.debug("Committed blank transaction with status {}", commitStatus);
return;
- } catch (ConflictingVersionException e) {
+ } catch (final ConflictingVersionException e) {
lastException = e;
try {
Thread.sleep(1000);
- } catch (InterruptedException interruptedException) {
+ } catch (final InterruptedException interruptedException) {
Thread.currentThread().interrupt();
LOG.debug("blankTransactionSync was interrupted");
return;
}
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
LOG.error("Validation exception while running blank transaction indicates programming error", e);
}
}
}
@Override
- public void modifiedService(ServiceReference <ModuleFactory> moduleFactoryServiceReference, Object o) {
+ public void modifiedService(final ServiceReference <ModuleFactory> moduleFactoryServiceReference, final Object o) {
blankTransactionAsync();
}
@Override
- public void removedService(ServiceReference<ModuleFactory> moduleFactoryServiceReference, Object o) {
+ public void removedService(final ServiceReference<ModuleFactory> moduleFactoryServiceReference, final Object o) {
blankTransactionAsync();
}
Collection<ServiceReference<ModuleFactory>> serviceReferences;
try {
serviceReferences = bundleContext.getServiceReferences(ModuleFactory.class, null);
- } catch (InvalidSyntaxException e) {
+ } catch (final InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
Map<String, Map.Entry<ModuleFactory, BundleContext>> result = new HashMap<>(serviceReferences.size());
forEachAdditionalBundle(tracker -> tracker.addingBundle(bundle, event));
LOG.trace("AddingBundle for {} and event {} finished successfully",bundle,event);
return primaryTrackerRetVal;
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Failed to add bundle {}", bundle, e);
throw e;
}
primaryTracker.removedBundle(bundle, event, object.get());
forEachAdditionalBundle(tracker -> tracker.removedBundle(bundle, event, null));
LOG.trace("Removed bundle event for {} finished successfully.",bundle);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Failed to remove bundle {}", bundle, e);
}
}
private final BlankTransactionServiceTracker blankTransactionServiceTracker;
private static final Logger LOG = LoggerFactory.getLogger(ModuleFactoryBundleTracker.class);
- public ModuleFactoryBundleTracker(BlankTransactionServiceTracker blankTransactionServiceTracker) {
+ public ModuleFactoryBundleTracker(final BlankTransactionServiceTracker blankTransactionServiceTracker) {
this.blankTransactionServiceTracker = blankTransactionServiceTracker;
}
@Override
- public Boolean addingBundle(Bundle bundle, BundleEvent event) {
+ public Boolean addingBundle(final Bundle bundle, final BundleEvent event) {
URL resource = bundle.getEntry("META-INF/services/" + ModuleFactory.class.getName());
LOG.trace("Got addingBundle event of bundle {}, resource {}, event {}",
bundle, resource, event);
}
return Boolean.TRUE;
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.error("Error while reading {}", resource, e);
throw new RuntimeException(e);
}
}
@Override
- public void modifiedBundle(Bundle bundle, BundleEvent event, Boolean hasFactory) {
+ public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Boolean hasFactory) {
// NOOP
}
@Override
- public void removedBundle(Bundle bundle, BundleEvent event, Boolean hasFactory) {
+ public void removedBundle(final Bundle bundle, final BundleEvent event, final Boolean hasFactory) {
if(hasFactory) {
// workaround for service tracker not getting removed service event
blankTransactionServiceTracker.blankTransactionSync();
}
@VisibleForTesting
- protected static ServiceRegistration<?> registerFactory(String factoryClassName, Bundle bundle) {
+ protected static ServiceRegistration<?> registerFactory(final String factoryClassName, final Bundle bundle) {
String errorMessage;
Exception ex = null;
try {
return bundle.getBundleContext().registerService(
ModuleFactory.class.getName(), clazz.newInstance(),
null);
- } catch (InstantiationException e) {
+ } catch (final InstantiationException e) {
errorMessage = logMessage(
"Could not instantiate {} in bundle {}, reason {}",
factoryClassName, bundle, e);
ex = e;
- } catch (IllegalAccessException e) {
+ } catch (final IllegalAccessException e) {
errorMessage = logMessage(
"Illegal access during instantiation of class {} in bundle {}, reason {}",
factoryClassName, bundle, e);
"Class {} does not implement {} in bundle {}", clazz,
ModuleFactory.class, bundle);
}
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
errorMessage = logMessage(
"Could not find class {} in bundle {}, reason {}",
factoryClassName, bundle, e);
throw ex == null ? new IllegalStateException(errorMessage) : new IllegalStateException(errorMessage, ex);
}
- public static String logMessage(String slfMessage, Object... params) {
+ public static String logMessage(final String slfMessage, final Object... params) {
LOG.info(slfMessage, params);
String formatMessage = slfMessage.replaceAll("\\{\\}", "%s");
return String.format(formatMessage, params);
if(!starting) {
moduleInfoRegistry.updateService();
}
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.error("Error while reading {} from bundle {}", resource, bundle, e);
- } catch (RuntimeException e) {
+ } catch (final RuntimeException e) {
LOG.error("Failed to process {} for bundle {}", resource, bundle, e);
}
for (ObjectRegistration<YangModuleInfo> reg : regs) {
try {
reg.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.error("Unable to unregister YangModuleInfo {}", reg.getInstance(), e);
}
}
try {
Object instanceObj = clazz.newInstance();
instance = YangModelBindingProvider.class.cast(instanceObj);
- } catch (InstantiationException e) {
+ } catch (final InstantiationException e) {
errorMessage = logMessage("Could not instantiate {} in bundle {}, reason {}", moduleInfoClass, bundle, e);
throw new IllegalStateException(errorMessage, e);
- } catch (IllegalAccessException e) {
+ } catch (final IllegalAccessException e) {
errorMessage = logMessage("Illegal access during instantiation of class {} in bundle {}, reason {}",
moduleInfoClass, bundle, e);
throw new IllegalStateException(errorMessage, e);
private static Class<?> loadClass(final String moduleInfoClass, final Bundle bundle) {
try {
return bundle.loadClass(moduleInfoClass);
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
String errorMessage = logMessage("Could not find class {} in bundle {}, reason {}", moduleInfoClass,
bundle, e);
throw new IllegalStateException(errorMessage);
private LookupBeansUtil() {
}
- public static ObjectName lookupConfigBean(LookupRegistry lookupRegistry,
- String moduleName, String instanceName)
+ public static ObjectName lookupConfigBean(final LookupRegistry lookupRegistry,
+ final String moduleName, final String instanceName)
throws InstanceNotFoundException {
Set<ObjectName> objectNames = lookupRegistry.lookupConfigBeans(
moduleName, instanceName);
private ModuleQNameUtil() {
}
- public static Set<String> getQNames(Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
- Set<String> result = new HashSet<>();
- for (Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
+ public static Set<String> getQNames(final Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
+ final Set<String> result = new HashSet<>();
+ for (final Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
Class<?> inspected = entry.getKey().getClass();
if (inspected.isInterface()) {
throw new IllegalArgumentException("Unexpected interface " + inspected);
AutoCloseable ac = it.previous();
try {
ac.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
LOG.warn("Exception while closing {}", ac, e);
if (firstException == null) {
firstException = e;
configRegistry.beginConfig();
fail();
- } catch (IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
assertTrue(
e.getMessage(),
e.getMessage()
} finally {
try {
configRegistry.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
// ignore
LOG.warn("Ignoring exception", e);
}
protected abstract AutoCloseable prepareMockedInstance() throws Exception;
- public AbstractMockedModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
+ public AbstractMockedModule(final DynamicMBeanWithInstance old, final ModuleIdentifier id) {
if(old!=null)
instance = old.getInstance();
else
try {
instance = prepareMockedInstance();
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new RuntimeException(e);
}
@Override
- public boolean canReuse(Module oldModule) {
+ public boolean canReuse(final Module oldModule) {
return instance!=null;
}
* This class must implement Module interface and all exported
* interfaces.
*/
- public ClassBasedModuleFactory(String implementationName,
- Class<? extends Module> configBeanClass) {
+ public ClassBasedModuleFactory(final String implementationName,
+ final Class<? extends Module> configBeanClass) {
this.implementationName = implementationName;
this.configBeanClass = configBeanClass;
}
}
@Override
- public Module createModule(String instanceName,
- DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext bundleContext)
+ public Module createModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old, final BundleContext bundleContext)
throws Exception {
Preconditions.checkNotNull(old);
return constructModule(instanceName, dependencyResolver, old);
}
- private Module constructModule(String instanceName, DependencyResolver dependencyResolver, DynamicMBeanWithInstance old) throws InstantiationException, IllegalAccessException, InvocationTargetException {
+ private Module constructModule(final String instanceName, final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old) throws InstantiationException, IllegalAccessException, InvocationTargetException {
Preconditions.checkNotNull(dependencyResolver);
ModuleIdentifier moduleIdentifier = new ModuleIdentifier(implementationName, instanceName);
Constructor<? extends Module> declaredConstructor;
try {
declaredConstructor = configBeanClass.getDeclaredConstructor(DynamicMBeanWithInstance.class, ModuleIdentifier.class);
- } catch (NoSuchMethodException e) {
+ } catch (final NoSuchMethodException e) {
throw new IllegalStateException(
"Did not find constructor with parameters (DynamicMBeanWithInstance) in "
+ configBeanClass, e);
}
@Override
- public Module createModule(String instanceName,
- DependencyResolver dependencyResolver, BundleContext bundleContext) {
+ public Module createModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
try {
return constructModule(instanceName, dependencyResolver, null);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
@Override
public boolean isModuleImplementingServiceInterface(
- Class<? extends AbstractServiceInterface> serviceInterface) {
+ final Class<? extends AbstractServiceInterface> serviceInterface) {
Class<?>[] classes = configBeanClass.getInterfaces();
List<Class<?>> ifc = Arrays.asList(classes);
if (ifc.contains(serviceInterface)) {
}
@Override
- public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext bundleContext) {
+ public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) {
return new HashSet<>();
}
try {
configRegistryJMXRegistrator.registerToJMX(mockedRegistry);
fail();
- } catch (Exception e) {
+ } catch (final Exception e) {
assertTrue(e instanceof InstanceAlreadyExistsException);
}
}
Method setter;
try {
setter = clazz.getMethod(methodName, new Class[] { ObjectName.class });
- } catch (Exception e) {
+ } catch (final Exception e) {
throw Throwables.propagate(e);
}
return setter;
assertRequireInterfaceAnnotationHasCorrectValue(SubClassWithAnnotation.class, setSomethingString,
emptySetOfInterfaces(), SubSI2.class);
fail();
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
assertTrue(e.getMessage(),
e.getMessage().startsWith("Error finding @RequireInterface. More than one value specified"));
}
public class DynamicReadableWrapperTest extends AbstractDynamicWrapperTest {
@Override
- protected AbstractDynamicWrapper getDynamicWrapper(Module module,
- ModuleIdentifier moduleIdentifier) {
+ protected AbstractDynamicWrapper getDynamicWrapper(final Module module,
+ final ModuleIdentifier moduleIdentifier) {
return new DynamicReadableWrapper(module, null, moduleIdentifier,
internalServer, ManagementFactory.getPlatformMBeanServer());
}
atomicBoolean);
@Override
- protected AbstractDynamicWrapper getDynamicWrapper(Module module,
- ModuleIdentifier moduleIdentifier) {
+ protected AbstractDynamicWrapper getDynamicWrapper(final Module module,
+ final ModuleIdentifier moduleIdentifier) {
return new DynamicWritableWrapper(module, moduleIdentifier,
"transaction-1",
readOnlyAtomicBoolean, MBeanServerFactory.createMBeanServer(),
}
}
- private void setNumberOfThreads(int numberOfThreads) throws Exception {
+ private void setNumberOfThreads(final int numberOfThreads) throws Exception {
DynamicMBean proxy = JMX.newMBeanProxy(platformMBeanServer,
threadPoolDynamicWrapperON, DynamicMBean.class);
try {
setNumberOfThreads(newThreadCount);
fail();
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
assertEquals("Operation is not allowed now", e.getMessage());
} finally {
atomicBoolean.set(false);
public class HardcodedModuleFactoriesResolver implements ModuleFactoriesResolver {
private Map<String, Map.Entry<ModuleFactory, BundleContext>> factories;
- public HardcodedModuleFactoriesResolver(BundleContext bundleContext, ModuleFactory... list) {
+ public HardcodedModuleFactoriesResolver(final BundleContext bundleContext, final ModuleFactory... list) {
List<ModuleFactory> factoryList = Arrays.asList(list);
this.factories = new HashMap<>(factoryList.size());
for (ModuleFactory moduleFactory : list) {
doReturn(f1).when(bundleContext).getService(s2);
try {
resolver.getAllFactories();
- } catch (Exception e) {
+ } catch (final Exception e) {
assertThat(e.getMessage(), containsString(f1.getImplementationName()));
assertThat(e.getMessage(), containsString("unique"));
return;
public void testRegisterFactoryInstantiateEx() throws Exception {
try {
ModuleFactoryBundleTracker.registerFactory(WrongConstructorTestingFactory.class.getName(), bundle);
- } catch (Exception e) {
+ } catch (final Exception e) {
verifyZeroInteractions(context);
assertNotNull(e.getCause());
assertEquals(InstantiationException.class, e.getCause().getClass());
public void testRegisterFactoryInstantiateExAccess() throws Exception {
try {
ModuleFactoryBundleTracker.registerFactory(NoAccessConstructorTestingFactory.class.getName(), bundle);
- } catch (Exception e) {
+ } catch (final Exception e) {
verifyZeroInteractions(context);
assertNotNull(e.getCause());
assertEquals(IllegalAccessException.class, e.getCause().getClass());
public void testRegisterFactoryNotExtending() throws Exception {
try {
ModuleFactoryBundleTracker.registerFactory(NotExtendingTestingFactory.class.getName(), bundle);
- } catch (Exception e) {
+ } catch (final Exception e) {
verifyZeroInteractions(context);
return;
}
public void testRegisterFactoryNotExisting() throws Exception {
try {
ModuleFactoryBundleTracker.registerFactory("Unknown class", bundle);
- } catch (Exception e) {
+ } catch (final Exception e) {
verifyZeroInteractions(context);
assertNotNull(e.getCause());
assertEquals(ClassNotFoundException.class, e.getCause().getClass());
doReturn(getClass().getResource("/module-factories/module-factory-fail")).when(bundle).getEntry(anyString());
try {
tracker.addingBundle(bundle, mock(BundleEvent.class));
- } catch (Exception e) {
+ } catch (final Exception e) {
verifyZeroInteractions(context);
return;
}
try {
platformMBeanServer.getMBeanInfo(on);
fail();
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
}
}
try {
createRoot();
fail();
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
assertThat(e.getMessage(), containsString(rootRegistration
.getObjectName().toString()));
assertThat(e.getMessage(),
private TestingThreadPoolIfc threadPool;
private String someParam;
- public TestingParallelAPSPImpl(TestingThreadPoolIfc threadPool,
- String someParam) {
+ public TestingParallelAPSPImpl(final TestingThreadPoolIfc threadPool,
+ final String someParam) {
checkArgument(
threadPool.getMaxNumberOfThreads() >= MINIMAL_NUMBER_OF_THREADS,
"Parameter 'threadPool' has not enough threads");
return threadPool;
}
- void setSomeParam(String s) {
+ void setSomeParam(final String s) {
checkArgument(Strings.isNullOrEmpty(someParam) == false,
"Parameter 'someParam' is blank");
this.someParam = s;
private TestingParallelAPSPImpl instance;
private String someParam;
- public TestingParallelAPSPModule(ModuleIdentifier identifier,
- DependencyResolver dependencyResolver,
- @Nullable AutoCloseable oldCloseable,
- @Nullable TestingParallelAPSPImpl oldInstance) {
+ public TestingParallelAPSPModule(final ModuleIdentifier identifier,
+ final DependencyResolver dependencyResolver,
+ @Nullable final AutoCloseable oldCloseable,
+ @Nullable final TestingParallelAPSPImpl oldInstance) {
this.identifier = identifier;
this.dependencyResolver = dependencyResolver;
this.oldCloseable = oldCloseable;
@RequireInterface(TestingThreadPoolServiceInterface.class)
@Override
- public void setThreadPool(ObjectName threadPoolName) {
+ public void setThreadPool(final ObjectName threadPoolName) {
this.threadPoolON = threadPoolName;
}
}
@Override
- public void setSomeParam(String someParam) {
+ public void setSomeParam(final String someParam) {
this.someParam = someParam;
}
dependencyResolver.resolveInstance(TestingThreadPoolIfc.class,
threadPoolON, threadPoolONJMXAttribute);
throw new RuntimeException("fail");
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
checkState("Commit was not triggered".equals(e.getMessage()),
e.getMessage());
}
int threadCount;
try {
threadCount = (Integer)dependencyResolver.getAttribute(threadPoolON, "ThreadCount");
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new IllegalStateException(e);
}
checkState(threadCount > 0);
if (oldCloseable != null) {
try {
oldCloseable.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new RuntimeException(e);
}
}
}
@Override
- public TestingParallelAPSPModule createModule(String instanceName,
- DependencyResolver dependencyResolver, BundleContext bundleContext) {
+ public TestingParallelAPSPModule createModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
return new TestingParallelAPSPModule(new ModuleIdentifier(NAME,
instanceName), dependencyResolver, null, null);
}
@Override
- public TestingParallelAPSPModule createModule(String instanceName,
- DependencyResolver dependencyResolver, DynamicMBeanWithInstance old, BundleContext context)
+ public TestingParallelAPSPModule createModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final DynamicMBeanWithInstance old, final BundleContext context)
throws Exception {
TestingParallelAPSPImpl oldInstance;
try {
oldInstance = (TestingParallelAPSPImpl) old.getInstance();
- } catch (ClassCastException e) {
+ } catch (final ClassCastException e) {
oldInstance = null;
}
TestingParallelAPSPModule result = new TestingParallelAPSPModule(
@Override
public boolean isModuleImplementingServiceInterface(
- Class<? extends AbstractServiceInterface> serviceInterface) {
+ final Class<? extends AbstractServiceInterface> serviceInterface) {
return false;
}
@Override
- public Set<Module> getDefaultModules(DependencyResolverFactory dependencyResolverFactory, BundleContext context) {
+ public Set<Module> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext context) {
return new HashSet<>();
}
protected abstract String getThreadPoolImplementationName();
protected ObjectName createParallelAPSP(
- ConfigTransactionJMXClient transaction, ObjectName threadPoolON)
+ final ConfigTransactionJMXClient transaction, final ObjectName threadPoolON)
throws InstanceAlreadyExistsException {
ObjectName apspName = transaction.createModule(
TestingParallelAPSPModuleFactory.NAME, apsp1);
return apspName;
}
- protected ObjectName createFixed1(ConfigTransactionJMXClient transaction,
- int numberOfThreads) throws InstanceAlreadyExistsException {
+ protected ObjectName createFixed1(final ConfigTransactionJMXClient transaction,
+ final int numberOfThreads) throws InstanceAlreadyExistsException {
ObjectName name = transaction.createModule(
getThreadPoolImplementationName(), fixed1);
try {
transaction.validateConfig();
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
try {
transaction.commit();
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
int threadCount;
public MockedThreadPoolModule(
- DynamicMBeanWithInstance dynamicMBeanWithInstance, ModuleIdentifier moduleIdentifier) {
+ final DynamicMBeanWithInstance dynamicMBeanWithInstance, final ModuleIdentifier moduleIdentifier) {
// no reconfiguration / reuse is supported
this.moduleIdentifier = moduleIdentifier;
}
}
@Override
- public void setThreadCount(int threadCount) {
+ public void setThreadCount(final int threadCount) {
this.threadCount = threadCount;
}
}
@Override
- public boolean canReuse(Module oldModule) {
+ public boolean canReuse(final Module oldModule) {
return false;
}
Closeable {
private final int threadCount;
- public MockedThreadPool(int threadCount) {
+ public MockedThreadPool(final int threadCount) {
this.threadCount = threadCount;
}
.newLinkedList();
public TestingScheduledThreadPoolImpl(
- RootRuntimeBeanRegistrator runtimeBeanRegistrator, int corePoolSize) {
+ final RootRuntimeBeanRegistrator runtimeBeanRegistrator, final int corePoolSize) {
this.runtimeBeanRegistrator = runtimeBeanRegistrator;
executor = new ScheduledThreadPoolExecutor(corePoolSize);
allExecutors.add(executor);
private RootRuntimeBeanRegistrator runtimeBeanRegistrator;
private boolean recreate;
- public TestingScheduledThreadPoolModule(ModuleIdentifier identifier,
- @Nullable AutoCloseable oldCloseable,
- @Nullable TestingScheduledThreadPoolImpl oldInstance) {
+ public TestingScheduledThreadPoolModule(final ModuleIdentifier identifier,
+ @Nullable final AutoCloseable oldCloseable,
+ @Nullable final TestingScheduledThreadPoolImpl oldInstance) {
this.identifier = identifier;
this.oldCloseable = oldCloseable;
this.oldInstance = oldInstance;
@Override
public void setRuntimeBeanRegistrator(
- RootRuntimeBeanRegistrator runtimeBeanRegistrator) {
+ final RootRuntimeBeanRegistrator runtimeBeanRegistrator) {
this.runtimeBeanRegistrator = runtimeBeanRegistrator;
}
}
@Override
- public void setThreadCount(int threadCount) {
+ public void setThreadCount(final int threadCount) {
this.threadCount = threadCount;
}
if (oldCloseable != null) {
try {
oldCloseable.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new RuntimeException(e);
}
}
}
@Override
- public void setRecreate(boolean recreate) {
+ public void setRecreate(final boolean recreate) {
this.recreate = recreate;
}
TestingScheduledThreadPoolImpl oldInstance;
try {
oldInstance = (TestingScheduledThreadPoolImpl) old.getInstance();
- } catch (ClassCastException e) {// happens after OSGi update
+ } catch (final ClassCastException e) {// happens after OSGi update
oldInstance = null;
}
try {
checkRuntimeBean(on);
fail();
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
// No-op
}
}
try {
transaction.lookupConfigBean(moduleName, instanceName);
fail();
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
}
} else {
try {
configRegistryClient.lookupConfigBean(moduleName, instanceName);
fail();
- } catch (InstanceNotFoundException e) {
+ } catch (final InstanceNotFoundException e) {
}
}
transaction.createModule(
TestingScheduledThreadPoolModuleFactory.NAME, scheduled1);
fail();
- } catch (InstanceAlreadyExistsException e) {
+ } catch (final InstanceAlreadyExistsException e) {
assertThat(
e.getMessage(),
containsString("There is an instance registered with name ModuleIdentifier{factoryName='scheduled', instanceName='scheduled1'}"));
public static final List<ThreadPoolExecutor> allExecutors = Collections
.synchronizedList(Lists.<ThreadPoolExecutor>newLinkedList());
- public TestingFixedThreadPool(int threadCount, String uniqueName) {
+ public TestingFixedThreadPool(final int threadCount, final String uniqueName) {
checkNotNull(uniqueName);
this.uniqueName = uniqueName;
executorService = (ThreadPoolExecutor) Executors
}
@Override
- public void setMaximumNumberOfThreads(int activeCount) {
+ public void setMaximumNumberOfThreads(final int activeCount) {
checkArgument(activeCount > 0);
executorService.setMaximumPoolSize(activeCount);
}
private int threadCount = 0;
private boolean triggerNewInstanceCreation;
- TestingFixedThreadPoolModule(ModuleIdentifier name,
- @Nullable AutoCloseable oldCloseable,
- @Nullable TestingFixedThreadPool oldInstance) {
+ TestingFixedThreadPoolModule(final ModuleIdentifier name,
+ @Nullable final AutoCloseable oldCloseable,
+ @Nullable final TestingFixedThreadPool oldInstance) {
this.name = name;
this.oldCloseable = oldCloseable;
this.oldInstance = oldInstance;
// attributes
@Override
- public void setThreadCount(int threadCount) {
+ public void setThreadCount(final int threadCount) {
this.threadCount = threadCount;
}
}
@Override
- public void setTriggerNewInstanceCreation(boolean triggerNewInstanceCreation) {
+ public void setTriggerNewInstanceCreation(final boolean triggerNewInstanceCreation) {
this.triggerNewInstanceCreation = triggerNewInstanceCreation;
}
if (oldCloseable != null) {
try {
oldCloseable.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new RuntimeException(e);
}
}
try {
// reconfigure existing instance
oldInstance = (TestingFixedThreadPool) old.getInstance();
- } catch (ClassCastException e) {
+ } catch (final ClassCastException e) {
// old instance will be closed, new needs to be created
oldInstance = null;
}
platformMBeanServer.invoke(fixed1names, "validate", new Object[0],
new String[0]);
fail();
- } catch (MBeanException e) {
+ } catch (final MBeanException e) {
Exception targetException = e.getTargetException();
assertNotNull(targetException);
assertEquals(ValidationException.class, targetException.getClass());
try {
transaction.validateBean(fixed1names);
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
try {
transaction.validateConfig();
fail();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
}
try {
transaction.commit();
- } catch (ValidationException e) {
+ } catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
try {
platformMBeanServer.getMBeanInfo(on);
fail();
- } catch (Exception e) {
+ } catch (final Exception e) {
assertTrue(e instanceof InstanceNotFoundException);
}
}
try {
platformMBeanServer.getMBeanInfo(transaction.getObjectName());
fail();
- }catch(InstanceNotFoundException e){
+ }catch(final InstanceNotFoundException e){
assertEquals("org.opendaylight.controller:TransactionName=ConfigTransaction-0-1,type=ConfigTransaction", e.getMessage());
}
}
try {
transaction1.commit();
fail();
- } catch (ConflictingVersionException e) {
+ } catch (final ConflictingVersionException e) {
assertEquals(
"Optimistic lock failed. Expected parent version 2, was 0",
e.getMessage());
try {
configRegistryClient.commitConfig(transaction1.getObjectName());
fail();
- } catch (ConflictingVersionException e) {
+ } catch (final ConflictingVersionException e) {
assertEquals(
"Optimistic lock failed. Expected parent version 2, was 0",
e.getMessage());