Improved: Remove support for “ofbiz-containers.xml”

(OFBIZ-11100)

To extend the containers loaded on startup, it was possible too both
edit the “ofbiz-containers.xml” file or alternatively to define a
container in a component.

This redundancy adds extra complexity in the startup process for no
good extensibility reason. The component container loader is more
flexible since it allows developper to add new containers without
touching the framework so it is better to only rely on this option.

The component loader is now hard-coded directly in code.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mathieu Lirzin
2019-07-13 21:37:40 +00:00
parent d0b092dacb
commit 72aba3778c
5 changed files with 19 additions and 112 deletions
@@ -45,12 +45,14 @@ public interface Container {
*
* @param ofbizCommands Command-line arguments.
* @param name Unique name of the container's instance.
* @param configFile Location of the configuration file used to load this container.
* @param configFile always {@code null} but used to be the location of the global
* container configuration file which does not exist anymore
* @throws ContainerException If an error was encountered. Throwing this exception
* will halt container loading, so it should be thrown only when other containers
* might depend on this one.
*/
public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException;
void init(List<StartupCommand> ofbizCommands, String name, String configFile)
throws ContainerException;
/**
* Start the container process. This method must not block - implementations
@@ -66,14 +66,17 @@ public class ContainerLoader {
// loaders defined in startup (e.g. main, test, load-data, etc ...)
List<String> loaders = config.loaders;
// load containers defined in ofbiz-containers.xml
Debug.logInfo("[Startup] Loading containers...", module);
List<ContainerConfig.Configuration> ofbizContainerConfigs = filterContainersHavingMatchingLoaders(
loaders, retrieveOfbizContainers(config.containerConfig));
loadedContainers.addAll(loadContainersFromConfigurations(ofbizContainerConfigs, config, ofbizCommands));
// Load mandatory container providing access to containers from components.
try {
ComponentContainer cc = new ComponentContainer();
cc.init(ofbizCommands, "component-container", null);
loadedContainers.add(cc);
} catch (ContainerException e) {
throw new StartupException("Cannot init() component-container", e);
}
// load containers defined in components
Debug.logInfo("[Startup] Loading component containers...", module);
// Load containers defined in components.
Debug.logInfo("[Startup] Loading containers...", module);
List<ContainerConfig.Configuration> componentContainerConfigs = filterContainersHavingMatchingLoaders(
loaders, ComponentConfig.getAllConfigurations());
loadedContainers.addAll(loadContainersFromConfigurations(componentContainerConfigs, config, ofbizCommands));
@@ -82,15 +85,6 @@ public class ContainerLoader {
startLoadedContainers();
}
private static Collection<ContainerConfig.Configuration> retrieveOfbizContainers(String configFile)
throws StartupException {
try {
return ContainerConfig.getConfigurations(configFile);
} catch (ContainerException e) {
throw new StartupException(e);
}
}
private static List<ContainerConfig.Configuration> filterContainersHavingMatchingLoaders(List<String> loaders,
Collection<ContainerConfig.Configuration> containerConfigs) {
return containerConfigs.stream()
@@ -116,15 +110,16 @@ public class ContainerLoader {
List<Container> loadContainers = new ArrayList<>();
for (ContainerConfig.Configuration containerCfg : containerConfigs) {
Debug.logInfo("Loading container: " + containerCfg.name, module);
Container tmpContainer = loadContainer(config.containerConfig, containerCfg, ofbizCommands);
Container tmpContainer = loadContainer(containerCfg, ofbizCommands);
loadContainers.add(tmpContainer);
Debug.logInfo("Loaded container: " + containerCfg.name, module);
}
return loadContainers;
}
private static Container loadContainer(String configFile, ContainerConfig.Configuration containerCfg,
List<StartupCommand> ofbizCommands) throws StartupException {
private static Container loadContainer(ContainerConfig.Configuration containerCfg, List<StartupCommand> ofbizCommands)
throws StartupException {
// load the container class
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> containerClass;
@@ -150,7 +145,7 @@ public class ContainerLoader {
// initialize the container object
try {
containerObj.init(ofbizCommands, containerCfg.name, configFile);
containerObj.init(ofbizCommands, containerCfg.name, null);
} catch (ContainerException e) {
throw new StartupException("Cannot init() " + containerCfg.name, e);
}