2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.manager.impl;
10 import com.google.common.collect.Maps;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.LinkedList;
17 import java.util.List;
19 import java.util.Map.Entry;
21 import javax.annotation.concurrent.GuardedBy;
22 import javax.annotation.concurrent.NotThreadSafe;
23 import javax.annotation.concurrent.ThreadSafe;
24 import javax.management.InstanceAlreadyExistsException;
25 import javax.management.InstanceNotFoundException;
26 import javax.management.MBeanServer;
27 import javax.management.MBeanServerFactory;
28 import javax.management.ObjectName;
29 import org.opendaylight.controller.config.api.ConflictingVersionException;
30 import org.opendaylight.controller.config.api.ModuleIdentifier;
31 import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule;
32 import org.opendaylight.controller.config.api.ValidationException;
33 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
34 import org.opendaylight.controller.config.api.jmx.CommitStatus;
35 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
36 import org.opendaylight.controller.config.manager.impl.dependencyresolver.DestroyedModule;
37 import org.opendaylight.controller.config.manager.impl.dependencyresolver.ModuleInternalTransactionalInfo;
38 import org.opendaylight.controller.config.manager.impl.dynamicmbean.DynamicReadableWrapper;
39 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HierarchicalConfigMBeanFactoriesHolder;
40 import org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleFactoriesResolver;
41 import org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator;
42 import org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator;
43 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
44 import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistrator;
45 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager;
46 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration;
47 import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider;
48 import org.opendaylight.controller.config.manager.impl.util.LookupBeansUtil;
49 import org.opendaylight.controller.config.manager.impl.util.ModuleQNameUtil;
50 import org.opendaylight.controller.config.spi.Module;
51 import org.opendaylight.controller.config.spi.ModuleFactory;
52 import org.osgi.framework.BundleContext;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
57 * Singleton that is responsible for creating and committing Config
58 * Transactions. It is registered in Platform MBean Server.
61 public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBean {
62 private static final Logger LOG = LoggerFactory.getLogger(ConfigRegistryImpl.class);
64 private final ModuleFactoriesResolver resolver;
65 private final MBeanServer configMBeanServer;
66 private final BindingContextProvider bindingContextProvider;
69 private long version = 0;
71 private long versionCounter = 0;
74 * Contains current configuration in form of {moduleName:{instanceName,read
75 * only module}} for copying state to new transaction. Each running module
76 * is present just once, no matter how many interfaces it exposes.
79 private final ConfigHolder currentConfig = new ConfigHolder();
82 * Will return true unless there was a transaction that succeeded during
83 * validation but failed in second phase of commit. In this case the server
84 * is unstable and its state is undefined.
87 private boolean isHealthy = true;
90 * Holds Map<transactionName, transactionController> and purges it each time
91 * its content is requested.
94 private final TransactionsHolder transactionsHolder = new TransactionsHolder();
96 private final BaseJMXRegistrator baseJMXRegistrator;
98 private final BeanToOsgiServiceManager beanToOsgiServiceManager;
100 // internal jmx server for read only beans
101 private final MBeanServer registryMBeanServer;
102 // internal jmx server shared by all transactions
103 private final MBeanServer transactionsMBeanServer;
105 // Used for finding new factory instances for default module functionality
107 private List<ModuleFactory> lastListOfFactories = Collections.emptyList();
109 @GuardedBy("this") // switched in every 2ndPC
110 private CloseableServiceReferenceReadableRegistry readableSRRegistry = ServiceReferenceRegistryImpl.createInitialSRLookupRegistry();
113 public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
114 MBeanServer configMBeanServer, BindingContextProvider bindingContextProvider) {
115 this(resolver, configMBeanServer,
116 new BaseJMXRegistrator(configMBeanServer), bindingContextProvider);
120 public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
121 MBeanServer configMBeanServer,
122 BaseJMXRegistrator baseJMXRegistrator, BindingContextProvider bindingContextProvider) {
123 this.resolver = resolver;
124 this.beanToOsgiServiceManager = new BeanToOsgiServiceManager();
125 this.configMBeanServer = configMBeanServer;
126 this.baseJMXRegistrator = baseJMXRegistrator;
127 this.bindingContextProvider = bindingContextProvider;
128 this.registryMBeanServer = MBeanServerFactory
129 .createMBeanServer("ConfigRegistry" + configMBeanServer.getDefaultDomain());
130 this.transactionsMBeanServer = MBeanServerFactory
131 .createMBeanServer("ConfigTransactions" + configMBeanServer.getDefaultDomain());
135 * Create new {@link ConfigTransactionControllerImpl }
138 public synchronized ObjectName beginConfig() {
139 return beginConfig(false);
143 * @param blankTransaction true if this transaction is created automatically by
144 * org.opendaylight.controller.config.manager.impl.osgi.BlankTransactionServiceTracker
146 public synchronized ObjectName beginConfig(boolean blankTransaction) {
147 return beginConfigInternal(blankTransaction).getControllerObjectName();
150 private synchronized ConfigTransactionControllerInternal beginConfigInternal(boolean blankTransaction) {
152 final String transactionName = "ConfigTransaction-" + version + "-" + versionCounter;
154 TransactionJMXRegistratorFactory factory = new TransactionJMXRegistratorFactory() {
156 public TransactionJMXRegistrator create() {
157 return baseJMXRegistrator.createTransactionJMXRegistrator(transactionName);
161 Map<String, Map.Entry<ModuleFactory, BundleContext>> allCurrentFactories = new HashMap<>(
162 resolver.getAllFactories());
164 // add all factories that disappeared from SR but are still committed
165 for (ModuleInternalInfo moduleInternalInfo : currentConfig.getEntries()) {
166 String name = moduleInternalInfo.getModuleFactory().getImplementationName();
167 if (allCurrentFactories.containsKey(name) == false) {
168 LOG.trace("Factory {} not found in SR, using reference from previous commit", name);
169 allCurrentFactories.put(name,
170 Maps.immutableEntry(moduleInternalInfo.getModuleFactory(), moduleInternalInfo.getBundleContext()));
173 allCurrentFactories = Collections.unmodifiableMap(allCurrentFactories);
175 // closed by transaction controller
176 ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry(new TransactionIdentifier(
177 transactionName), factory, allCurrentFactories);
178 SearchableServiceReferenceWritableRegistry writableRegistry = ServiceReferenceRegistryImpl.createSRWritableRegistry(
179 readableSRRegistry, txLookupRegistry, allCurrentFactories);
181 ConfigTransactionControllerInternal transactionController = new ConfigTransactionControllerImpl(
182 txLookupRegistry, version, bindingContextProvider,
183 versionCounter, allCurrentFactories, transactionsMBeanServer,
184 configMBeanServer, blankTransaction, writableRegistry);
186 txLookupRegistry.registerMBean(transactionController, transactionController.getControllerObjectName());
187 } catch (InstanceAlreadyExistsException e) {
188 throw new IllegalStateException(e);
190 transactionController.copyExistingModulesAndProcessFactoryDiff(currentConfig.getEntries(), lastListOfFactories);
191 transactionsHolder.add(transactionName, transactionController, txLookupRegistry);
192 return transactionController;
199 public synchronized CommitStatus commitConfig(ObjectName transactionControllerON)
200 throws ConflictingVersionException, ValidationException {
201 final String transactionName = ObjectNameUtil
202 .getTransactionName(transactionControllerON);
203 LOG.trace("About to commit {}. Current parentVersion: {}, versionCounter {}", transactionName, version, versionCounter);
205 // find ConfigTransactionController
206 Map<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> transactions = transactionsHolder.getCurrentTransactions();
207 Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry> configTransactionControllerEntry = transactions.get(transactionName);
208 if (configTransactionControllerEntry == null) {
209 throw new IllegalArgumentException(String.format(
210 "Transaction with name '%s' not found", transactionName));
212 ConfigTransactionControllerInternal configTransactionController = configTransactionControllerEntry.getKey();
213 // check optimistic lock
214 if (version != configTransactionController.getParentVersion()) {
215 throw new ConflictingVersionException(
217 "Optimistic lock failed. Expected parent version %d, was %d",
219 configTransactionController.getParentVersion()));
221 // optimistic lock ok
223 CommitInfo commitInfo = configTransactionController.validateBeforeCommitAndLockTransaction();
224 lastListOfFactories = Collections.unmodifiableList(configTransactionController.getCurrentlyRegisteredFactories());
225 // non recoverable from here:
227 return secondPhaseCommit(configTransactionController, commitInfo, configTransactionControllerEntry.getValue());
228 } catch (Error | RuntimeException t) { // some libs throw Errors: e.g.
229 // javax.xml.ws.spi.FactoryFinder$ConfigurationError
231 LOG.error("Configuration Transaction failed on 2PC, server is unhealthy", t);
232 if (t instanceof RuntimeException) {
233 throw (RuntimeException) t;
240 private CommitStatus secondPhaseCommit(ConfigTransactionControllerInternal configTransactionController,
241 CommitInfo commitInfo, ConfigTransactionLookupRegistry txLookupRegistry) {
243 // close instances which were destroyed by the user, including
244 // (hopefully) runtime beans
245 for (DestroyedModule toBeDestroyed : commitInfo
246 .getDestroyedFromPreviousTransactions()) {
247 toBeDestroyed.close(); // closes instance (which should close
248 // runtime jmx registrator),
249 // also closes osgi registration and ModuleJMXRegistrator
251 currentConfig.remove(toBeDestroyed.getIdentifier());
254 // set RuntimeBeanRegistrators on beans implementing
255 // RuntimeBeanRegistratorAwareModule
256 Map<ModuleIdentifier, RootRuntimeBeanRegistratorImpl> runtimeRegistrators = new HashMap<>();
257 for (ModuleInternalTransactionalInfo entry : commitInfo.getCommitted()
259 // set runtime jmx registrator if required
260 Module module = entry.getProxiedModule();
261 RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = null;
263 if (module instanceof RuntimeBeanRegistratorAwareModule) {
265 if(entry.hasOldModule()) {
267 if(module.canReuse(entry.getOldInternalInfo().getReadableModule().getModule())) {
268 runtimeBeanRegistrator = entry.getOldInternalInfo().getRuntimeBeanRegistrator();
269 ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
271 runtimeBeanRegistrator = baseJMXRegistrator.createRuntimeBeanRegistrator(entry.getIdentifier());
272 entry.getOldInternalInfo().getRuntimeBeanRegistrator().close();
273 ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
276 runtimeBeanRegistrator = baseJMXRegistrator.createRuntimeBeanRegistrator(entry.getIdentifier());
277 ((RuntimeBeanRegistratorAwareModule) module).setRuntimeBeanRegistrator(runtimeBeanRegistrator);
280 // save it to info so it is accessible afterwards
281 if(runtimeBeanRegistrator != null) {
282 runtimeRegistrators.put(entry.getIdentifier(), runtimeBeanRegistrator);
286 // can register runtime beans
287 List<ModuleIdentifier> orderedModuleIdentifiers = configTransactionController.secondPhaseCommit();
288 txLookupRegistry.close();
289 configTransactionController.close();
291 // copy configuration to read only mode
292 List<ObjectName> newInstances = new LinkedList<>();
293 List<ObjectName> reusedInstances = new LinkedList<>();
294 List<ObjectName> recreatedInstances = new LinkedList<>();
296 Map<Module, ModuleInternalInfo> newConfigEntries = new HashMap<>();
299 for (ModuleIdentifier moduleIdentifier : orderedModuleIdentifiers) {
300 LOG.trace("Registering {}", moduleIdentifier);
301 ModuleInternalTransactionalInfo entry = commitInfo.getCommitted()
302 .get(moduleIdentifier);
304 throw new NullPointerException("Module not found "
308 ObjectName primaryReadOnlyON = ObjectNameUtil
309 .createReadOnlyModuleON(moduleIdentifier);
311 // determine if current instance was recreated or reused or is new
313 // rules for closing resources:
314 // osgi registration - will be reused if possible.
315 // module jmx registration - will be (re)created every time, needs
317 // runtime jmx registration - should be taken care of by module
319 // instance - is closed only if it was destroyed
320 ModuleJMXRegistrator newModuleJMXRegistrator = baseJMXRegistrator
321 .createModuleJMXRegistrator();
323 OsgiRegistration osgiRegistration = null;
324 AutoCloseable instance = entry.getProxiedModule().getInstance();
325 if (entry.hasOldModule()) {
326 ModuleInternalInfo oldInternalInfo = entry.getOldInternalInfo();
327 DynamicReadableWrapper oldReadableConfigBean = oldInternalInfo.getReadableModule();
328 currentConfig.remove(entry.getIdentifier());
330 // test if old instance == new instance
331 if (oldReadableConfigBean.getInstance().equals(instance)) {
332 // reused old instance:
333 // wrap in readable dynamic mbean
334 reusedInstances.add(primaryReadOnlyON);
335 osgiRegistration = oldInternalInfo.getOsgiRegistration();
337 // recreated instance:
338 // it is responsibility of module to call the old instance -
339 // we just need to unregister configbean
340 recreatedInstances.add(primaryReadOnlyON);
342 // close old osgi registration
343 oldInternalInfo.getOsgiRegistration().close();
346 // close old module jmx registrator
347 oldInternalInfo.getModuleJMXRegistrator().close();
349 // We no longer need old internal info. Clear it out, so we do not create a serial leak evidenced
350 // by BUG-4514. The reason is that modules retain their resolver, which retains modules. If we retain
351 // the old module, we would have the complete reconfiguration history held in heap for no good reason.
352 entry.clearOldInternalInfo();
355 // wrap in readable dynamic mbean
356 newInstances.add(primaryReadOnlyON);
358 Module realModule = entry.getRealModule();
360 DynamicReadableWrapper newReadableConfigBean = new DynamicReadableWrapper(
361 realModule, instance, moduleIdentifier,
362 registryMBeanServer, configMBeanServer);
366 newModuleJMXRegistrator.registerMBean(newReadableConfigBean, primaryReadOnlyON);
367 } catch (InstanceAlreadyExistsException e) {
368 throw new IllegalStateException("Possible code error, already registered:" + primaryReadOnlyON,e);
371 // register services to OSGi
372 Map<ServiceInterfaceAnnotation, String /* service ref name */> annotationMapping = configTransactionController.getWritableRegistry().findServiceInterfaces(moduleIdentifier);
373 BundleContext bc = configTransactionController.getModuleFactoryBundleContext(
374 entry.getModuleFactory().getImplementationName());
375 if (osgiRegistration == null) {
376 osgiRegistration = beanToOsgiServiceManager.registerToOsgi(
377 newReadableConfigBean.getInstance(), moduleIdentifier, bc, annotationMapping);
379 osgiRegistration.updateRegistrations(annotationMapping, bc, instance);
382 RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator = runtimeRegistrators
383 .get(entry.getIdentifier());
384 ModuleInternalInfo newInfo = new ModuleInternalInfo(
385 entry.getIdentifier(), newReadableConfigBean, osgiRegistration,
386 runtimeBeanRegistrator, newModuleJMXRegistrator,
387 orderingIdx, entry.isDefaultBean(), entry.getModuleFactory(), entry.getBundleContext());
389 newConfigEntries.put(realModule, newInfo);
392 currentConfig.addAll(newConfigEntries.values());
395 version = configTransactionController.getVersion();
397 // switch readable Service Reference Registry
398 this.readableSRRegistry.close();
399 this.readableSRRegistry = ServiceReferenceRegistryImpl.createSRReadableRegistry(
400 configTransactionController.getWritableRegistry(), this, baseJMXRegistrator);
402 return new CommitStatus(newInstances, reusedInstances,
410 public synchronized List<ObjectName> getOpenConfigs() {
411 Map<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> transactions = transactionsHolder
412 .getCurrentTransactions();
413 List<ObjectName> result = new ArrayList<>(transactions.size());
414 for (Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry> configTransactionControllerEntry : transactions
416 result.add(configTransactionControllerEntry.getKey().getControllerObjectName());
422 * Abort open transactions and unregister read only modules. Since this
423 * class is not responsible for registering itself under
424 * {@link org.opendaylight.controller.config.api.ConfigRegistry#OBJECT_NAME}, it will not unregister itself
428 public synchronized void close() {
429 // abort transactions
430 Map<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> transactions = transactionsHolder
431 .getCurrentTransactions();
432 for (Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry> configTransactionControllerEntry : transactions
435 ConfigTransactionControllerInternal configTransactionController = configTransactionControllerEntry.getKey();
437 configTransactionControllerEntry.getValue().close();
438 configTransactionController.abortConfig();
439 } catch (RuntimeException e) {
440 LOG.warn("Ignoring exception while aborting {}",
441 configTransactionController, e);
445 // destroy all live objects one after another in order of the dependency hierarchy, from top to bottom
446 List<DestroyedModule> destroyedModules = currentConfig
447 .getModulesToBeDestroyed();
448 for (DestroyedModule destroyedModule : destroyedModules) {
449 destroyedModule.close();
451 // unregister MBeans that failed to unregister properly
452 baseJMXRegistrator.close();
453 // remove jmx servers
454 MBeanServerFactory.releaseMBeanServer(registryMBeanServer);
455 MBeanServerFactory.releaseMBeanServer(transactionsMBeanServer);
463 public long getVersion() {
471 public Set<String> getAvailableModuleNames() {
472 return new HierarchicalConfigMBeanFactoriesHolder(
473 resolver.getAllFactories()).getModuleNames();
480 public boolean isHealthy() {
490 public Set<ObjectName> lookupConfigBeans() {
491 return lookupConfigBeans("*", "*");
498 public Set<ObjectName> lookupConfigBeans(String moduleName) {
499 return lookupConfigBeans(moduleName, "*");
506 public ObjectName lookupConfigBean(String moduleName, String instanceName)
507 throws InstanceNotFoundException {
508 return LookupBeansUtil.lookupConfigBean(this, moduleName, instanceName);
515 public Set<ObjectName> lookupConfigBeans(String moduleName,
516 String instanceName) {
517 ObjectName namePattern = ObjectNameUtil.createModulePattern(moduleName,
519 return baseJMXRegistrator.queryNames(namePattern, null);
526 public Set<ObjectName> lookupRuntimeBeans() {
527 return lookupRuntimeBeans("*", "*");
534 public Set<ObjectName> lookupRuntimeBeans(String moduleName,
535 String instanceName) {
536 String finalModuleName = moduleName == null ? "*" : moduleName;
537 String finalInstanceName = instanceName == null ? "*" : instanceName;
538 ObjectName namePattern = ObjectNameUtil.createRuntimeBeanPattern(
539 finalModuleName, finalInstanceName);
540 return baseJMXRegistrator.queryNames(namePattern, null);
544 public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
545 ObjectNameUtil.checkDomain(objectName);
546 ObjectNameUtil.checkType(objectName, ObjectNameUtil.TYPE_MODULE);
547 String transactionName = ObjectNameUtil.getTransactionName(objectName);
548 if (transactionName != null) {
549 throw new IllegalArgumentException("Transaction attribute not supported in registry, wrong ObjectName: " + objectName);
551 // make sure exactly one match is found:
552 LookupBeansUtil.lookupConfigBean(this, ObjectNameUtil.getFactoryName(objectName), ObjectNameUtil.getInstanceName(objectName));
555 // service reference functionality:
557 public synchronized ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) {
558 return readableSRRegistry.lookupConfigBeanByServiceInterfaceName(serviceInterfaceQName, refName);
562 public synchronized Map<String, Map<String, ObjectName>> getServiceMapping() {
563 return readableSRRegistry.getServiceMapping();
567 public synchronized Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
568 return readableSRRegistry.lookupServiceReferencesByServiceInterfaceName(serviceInterfaceQName);
572 public synchronized Set<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
573 return readableSRRegistry.lookupServiceInterfaceNames(objectName);
577 public synchronized String getServiceInterfaceName(String namespace, String localName) {
578 return readableSRRegistry.getServiceInterfaceName(namespace, localName);
582 public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException {
583 readableSRRegistry.checkServiceReferenceExists(objectName);
587 public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
588 return readableSRRegistry.getServiceReference(serviceInterfaceQName, refName);
592 public Set<String> getAvailableModuleFactoryQNames() {
593 return ModuleQNameUtil.getQNames(resolver.getAllFactories());
597 public String toString() {
598 return "ConfigRegistryImpl{" +
599 "versionCounter=" + versionCounter +
600 ", version=" + version +
606 * Holds currently running modules
610 private final Map<ModuleIdentifier, ModuleInternalInfo> currentConfig = new HashMap<>();
613 * Add all modules to the internal map. Also add service instance to OSGi
616 public void addAll(Collection<ModuleInternalInfo> configInfos) {
617 if (!currentConfig.isEmpty()) {
618 throw new IllegalStateException(
619 "Error - some config entries were not removed: "
622 for (ModuleInternalInfo configInfo : configInfos) {
627 private void add(ModuleInternalInfo configInfo) {
628 ModuleInternalInfo oldValue = currentConfig.put(configInfo.getIdentifier(),
630 if (oldValue != null) {
631 throw new IllegalStateException(
632 "Cannot overwrite module with same name:"
633 + configInfo.getIdentifier() + ":" + configInfo);
638 * Remove entry from current config.
640 public void remove(ModuleIdentifier name) {
641 ModuleInternalInfo removed = currentConfig.remove(name);
642 if (removed == null) {
643 throw new IllegalStateException(
644 "Cannot remove from ConfigHolder - name not found:" + name);
648 public Collection<ModuleInternalInfo> getEntries() {
649 return currentConfig.values();
652 public List<DestroyedModule> getModulesToBeDestroyed() {
653 List<DestroyedModule> result = new ArrayList<>();
654 for (ModuleInternalInfo moduleInternalInfo : getEntries()) {
655 result.add(moduleInternalInfo.toDestroyedModule());
657 Collections.sort(result);
665 * Holds Map<transactionName, transactionController> and purges it each time its
666 * content is requested.
669 class TransactionsHolder {
671 * This map keeps transaction names and
672 * {@link ConfigTransactionControllerInternal} instances, because platform
673 * MBeanServer transforms mbeans into another representation. Map is cleaned
674 * every time current transactions are requested.
676 @GuardedBy("ConfigRegistryImpl.this")
677 private final Map<String /* transactionName */,
678 Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> transactions = new HashMap<>();
681 * Can only be called from within synchronized method.
683 public void add(String transactionName,
684 ConfigTransactionControllerInternal transactionController, ConfigTransactionLookupRegistry txLookupRegistry) {
685 Object oldValue = transactions.put(transactionName,
686 Maps.immutableEntry(transactionController, txLookupRegistry));
687 if (oldValue != null) {
688 throw new IllegalStateException(
689 "Error: two transactions with same name");
694 * Purges closed transactions from transactions map. Can only be called from
695 * within synchronized method. Calling this method more than once within the
696 * method can modify the resulting map that was obtained in previous calls.
698 * @return current view on transactions map.
700 public Map<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> getCurrentTransactions() {
701 // first, remove closed transaction
702 for (Iterator<Entry<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>>> it = transactions
703 .entrySet().iterator(); it.hasNext(); ) {
704 Entry<String, Entry<ConfigTransactionControllerInternal, ConfigTransactionLookupRegistry>> entry = it
706 if (entry.getValue().getKey().isClosed()) {
710 return Collections.unmodifiableMap(transactions);