From a4fe69626b027ec8d4342569ae830abcb80ea7be Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 13 Jul 2019 21:40:02 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Inline=20=E2=80=98filterContainersH?= =?UTF-8?q?avingMatchingLoaders=E2=80=99=20(OFBIZ-11100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ofbiz/base/container/ContainerLoader.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java index 79c805b715..f07d72fd7a 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java @@ -24,7 +24,6 @@ import java.util.Collections; 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 @@ public class ContainerLoader { * operate without it. */ public synchronized void load(Config config, List ofbizCommands) throws StartupException { - - // loaders defined in startup (e.g. main, test, load-data, etc ...) - List loaders = config.loaders; - // Load mandatory container providing access to containers from components. try { ComponentContainer cc = new ComponentContainer(); @@ -77,21 +72,13 @@ public class ContainerLoader { // Load containers defined in components. Debug.logInfo("[Startup] Loading containers...", module); - List componentContainerConfigs = filterContainersHavingMatchingLoaders( - loaders, ComponentConfig.getAllConfigurations()); + List componentContainerConfigs = ComponentConfig.getAllConfigurations(); loadedContainers.addAll(loadContainersFromConfigurations(componentContainerConfigs, config, ofbizCommands)); // Start all containers loaded from above steps startLoadedContainers(); } - private static List filterContainersHavingMatchingLoaders(List loaders, - Collection 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 @@ public class ContainerLoader { || !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 loadContainersFromConfigurations(List containerConfigs, Config config, List ofbizCommands) throws StartupException { List 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; }