- logger.trace("Committing transaction {}", getTransactionIdentifier());
-
- // call getInstance()
- for (Entry<ModuleIdentifier, Module> entry : dependencyResolverManager
- .getAllModules().entrySet()) {
- Module module = entry.getValue();
- ModuleIdentifier name = entry.getKey();
- try {
- logger.debug("About to commit {} in transaction {}",
- name, getTransactionIdentifier());
- AutoCloseable instance = module.getInstance();
- checkNotNull(instance, "Instance is null:{} in transaction {}", name, getTransactionIdentifier());
- } catch (Exception e) {
- logger.error("Commit failed on {} in transaction {}", name,
- getTransactionIdentifier(), e);
- internalAbort();
- throw new IllegalStateException(
- format("Error - getInstance() failed for %s in transaction %s",
- name, getTransactionIdentifier()), e);
- }
+ LOG.trace("Committing transaction {}", getTransactionIdentifier());
+
+ Map<ModuleIdentifier, Module> allModules = dependencyResolverManager.getAllModules();
+
+ // call getInstance() on all Modules from top to bottom (from source to target
+ // of the dependency relation)
+ // The source of a dependency closes itself and calls getInstance recursively on
+ // the dependencies (in case of reconfiguration)
+ // This makes close() calls from top to bottom while createInstance() calls are
+ // performed bottom to top
+ List<ModuleIdentifier> sortedModuleIdentifiers = Lists
+ .reverse(dependencyResolverManager.getSortedModuleIdentifiers());
+ for (ModuleIdentifier moduleIdentifier : sortedModuleIdentifiers) {
+ Module module = allModules.get(moduleIdentifier);
+
+ LOG.debug("About to commit {} in transaction {}", moduleIdentifier, getTransactionIdentifier());
+ AutoCloseable instance = module.getInstance();
+ Preconditions.checkNotNull(instance, "Instance is null:%s in transaction %s", moduleIdentifier,
+ getTransactionIdentifier());