Skip to content
Permalink
Browse files

Improved: Inline ‘filterContainersHavingMatchingLoaders’

(OFBIZ-11100)

The filtering of matching loaders is now done directly inside the
‘loadContainersFromConfigurations’ method.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863021 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Jul 13, 2019
1 parent 16ee111 commit a4fe69626b027ec8d4342569ae830abcb80ea7be
Showing with 16 additions and 18 deletions.
  1. +16 −18 framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java
@@ -24,7 +24,6 @@
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.ofbiz.base.component.ComponentConfig;
import org.apache.ofbiz.base.start.Config;
@@ -62,10 +61,6 @@
* operate without it.
*/
public synchronized void load(Config config, List<StartupCommand> ofbizCommands) throws StartupException {

// loaders defined in startup (e.g. main, test, load-data, etc ...)
List<String> loaders = config.loaders;

// Load mandatory container providing access to containers from components.
try {
ComponentContainer cc = new ComponentContainer();
@@ -77,21 +72,13 @@ public synchronized void load(Config config, List<StartupCommand> ofbizCommands)

// Load containers defined in components.
Debug.logInfo("[Startup] Loading containers...", module);
List<ContainerConfig.Configuration> componentContainerConfigs = filterContainersHavingMatchingLoaders(
loaders, ComponentConfig.getAllConfigurations());
List<ContainerConfig.Configuration> componentContainerConfigs = ComponentConfig.getAllConfigurations();
loadedContainers.addAll(loadContainersFromConfigurations(componentContainerConfigs, config, ofbizCommands));

// Start all containers loaded from above steps
startLoadedContainers();
}

private static List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
Collection<ContainerConfig.Configuration> containerConfigs) {
return containerConfigs.stream()
.filter(cfg -> intersects(cfg.loaders, loaders))
.collect(Collectors.toList());
}

/**
* Checks if two collections have an intersection or are both empty.
*
@@ -104,15 +91,26 @@ private static boolean intersects(Collection<?> a, Collection<?> b) {
|| !Collections.disjoint(a, b);
}

/**
* Loads the available containers which are matching the configured loaders.
*
* @param containerConfigs the list of available container configurations
* @param config the configuration defining the loaders to match
* @param ofbizCommands the parsed commands line arguments used by the containers
* @return a list of loaded containers.
* @throws StartupException when a container fails to load.
*/
private static List<Container> loadContainersFromConfigurations(List<ContainerConfig.Configuration> containerConfigs,
Config config, List<StartupCommand> ofbizCommands) throws StartupException {

List<Container> loadContainers = new ArrayList<>();
for (ContainerConfig.Configuration containerCfg : containerConfigs) {
Debug.logInfo("Loading container: " + containerCfg.name, module);
Container tmpContainer = loadContainer(containerCfg, ofbizCommands);
loadContainers.add(tmpContainer);
Debug.logInfo("Loaded container: " + containerCfg.name, module);
if (intersects(containerCfg.loaders, config.loaders)) {
Debug.logInfo("Loading container: " + containerCfg.name, module);
Container tmpContainer = loadContainer(containerCfg, ofbizCommands);
loadContainers.add(tmpContainer);
Debug.logInfo("Loaded container: " + containerCfg.name, module);
}
}
return loadContainers;
}

0 comments on commit a4fe696

Please sign in to comment.
You can’t perform that action at this time.