Skip to content
Permalink
Browse files

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
  • Loading branch information
mthl committed Jul 13, 2019
1 parent d0b092d commit 72aba3778ca94448abfa42f920ac2acbf5882512

This file was deleted.

This file was deleted.

@@ -45,12 +45,14 @@
*
* @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 synchronized void load(Config config, List<StartupCommand> ofbizCommands)
// 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 synchronized void load(Config config, List<StartupCommand> ofbizCommands)
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 @@ private static boolean intersects(Collection<?> a, Collection<?> b) {
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 @@ private static Container loadContainer(String configFile, ContainerConfig.Config

// 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);
}
@@ -40,7 +40,6 @@
public final String adminKey;
public final int portOffset;
public final int adminPort;
public final String containerConfig;
public final List<String> loaders;
public final String logDir;
public final boolean shutdownAfterLoad;
@@ -57,8 +56,6 @@
adminKey = getProperty(props, "ofbiz.admin.key", "NA");
portOffset = getPortOffsetValue(ofbizCommands, "0");
adminPort = getAdminPort(props, 0, portOffset);
containerConfig = getAbsolutePath(props, "ofbiz.container.config",
"framework/base/config/ofbiz-containers.xml", ofbizHome);
loaders = Arrays.asList(getProperty(props, "ofbiz.start.loaders", "").split(","));
logDir = getAbsolutePath(props, "ofbiz.log.dir", "runtime/logs", ofbizHome);
shutdownAfterLoad = getProperty(props, "ofbiz.auto.shutdown", "false").equalsIgnoreCase("true");

0 comments on commit 72aba37

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