diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java index 40e50c3d9d..377966ca3f 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java @@ -33,7 +33,7 @@ import java.util.Map; import java.util.TreeMap; import org.apache.ofbiz.base.container.ContainerConfig; -import org.apache.ofbiz.base.container.ContainerConfig.Container; +import org.apache.ofbiz.base.container.ContainerConfig.Configuration; import org.apache.ofbiz.base.container.ContainerException; import org.apache.ofbiz.base.location.FlexibleLocation; import org.apache.ofbiz.base.util.Assert; @@ -85,18 +85,18 @@ public final class ComponentConfig { return componentConfigCache.values(); } - public static List getAllContainers() { - return getAllContainers(null); + public static List getAllConfigurations() { + return getAllConfigurations(null); } - public static List getAllContainers(String componentName) { - List containers = new ArrayList(); + public static List getAllConfigurations(String componentName) { + List configurations = new ArrayList(); for (ComponentConfig cc : getAllComponents()) { if (componentName == null || componentName.equals(cc.getComponentName())) { - containers.addAll(cc.getContainers()); + configurations.addAll(cc.getConfigurations()); } } - return containers; + return configurations; } public static List getAllEntityResourceInfos(String type) { @@ -346,7 +346,7 @@ public final class ComponentConfig { private final List testSuiteInfos; private final List keystoreInfos; private final List webappInfos; - private final List containers; + private final List configurations; private ComponentConfig(String globalName, String rootLocation) throws ComponentException { if (!rootLocation.endsWith("/")) { @@ -463,16 +463,16 @@ public final class ComponentConfig { } else { this.webappInfos = Collections.emptyList(); } - // containers + // configurations try { - Collection containers = ContainerConfig.getContainers(xmlUrl); - if (!containers.isEmpty()) { - this.containers = Collections.unmodifiableList(new ArrayList(containers)); + Collection configurations = ContainerConfig.getConfigurations(xmlUrl); + if (!configurations.isEmpty()) { + this.configurations = Collections.unmodifiableList(new ArrayList(configurations)); } else { - this.containers = Collections.emptyList(); + this.configurations = Collections.emptyList(); } } catch (ContainerException ce) { - throw new ComponentException("Error reading containers for component: " + this.globalName, ce); + throw new ComponentException("Error reading container configurations for component: " + this.globalName, ce); } if (Debug.verboseOn()) Debug.logVerbose("Read component config : [" + rootLocation + "]", module); @@ -490,8 +490,8 @@ public final class ComponentConfig { return this.componentName; } - public List getContainers() { - return this.containers; + public List getConfigurations() { + return this.configurations; } public List getEntityResourceInfos() { diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java index 80065f0d0a..be38e60c3e 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java @@ -31,6 +31,7 @@ import org.apache.ofbiz.base.component.ComponentException; import org.apache.ofbiz.base.component.ComponentLoaderConfig; import org.apache.ofbiz.base.start.Classpath; import org.apache.ofbiz.base.start.NativeLibClassLoader; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.FileUtil; import org.apache.ofbiz.base.util.UtilValidate; @@ -52,7 +53,7 @@ public class ComponentContainer implements Container { private final AtomicBoolean loaded = new AtomicBoolean(false); @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { if (!loaded.compareAndSet(false, true)) { throw new ContainerException("Components already loaded, cannot start"); } @@ -60,7 +61,7 @@ public class ComponentContainer implements Container { this.configFileLocation = configFile; // get the config for this container - ContainerConfig.Container cc = ContainerConfig.getContainer(name, configFileLocation); + ContainerConfig.Configuration cc = ContainerConfig.getConfiguration(name, configFileLocation); // check for an override loader config String loaderConfig = null; diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java index d5d18b6bd9..43ea708cec 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java @@ -18,6 +18,10 @@ *******************************************************************************/ package org.apache.ofbiz.base.container; +import java.util.List; + +import org.apache.ofbiz.base.start.StartupCommand; + /** * An OFBiz container. A container can be thought of as a background process. * @@ -39,14 +43,14 @@ public interface Container { /** Initialize the container. This method must not block - implementations * should initialize internal structures and then return. * - * @param args Command-line arguments. + * @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. * @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(String[] args, String name, String configFile) throws ContainerException; + public void init(List ofbizCommands, String name, String configFile) throws ContainerException; /** * Start the container process. This method must not block - implementations diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java index d1517af661..707934618b 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerConfig.java @@ -29,7 +29,6 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; -import org.apache.ofbiz.base.lang.LockedBy; import org.apache.ofbiz.base.util.StringUtil; import org.apache.ofbiz.base.util.UtilURL; import org.apache.ofbiz.base.util.UtilValidate; @@ -44,24 +43,25 @@ import org.xml.sax.SAXException; */ public class ContainerConfig { + private ContainerConfig() {} + public static final String module = ContainerConfig.class.getName(); - @LockedBy("ContainerConfig.class") - private static Map containers = new LinkedHashMap(); + private static Map configurations = new LinkedHashMap(); - public static Container getContainer(String containerName, String configFile) throws ContainerException { - Container container = containers.get(containerName); - if (container == null) { - getContainers(configFile); - container = containers.get(containerName); + public static Configuration getConfiguration(String containerName, String configFile) throws ContainerException { + Configuration configuration = configurations.get(containerName); + if (configuration == null) { + getConfigurations(configFile); + configuration = configurations.get(containerName); } - if (container == null) { + if (configuration == null) { throw new ContainerException("No container found with the name : " + containerName); } - return container; + return configuration; } - public static Collection getContainers(String configFile) throws ContainerException { + public static Collection getConfigurations(String configFile) throws ContainerException { if (UtilValidate.isEmpty(configFile)) { throw new ContainerException("configFile argument cannot be null or empty"); } @@ -69,24 +69,24 @@ public class ContainerConfig { if (xmlUrl == null) { throw new ContainerException("Could not find container config file " + configFile); } - return getContainers(xmlUrl); + return getConfigurations(xmlUrl); } - public static Collection getContainers(URL xmlUrl) throws ContainerException { + public static Collection getConfigurations(URL xmlUrl) throws ContainerException { if (xmlUrl == null) { throw new ContainerException("xmlUrl argument cannot be null"); } - Collection result = getContainerPropsFromXml(xmlUrl); + Collection result = getConfigurationPropsFromXml(xmlUrl); synchronized (ContainerConfig.class) { - for (Container container : result) { - containers.put(container.name, container); + for (Configuration container : result) { + configurations.put(container.name, container); } } return result; } - public static String getPropertyValue(ContainerConfig.Container parentProp, String name, String defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static String getPropertyValue(ContainerConfig.Configuration parentProp, String name, String defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -94,8 +94,8 @@ public class ContainerConfig { } } - public static int getPropertyValue(ContainerConfig.Container parentProp, String name, int defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static int getPropertyValue(ContainerConfig.Configuration parentProp, String name, int defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -109,8 +109,8 @@ public class ContainerConfig { } } - public static boolean getPropertyValue(ContainerConfig.Container parentProp, String name, boolean defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static boolean getPropertyValue(ContainerConfig.Configuration parentProp, String name, boolean defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -118,8 +118,8 @@ public class ContainerConfig { } } - public static String getPropertyValue(ContainerConfig.Container.Property parentProp, String name, String defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static String getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, String defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -127,8 +127,8 @@ public class ContainerConfig { } } - public static int getPropertyValue(ContainerConfig.Container.Property parentProp, String name, int defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static int getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, int defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -142,8 +142,8 @@ public class ContainerConfig { } } - public static boolean getPropertyValue(ContainerConfig.Container.Property parentProp, String name, boolean defaultValue) { - ContainerConfig.Container.Property prop = parentProp.getProperty(name); + public static boolean getPropertyValue(ContainerConfig.Configuration.Property parentProp, String name, boolean defaultValue) { + ContainerConfig.Configuration.Property prop = parentProp.getProperty(name); if (prop == null || UtilValidate.isEmpty(prop.value)) { return defaultValue; } else { @@ -151,9 +151,7 @@ public class ContainerConfig { } } - private ContainerConfig() {} - - private static Collection getContainerPropsFromXml(URL xmlUrl) throws ContainerException { + private static Collection getConfigurationPropsFromXml(URL xmlUrl) throws ContainerException { Document containerDocument = null; try { containerDocument = UtilXml.readXmlDocument(xmlUrl, true); @@ -165,20 +163,20 @@ public class ContainerConfig { throw new ContainerException("Error reading the container config file: " + xmlUrl, e); } Element root = containerDocument.getDocumentElement(); - List result = new ArrayList(); + List result = new ArrayList(); for (Element curElement: UtilXml.childElementList(root, "container")) { - result.add(new Container(curElement)); + result.add(new Configuration(curElement)); } return result; } - public static class Container { + public static class Configuration { public final String name; public final String className; public final List loaders; public final Map properties; - public Container(Element element) { + public Configuration(Element element) { this.name = element.getAttribute("name"); this.className = element.getAttribute("class"); this.loaders = StringUtil.split(element.getAttribute("loaders"), ","); 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 4410870d33..0a354e21fc 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 @@ -18,23 +18,23 @@ *******************************************************************************/ package org.apache.ofbiz.base.container; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.net.URL; +import java.util.ArrayList; import java.util.Collection; -import java.util.Enumeration; import java.util.LinkedList; import java.util.List; -import java.util.Map; +import java.util.stream.Collectors; import org.apache.ofbiz.base.component.ComponentConfig; import org.apache.ofbiz.base.start.Config; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.start.StartupException; import org.apache.ofbiz.base.start.StartupLoader; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.StringUtil; import org.apache.ofbiz.base.util.UtilValidate; +import edu.emory.mathcs.backport.java.util.Collections; + /** * An object that loads containers (background processes). * @@ -47,115 +47,70 @@ public class ContainerLoader implements StartupLoader { public static final String module = ContainerLoader.class.getName(); - private String configFile = null; private final List loadedContainers = new LinkedList(); - private boolean unloading = false; - private boolean loaded = false; /** * @see org.apache.ofbiz.base.start.StartupLoader#load(Config, String[]) */ @Override - public synchronized void load(Config config, String args[]) throws StartupException { - if (this.loaded || this.unloading) { - return; - } - this.loadedContainers.clear(); - // get this loader's configuration file - this.configFile = config.containerConfig; + public synchronized void load(Config config, List ofbizCommands) throws StartupException { - List loaders = null; - for (Map loaderMap: config.loaders) { - if (module.equals(loaderMap.get("class"))) { - loaders = StringUtil.split((String)loaderMap.get("profiles"), ","); - } - } + // loaders defined in startup (e.g. main, test, load-data, etc ...) + List loaders = StringUtil.split((String) config.loader.get("profiles"), ","); - Debug.logInfo("[Startup] Loading containers from " + configFile + " for loaders " + loaders, module); - Collection containers = null; - try { - containers = ContainerConfig.getContainers(configFile); - } catch (ContainerException e) { - throw new StartupException(e); - } - for (ContainerConfig.Container containerCfg : containers) { - if (this.unloading) { - return; - } - boolean matchingLoaderFound = false; - if (UtilValidate.isEmpty(containerCfg.loaders) && UtilValidate.isEmpty(loaders)) { - matchingLoaderFound = true; - } else { - for (String loader: loaders) { - if (UtilValidate.isEmpty(containerCfg.loaders) || containerCfg.loaders.contains(loader)) { - matchingLoaderFound = true; - break; - } - } - } - if (matchingLoaderFound) { - Debug.logInfo("Loading container: " + containerCfg.name, module); - Container tmpContainer = loadContainer(containerCfg, args); - this.loadedContainers.add(tmpContainer); - Debug.logInfo("Loaded container: " + containerCfg.name, module); - } - } - if (this.unloading) { - return; - } + // load containers defined in ofbiz-containers.xml + Debug.logInfo("[Startup] Loading containers...", module); + List ofbizContainerConfigs = filterContainersHavingMatchingLoaders( + loaders, retrieveOfbizContainers(config.containerConfig)); + loadedContainers.addAll(loadContainersFromConfigurations(ofbizContainerConfigs, config, ofbizCommands)); - List containersDefinedInComponents = ComponentConfig.getAllContainers(); - for (ContainerConfig.Container containerCfg: containersDefinedInComponents) { - boolean matchingLoaderFound = false; - if (UtilValidate.isEmpty(containerCfg.loaders) && UtilValidate.isEmpty(loaders)) { - matchingLoaderFound = true; - } else { - for (String loader: loaders) { - if (UtilValidate.isEmpty(containerCfg.loaders) || containerCfg.loaders.contains(loader)) { - matchingLoaderFound = true; - break; - } - } - } - if (matchingLoaderFound) { - Debug.logInfo("Loading component's container: " + containerCfg.name, module); - Container tmpContainer = loadContainer(containerCfg, args); - this.loadedContainers.add(tmpContainer); - Debug.logInfo("Loaded component's container: " + containerCfg.name, module); - } - } - // Get hot-deploy container configuration files - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - Enumeration resources; - try { - resources = loader.getResources("hot-deploy-containers.xml"); - while (resources.hasMoreElements() && !this.unloading) { - URL xmlUrl = resources.nextElement(); - Debug.logInfo("Loading hot-deploy containers from " + xmlUrl, module); - Collection hotDeployContainers = ContainerConfig.getContainers(xmlUrl); - for (ContainerConfig.Container containerCfg : hotDeployContainers) { - if (this.unloading) { - return; - } - Container tmpContainer = loadContainer(containerCfg, args); - this.loadedContainers.add(tmpContainer); - } - } - } catch (Exception e) { - Debug.logError(e, "Could not load hot-deploy-containers.xml", module); - throw new StartupException(e); - } - loaded = true; + // load containers defined in components + Debug.logInfo("[Startup] Loading component containers...", module); + List componentContainerConfigs = filterContainersHavingMatchingLoaders( + loaders, ComponentConfig.getAllConfigurations()); + loadedContainers.addAll(loadContainersFromConfigurations(componentContainerConfigs, config, ofbizCommands)); + + // Start all containers loaded from above steps + startLoadedContainers(); } - private Container loadContainer(ContainerConfig.Container containerCfg, String[] args) throws StartupException { + private Collection retrieveOfbizContainers(String configFile) throws StartupException { + try { + return ContainerConfig.getConfigurations(configFile); + } catch (ContainerException e) { + throw new StartupException(e); + } + } + + private List filterContainersHavingMatchingLoaders(List loaders, + Collection containerConfigs) throws StartupException { + return containerConfigs.stream() + .filter(containerCfg -> + UtilValidate.isEmpty(containerCfg.loaders) && + UtilValidate.isEmpty(loaders) || + containerCfg.loaders.stream().anyMatch(loader -> loaders.contains(loader))) + .collect(Collectors.toList()); + } + + private 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(config.containerConfig, containerCfg, ofbizCommands); + loadContainers.add(tmpContainer); + Debug.logInfo("Loaded container: " + containerCfg.name, module); + } + return loadContainers; + } + + private Container loadContainer(String configFile, + ContainerConfig.Configuration containerCfg, + List ofbizCommands) throws StartupException { // load the container class ClassLoader loader = Thread.currentThread().getContextClassLoader(); - if (loader == null) { - Debug.logWarning("Unable to get context classloader; using system", module); - loader = ClassLoader.getSystemClassLoader(); - } - Class containerClass = null; + Class containerClass; try { containerClass = loader.loadClass(containerCfg.className); } catch (ClassNotFoundException e) { @@ -166,79 +121,34 @@ public class ContainerLoader implements StartupLoader { } // create a new instance of the container object - Container containerObj = null; + Container containerObj; try { containerObj = (Container) containerClass.newInstance(); - } catch (InstantiationException e) { - throw new StartupException("Cannot create " + containerCfg.name, e); - } catch (IllegalAccessException e) { - throw new StartupException("Cannot create " + containerCfg.name, e); - } catch (ClassCastException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new StartupException("Cannot create " + containerCfg.name, e); } - if (containerObj == null) { throw new StartupException("Unable to create instance of component container"); } // initialize the container object try { - containerObj.init(args, containerCfg.name, configFile); + containerObj.init(ofbizCommands, containerCfg.name, configFile); } catch (ContainerException e) { throw new StartupException("Cannot init() " + containerCfg.name, e); - } catch (java.lang.AbstractMethodError e) { - throw new StartupException("Cannot init() " + containerCfg.name, e); } return containerObj; } - private void printThreadDump() { - Thread currentThread = Thread.currentThread(); - ThreadGroup group = currentThread.getThreadGroup(); - while (group.getParent() != null) { - group = group.getParent(); - } - Thread threadArr[] = new Thread[1000]; - group.enumerate(threadArr); - - StringWriter writer = new StringWriter(); - PrintWriter out = new PrintWriter(writer); - out.println("Thread dump:"); - for (Thread t: threadArr) { - if (t != null) { - ThreadGroup g = t.getThreadGroup(); - out.println("Thread: " + t.getName() + " [" + t.getId() + "] @ " + (g != null ? g.getName() : "[none]") + " : " + t.getPriority() + " [" + t.getState().name() + "]"); - out.println("--- Alive: " + t.isAlive() + " Daemon: " + t.isDaemon()); - for (StackTraceElement stack: t.getStackTrace()) { - out.println("### " + stack.toString()); - } - } - } - Debug.logInfo(writer.toString(), module); - } - - /** - * @see org.apache.ofbiz.base.start.StartupLoader#start() - */ - @Override - public synchronized void start() throws StartupException { - if (!this.loaded || this.unloading) { - throw new IllegalStateException("start() called on unloaded containers"); - } + private void startLoadedContainers() throws StartupException { Debug.logInfo("[Startup] Starting containers...", module); - // start each container object - for (Container container: this.loadedContainers) { - if (this.unloading) { - return; - } + for (Container container: loadedContainers) { Debug.logInfo("Starting container " + container.getName(), module); try { container.start(); } catch (ContainerException e) { throw new StartupException("Cannot start() " + container.getClass().getName(), e); - } catch (java.lang.AbstractMethodError e) { - throw new StartupException("Cannot start() " + container.getClass().getName(), e); } Debug.logInfo("Started container " + container.getName(), module); } @@ -248,26 +158,20 @@ public class ContainerLoader implements StartupLoader { * @see org.apache.ofbiz.base.start.StartupLoader#unload() */ @Override - public void unload() throws StartupException { - if (!this.unloading) { - this.unloading = true; - synchronized (this) { - Debug.logInfo("Shutting down containers", module); - if (Debug.verboseOn()) { - printThreadDump(); - } - // shutting down in reverse order - for (int i = this.loadedContainers.size(); i > 0; i--) { - Container container = this.loadedContainers.get(i-1); - Debug.logInfo("Stopping container " + container.getName(), module); - try { - container.stop(); - } catch (ContainerException e) { - Debug.logError(e, module); - } - Debug.logInfo("Stopped container " + container.getName(), module); - } + public synchronized void unload() throws StartupException { + Debug.logInfo("Shutting down containers", module); + + List reversedContainerList = new ArrayList(loadedContainers); + Collections.reverse(reversedContainerList); + + for(Container loadedContainer : reversedContainerList) { + Debug.logInfo("Stopping container " + loadedContainer.getName(), module); + try { + loadedContainer.stop(); + } catch (ContainerException e) { + Debug.logError(e, module); } + Debug.logInfo("Stopped container " + loadedContainer.getName(), module); } } } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/JustLoadComponentsContainer.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/JustLoadComponentsContainer.java index 3673e47ef8..d9c35e398f 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/JustLoadComponentsContainer.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/JustLoadComponentsContainer.java @@ -18,10 +18,14 @@ *******************************************************************************/ package org.apache.ofbiz.base.container; +import java.util.List; + import org.apache.ofbiz.base.component.AlreadyLoadedException; import org.apache.ofbiz.base.component.ComponentException; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; + /** * A Container implementation to run the tests configured through this testtools stuff. */ @@ -32,7 +36,7 @@ public class JustLoadComponentsContainer implements Container { private String name; @Override - public void init(String[] args, String name, String configFile) { + public void init(List ofbizCommands, String name, String configFile) { this.name = name; try { ComponentContainer cc = new ComponentContainer(); diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/NamingServiceContainer.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/NamingServiceContainer.java index 3af2a9dafe..da3eca384f 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/NamingServiceContainer.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/NamingServiceContainer.java @@ -24,8 +24,10 @@ import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; +import java.util.List; import org.apache.ofbiz.base.start.Start; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.RMIExtendedSocketFactory; /** @@ -47,15 +49,15 @@ public class NamingServiceContainer implements Container { private String name; - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name =name; this.configFileLocation = configFile; - ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFileLocation); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFileLocation); // get the naming (JNDI) port - ContainerConfig.Container.Property port = cfg.getProperty("port"); + ContainerConfig.Configuration.Property port = cfg.getProperty("port"); if (port.value != null) { try { this.namingPort = Integer.parseInt(port.value) + Start.getInstance().getConfig().portOffset; @@ -65,7 +67,7 @@ public class NamingServiceContainer implements Container { } // get the naming (JNDI) server - ContainerConfig.Container.Property host = cfg.getProperty("host"); + ContainerConfig.Configuration.Property host = cfg.getProperty("host"); if (host != null && host.value != null) { this.namingHost = host.value ; } diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/StartupCommandToArgsAdapter.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/StartupCommandToArgsAdapter.java new file mode 100644 index 0000000000..be8ff5bc3a --- /dev/null +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/StartupCommandToArgsAdapter.java @@ -0,0 +1,47 @@ +package org.apache.ofbiz.base.container; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.ofbiz.base.start.StartupCommand; +import org.apache.ofbiz.base.start.StartupCommandUtil; + +/** + * Temporary class. This class is responsible for converting + * StartupCommand instances to String[]. This is a workaround until all + * containers have fully changed their signatures to adopt the StartupCommand + * object + */ +public class StartupCommandToArgsAdapter { + /** + * Generates the loaderArgs with arguments as expected by the + * containers that will receive them. + * + * TODO A better solution is to change the signature of all + * containers to receive a List of StartupCommands + * instead and delete the methods adaptStartupCommandsToLoaderArgs + * and retrieveCommandArguments along with the loaderArgs list. + */ + public static String[] adaptStartupCommandsToLoaderArgs(List ofbizCommands) { + List loaderArgs = new ArrayList(); + final String LOAD_DATA = StartupCommandUtil.StartupOption.LOAD_DATA.getName(); + final String TEST = StartupCommandUtil.StartupOption.TEST.getName(); + + if(ofbizCommands.stream().anyMatch(command -> command.getName().equals(LOAD_DATA))) { + retrieveCommandArguments(ofbizCommands, LOAD_DATA).entrySet().stream().forEach(entry -> + loaderArgs.add("-" + entry.getKey() + "=" + entry.getValue())); + } else if(ofbizCommands.stream().anyMatch(command -> command.getName().equals(TEST))) { + retrieveCommandArguments(ofbizCommands, TEST).entrySet().stream().forEach(entry -> + loaderArgs.add("-" + entry.getKey() + "=" + entry.getValue())); + } + return loaderArgs.toArray(new String[loaderArgs.size()]); + } + + private static Map retrieveCommandArguments(List ofbizCommands, String commandName) { + return ofbizCommands.stream() + .filter(option-> option.getName().equals(commandName)) + .collect(Collectors.toList()).get(0).getProperties(); + } +} diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/lang/LockedBy.java b/framework/base/src/main/java/org/apache/ofbiz/base/lang/LockedBy.java deleted file mode 100644 index be3c8bdc59..0000000000 --- a/framework/base/src/main/java/org/apache/ofbiz/base/lang/LockedBy.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.ofbiz.base.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** This annotation is meant to be used to describe how some variable - * or method is protected by some other locking mechanism. Its value - * is free-form, and can contain anything. It will generally contain - * the name of an instance variable, including this. - */ -@Documented -@Retention(RetentionPolicy.SOURCE) -@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD}) -public @interface LockedBy { - String value(); -} diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/metrics/MetricsFactory.java b/framework/base/src/main/java/org/apache/ofbiz/base/metrics/MetricsFactory.java index 7ce330724a..aee5cec6d7 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/metrics/MetricsFactory.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/metrics/MetricsFactory.java @@ -31,7 +31,6 @@ package org.apache.ofbiz.base.metrics; import java.util.Collection; import java.util.TreeSet; -import org.apache.ofbiz.base.lang.LockedBy; import org.apache.ofbiz.base.lang.ThreadSafe; import org.apache.ofbiz.base.util.Assert; import org.apache.ofbiz.base.util.UtilProperties; @@ -138,17 +137,11 @@ public final class MetricsFactory { } private static final class MetricsImpl implements Metrics, Comparable { - @LockedBy("this") private int count = 0; - @LockedBy("this") private long lastTime = System.currentTimeMillis(); - @LockedBy("this") private double serviceRate = 0.0; - @LockedBy("this") private long totalServiceTime = 0; - @LockedBy("this") private long totalEvents = 0; - @LockedBy("this") private long cumulativeEvents = 0; private final String name; private final int estimationSize; diff --git a/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java b/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java index 5eb02a074d..bf5e49a05c 100644 --- a/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java +++ b/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java @@ -68,10 +68,11 @@ import org.apache.ofbiz.base.component.ComponentConfig; import org.apache.ofbiz.base.concurrent.ExecutionPool; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; -import org.apache.ofbiz.base.container.ContainerConfig.Container.Property; +import org.apache.ofbiz.base.container.ContainerConfig.Configuration.Property; import org.apache.ofbiz.base.container.ContainerException; import org.apache.ofbiz.base.location.FlexibleLocation; import org.apache.ofbiz.base.start.Start; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.SSLUtil; import org.apache.ofbiz.base.util.UtilValidate; @@ -145,7 +146,7 @@ public class CatalinaContainer implements Container { } private Tomcat tomcat = null; - protected Map clusterConfig = new HashMap(); + protected Map clusterConfig = new HashMap(); protected boolean contextReloadable = false; protected boolean crossContext = false; @@ -156,10 +157,10 @@ public class CatalinaContainer implements Container { private String name; @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name = name; // get the container config - ContainerConfig.Container cc = ContainerConfig.getContainer(name, configFile); + ContainerConfig.Configuration cc = ContainerConfig.getConfiguration(name, configFile); if (cc == null) { throw new ContainerException("No catalina-container configuration found in container config!"); } @@ -196,7 +197,7 @@ public class CatalinaContainer implements Container { } // create the engine - List engineProps = cc.getPropertiesWithValue("engine"); + List engineProps = cc.getPropertiesWithValue("engine"); if (UtilValidate.isEmpty(engineProps)) { throw new ContainerException("Cannot load CatalinaContainer; no engines defined."); } @@ -206,11 +207,11 @@ public class CatalinaContainer implements Container { createEngine(engineProps.get(0)); // create the connectors - List connectorProps = cc.getPropertiesWithValue("connector"); + List connectorProps = cc.getPropertiesWithValue("connector"); if (UtilValidate.isEmpty(connectorProps)) { throw new ContainerException("Cannot load CatalinaContainer; no connectors defined!"); } - for (ContainerConfig.Container.Property connectorProp: connectorProps) { + for (ContainerConfig.Configuration.Property connectorProp: connectorProps) { createConnector(connectorProp); } } @@ -234,12 +235,12 @@ public class CatalinaContainer implements Container { return true; } - private Engine createEngine(ContainerConfig.Container.Property engineConfig) throws ContainerException { + private Engine createEngine(ContainerConfig.Configuration.Property engineConfig) throws ContainerException { if (tomcat == null) { throw new ContainerException("Cannot create Engine without Tomcat instance!"); } - ContainerConfig.Container.Property defaultHostProp = engineConfig.getProperty("default-host"); + ContainerConfig.Configuration.Property defaultHostProp = engineConfig.getProperty("default-host"); if (defaultHostProp == null) { throw new ContainerException("default-host element of server property is required for catalina!"); } @@ -262,13 +263,13 @@ public class CatalinaContainer implements Container { configureHost(host); // configure clustering - List clusterProps = engineConfig.getPropertiesWithValue("cluster"); + List clusterProps = engineConfig.getPropertiesWithValue("cluster"); if (clusterProps != null && clusterProps.size() > 1) { throw new ContainerException("Only one cluster configuration allowed per engine"); } if (UtilValidate.isNotEmpty(clusterProps)) { - ContainerConfig.Container.Property clusterProp = clusterProps.get(0); + ContainerConfig.Configuration.Property clusterProp = clusterProps.get(0); createCluster(clusterProp, host); clusterConfig.put(engineName, clusterProp); } @@ -341,7 +342,7 @@ public class CatalinaContainer implements Container { ((StandardHost)host).setWorkDir(new File(System.getProperty(Globals.CATALINA_HOME_PROP), "work" + File.separator + host.getName()).getAbsolutePath()); } - protected Cluster createCluster(ContainerConfig.Container.Property clusterProps, Host host) throws ContainerException { + protected Cluster createCluster(ContainerConfig.Configuration.Property clusterProps, Host host) throws ContainerException { String defaultValveFilter = ".*\\.gif;.*\\.js;.*\\.jpg;.*\\.htm;.*\\.html;.*\\.txt;.*\\.png;.*\\.css;.*\\.ico;.*\\.htc;"; ReplicationValve clusterValve = new ReplicationValve(); @@ -429,7 +430,7 @@ public class CatalinaContainer implements Container { return cluster; } - protected Connector createConnector(ContainerConfig.Container.Property connectorProp) throws ContainerException { + protected Connector createConnector(ContainerConfig.Configuration.Property connectorProp) throws ContainerException { if (tomcat == null) { throw new ContainerException("Cannot create Connector without Tomcat instance!"); } @@ -442,7 +443,7 @@ public class CatalinaContainer implements Container { connector = new Connector(protocol); connector.setPort(port); // then set all the other parameters - for (ContainerConfig.Container.Property prop: connectorProp.properties.values()) { + for (ContainerConfig.Configuration.Property prop: connectorProp.properties.values()) { if ("protocol".equals(prop.name) || "port".equals(prop.name)) { // protocol and port are already set continue; diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java index 6325c5aa49..3fa9ebf864 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/DelegatorContainer.java @@ -27,6 +27,7 @@ import org.apache.ofbiz.base.concurrent.ExecutionPool; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.base.util.StringUtil; @@ -35,10 +36,10 @@ public class DelegatorContainer implements Container { private List preloadedDelegatorNames; @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name = name; - ContainerConfig.Container cc = ContainerConfig.getContainer(name, configFile); + ContainerConfig.Configuration cc = ContainerConfig.getConfiguration(name, configFile); preloadedDelegatorNames = StringUtil.split(ContainerConfig.getPropertyValue(cc, "preloaded-delegators", "default"), ", "); } diff --git a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java index b9b4ca1315..7e844042a6 100644 --- a/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java +++ b/framework/entityext/src/main/java/org/apache/ofbiz/entityext/data/EntityDataLoadContainer.java @@ -32,6 +32,8 @@ import org.apache.ofbiz.base.component.ComponentConfig; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.container.StartupCommandToArgsAdapter; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.StringUtil; import org.apache.ofbiz.base.util.UtilURL; @@ -83,7 +85,10 @@ public class EntityDataLoadContainer implements Container { } @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { + // TODO: remove this hack and provide clean implementation + String[] args = StartupCommandToArgsAdapter.adaptStartupCommandsToLoaderArgs(ofbizCommands); + this.name = name; this.configFile = configFile; // disable job scheduler, JMS listener and startup services @@ -212,8 +217,8 @@ public class EntityDataLoadContainer implements Container { Debug.logWarning("Multitenant is disabled. Please enable multitenant. (e.g. general.properties --> multitenant=Y)", module); return true; } - ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFile); - ContainerConfig.Container.Property delegatorNameProp = cfg.getProperty("delegator-name"); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFile); + ContainerConfig.Configuration.Property delegatorNameProp = cfg.getProperty("delegator-name"); String delegatorName = null; if (delegatorNameProp == null || UtilValidate.isEmpty(delegatorNameProp.value)) { throw new ContainerException("Invalid delegator-name defined in container configuration"); @@ -243,9 +248,9 @@ public class EntityDataLoadContainer implements Container { return true; } private void loadContainer() throws ContainerException{ - ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFile); - ContainerConfig.Container.Property delegatorNameProp = cfg.getProperty("delegator-name"); - ContainerConfig.Container.Property entityGroupNameProp = cfg.getProperty("entity-group-name"); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFile); + ContainerConfig.Configuration.Property delegatorNameProp = cfg.getProperty("delegator-name"); + ContainerConfig.Configuration.Property entityGroupNameProp = cfg.getProperty("entity-group-name"); String delegatorName = null; String entityGroupName = null; diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceContainer.java b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceContainer.java index dd4d4f1a74..037144323e 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/ServiceContainer.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/ServiceContainer.java @@ -19,12 +19,14 @@ package org.apache.ofbiz.service; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.entity.Delegator; @@ -41,11 +43,11 @@ public class ServiceContainer implements Container { private String name; @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name = name; // initialize the LocalDispatcherFactory - ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFile); - ContainerConfig.Container.Property dispatcherFactoryProperty = cfg.getProperty("dispatcher-factory"); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFile); + ContainerConfig.Configuration.Property dispatcherFactoryProperty = cfg.getProperty("dispatcher-factory"); if (dispatcherFactoryProperty == null || UtilValidate.isEmpty(dispatcherFactoryProperty.value)) { throw new ContainerException("Unable to initialize container " + name + ": dispatcher-factory property is not set"); } diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/mail/JavaMailContainer.java b/framework/service/src/main/java/org/apache/ofbiz/service/mail/JavaMailContainer.java index 19180779a0..9e8f5a74ae 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/mail/JavaMailContainer.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/mail/JavaMailContainer.java @@ -43,6 +43,7 @@ import javax.mail.search.FlagTerm; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilValidate; @@ -80,7 +81,7 @@ public class JavaMailContainer implements Container { * */ @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name = name; this.configFile = configFile; this.stores = new LinkedHashMap(); @@ -96,7 +97,7 @@ public class JavaMailContainer implements Container { */ @Override public boolean start() throws ContainerException { - ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFile); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFile); String dispatcherName = ContainerConfig.getPropertyValue(cfg, "dispatcher-name", "JavaMailDispatcher"); String delegatorName = ContainerConfig.getPropertyValue(cfg, "delegator-name", "default"); this.deleteMail = "true".equals(ContainerConfig.getPropertyValue(cfg, "delete-mail", "false")); @@ -119,8 +120,8 @@ public class JavaMailContainer implements Container { ServiceMcaUtil.readConfig(); // load the listeners - List configs = cfg.getPropertiesWithValue("store-listener"); - for (ContainerConfig.Container.Property prop: configs) { + List configs = cfg.getPropertiesWithValue("store-listener"); + for (ContainerConfig.Configuration.Property prop: configs) { Session session = this.makeSession(prop); Store store = this.getStore(session); if (store != null) { @@ -158,11 +159,11 @@ public class JavaMailContainer implements Container { } // java-mail methods - protected Session makeSession(ContainerConfig.Container.Property client) { + protected Session makeSession(ContainerConfig.Configuration.Property client) { Properties props = new Properties(); - Map clientProps = client.properties; + Map clientProps = client.properties; if (clientProps != null) { - for (ContainerConfig.Container.Property p: clientProps.values()) { + for (ContainerConfig.Configuration.Property p: clientProps.values()) { props.setProperty(p.name.toLowerCase(), p.value); } } diff --git a/framework/service/src/main/java/org/apache/ofbiz/service/rmi/RmiServiceContainer.java b/framework/service/src/main/java/org/apache/ofbiz/service/rmi/RmiServiceContainer.java index 6eed6f54cd..e8fcf02ef1 100644 --- a/framework/service/src/main/java/org/apache/ofbiz/service/rmi/RmiServiceContainer.java +++ b/framework/service/src/main/java/org/apache/ofbiz/service/rmi/RmiServiceContainer.java @@ -22,6 +22,7 @@ import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.server.RMIClientSocketFactory; import java.rmi.server.RMIServerSocketFactory; +import java.util.List; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -30,6 +31,7 @@ import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; import org.apache.ofbiz.base.start.Start; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.entity.Delegator; import org.apache.ofbiz.entity.DelegatorFactory; @@ -50,21 +52,21 @@ public class RmiServiceContainer implements Container { // Container methods @Override - public void init(String[] args, String name, String configFile) { + public void init(List ofbizCommands, String name, String configFile) { this.containerName = name; this.configFile = configFile; } public boolean start() throws ContainerException { // get the container config - ContainerConfig.Container cfg = ContainerConfig.getContainer(containerName, configFile); - ContainerConfig.Container.Property initialCtxProp = cfg.getProperty("use-initial-context"); - ContainerConfig.Container.Property lookupHostProp = cfg.getProperty("bound-host"); - ContainerConfig.Container.Property lookupPortProp = cfg.getProperty("bound-port"); - ContainerConfig.Container.Property lookupNameProp = cfg.getProperty("bound-name"); - ContainerConfig.Container.Property delegatorProp = cfg.getProperty("delegator-name"); - ContainerConfig.Container.Property clientProp = cfg.getProperty("client-factory"); - ContainerConfig.Container.Property serverProp = cfg.getProperty("server-factory"); + ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(containerName, configFile); + ContainerConfig.Configuration.Property initialCtxProp = cfg.getProperty("use-initial-context"); + ContainerConfig.Configuration.Property lookupHostProp = cfg.getProperty("bound-host"); + ContainerConfig.Configuration.Property lookupPortProp = cfg.getProperty("bound-port"); + ContainerConfig.Configuration.Property lookupNameProp = cfg.getProperty("bound-name"); + ContainerConfig.Configuration.Property delegatorProp = cfg.getProperty("delegator-name"); + ContainerConfig.Configuration.Property clientProp = cfg.getProperty("client-factory"); + ContainerConfig.Configuration.Property serverProp = cfg.getProperty("server-factory"); // check the required lookup-name property if (lookupNameProp == null || UtilValidate.isEmpty(lookupNameProp.value)) { diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminClient.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminClient.java index 8ce74cf15d..3f17d8d75d 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminClient.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminClient.java @@ -73,20 +73,15 @@ class AdminClient { private static String sendSocketCommand(OfbizSocketCommand socketCommand, Config config) throws IOException { String response = "OFBiz is Down"; - try { - Socket socket = new Socket(config.adminAddress, config.adminPort); + try (Socket socket = new Socket(config.adminAddress, config.adminPort); + PrintWriter writer = new PrintWriter(socket.getOutputStream(), true); + BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { + // send the command - PrintWriter writer = new PrintWriter(socket.getOutputStream(), true); writer.println(config.adminKey + ":" + socketCommand); writer.flush(); // read the reply - BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); response = reader.readLine(); - reader.close(); - // close the socket - writer.close(); - socket.close(); - } catch (ConnectException e) { System.out.println("Could not connect to " + config.adminAddress + ":" + config.adminPort); } diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminServer.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminServer.java index 62479431eb..5d468449db 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminServer.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/AdminServer.java @@ -24,7 +24,6 @@ import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.apache.ofbiz.base.start.Start.ServerState; @@ -44,11 +43,11 @@ final class AdminServer extends Thread { } private ServerSocket serverSocket = null; - private List loaders = null; + private StartupLoader loader = null; private AtomicReference serverState = null; private Config config = null; - AdminServer(List loaders, AtomicReference serverState, Config config) throws StartupException { + AdminServer(StartupLoader loader, AtomicReference serverState, Config config) throws StartupException { super("OFBiz-AdminServer"); try { this.serverSocket = new ServerSocket(config.adminPort, 1, config.adminAddress); @@ -56,7 +55,7 @@ final class AdminServer extends Thread { throw new StartupException("Couldn't create server socket(" + config.adminAddress + ":" + config.adminPort + ")", e); } setDaemon(false); - this.loaders = loaders; + this.loader = loader; this.serverState = serverState; this.config = config; } @@ -65,52 +64,41 @@ final class AdminServer extends Thread { public void run() { System.out.println("Admin socket configured on - " + config.adminAddress + ":" + config.adminPort); while (!Thread.interrupted()) { - try { - Socket clientSocket = serverSocket.accept(); - System.out.println("Received connection from - " + clientSocket.getInetAddress() + " : " + try (Socket clientSocket = serverSocket.accept()){ + + System.out.println("Received connection from - " + + clientSocket.getInetAddress() + " : " + clientSocket.getPort()); - processClientRequest(clientSocket, loaders, serverState); - clientSocket.close(); + + processClientRequest(clientSocket, loader, serverState); + } catch (IOException e) { e.printStackTrace(); } } } - private void processClientRequest(Socket client, List loaders, AtomicReference serverState) throws IOException { - BufferedReader reader = null; - PrintWriter writer = null; - try { - reader = new BufferedReader(new InputStreamReader(client.getInputStream())); - writer = new PrintWriter(client.getOutputStream(), true); + private void processClientRequest(Socket client, StartupLoader loader, AtomicReference serverState) throws IOException { - executeClientRequest(reader, writer, loaders, serverState); - } finally { - if (reader != null) { - reader.close(); - } - if (writer != null) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream())); + PrintWriter writer = new PrintWriter(client.getOutputStream(), true)) { + + // read client request and prepare response + String clientRequest = reader.readLine(); + OfbizSocketCommand clientCommand = determineClientCommand(clientRequest); + String serverResponse = prepareResponseToClient(clientCommand, serverState); + + // send response back to client + writer.println(serverResponse); + + // if the client request is shutdown, execute shutdown sequence + if(clientCommand.equals(OfbizSocketCommand.SHUTDOWN)) { writer.flush(); - writer.close(); + StartupControlPanel.stop(loader, serverState, this); } } } - private void executeClientRequest(BufferedReader reader, PrintWriter writer, - List loaders, AtomicReference serverState) throws IOException { - - String clientRequest = reader.readLine(); - OfbizSocketCommand clientCommand = determineClientCommand(clientRequest); - String serverResponse = prepareResponseToClient(clientCommand, serverState); - - writer.println(serverResponse); - - if(clientCommand.equals(OfbizSocketCommand.SHUTDOWN)) { - writer.flush(); - StartupControlPanel.stop(loaders, serverState, this); - } - } - private OfbizSocketCommand determineClientCommand(String request) { OfbizSocketCommand clientCommand; if(request == null diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java index df2466dc32..17f525d89a 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java @@ -25,8 +25,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -48,7 +46,7 @@ public final class Config { public final int portOffset; public final int adminPort; public final String containerConfig; - public final List> loaders; + public final Map loader; public final String logDir; public final boolean shutdownAfterLoad; public final boolean useShutdownHook; @@ -72,7 +70,7 @@ public final class Config { portOffset = getPortOffsetValue(ofbizCommands); adminPort = getAdminPort(props, portOffset); containerConfig = getAbsolutePath(props, "ofbiz.container.config", "framework/base/config/ofbiz-containers.xml", ofbizHome); - loaders = getLoaders(props); + loader = getLoader(props); logDir = getAbsolutePath(props, "ofbiz.log.dir", "runtime/logs", ofbizHome); shutdownAfterLoad = isShutdownAfterLoad(props); useShutdownHook = isUseShutdownHook(props); @@ -234,25 +232,11 @@ public final class Config { return calculatedAdminPort; } - private List> getLoaders(Properties props) { - ArrayList> loadersTmp = new ArrayList>(); - int currentPosition = 1; - Map loader = null; - while (true) { - loader = new HashMap(); - String loaderClass = props.getProperty("ofbiz.start.loader" + currentPosition); - - if (loaderClass == null || loaderClass.length() == 0) { - break; - } else { - loader.put("class", loaderClass); - loader.put("profiles", props.getProperty("ofbiz.start.loader" + currentPosition + ".loaders")); - loadersTmp.add(Collections.unmodifiableMap(loader)); - currentPosition++; - } - } - loadersTmp.trimToSize(); - return Collections.unmodifiableList(loadersTmp); + private Map getLoader(Properties props) { + Map loader = new HashMap(); + loader.put("class", props.getProperty("ofbiz.start.loader")); + loader.put("profiles", props.getProperty("ofbiz.start.loader.loaders")); + return loader; } private String getOfbizHome(Properties props) { diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommand.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommand.java index 94dd6f62e4..6e46131fce 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommand.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommand.java @@ -18,6 +18,7 @@ *******************************************************************************/ package org.apache.ofbiz.base.start; +import java.util.HashMap; import java.util.Map; /** @@ -29,7 +30,7 @@ import java.util.Map; * For example: java -jar build/libs/ofbiz.jar --status where status is a command. *

*/ -final class StartupCommand { +public final class StartupCommand { private String name; private Map properties; @@ -59,6 +60,13 @@ final class StartupCommand { this.properties = properties; return this; } + public Builder addProperty(String key, String value) { + if(properties == null) { + properties = new HashMap(); + } + properties.put(key, value); + return this; + } public StartupCommand build() { return new StartupCommand(this); diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java index 11b3cd6782..678a393348 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java @@ -20,7 +20,6 @@ package org.apache.ofbiz.base.start; import java.io.PrintStream; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -46,7 +45,7 @@ import org.apache.commons.cli.ParseException; * in addition to utility methods for parsing and handling these options *

*/ -final class StartupCommandUtil { +public final class StartupCommandUtil { /* * Make sure of defining the same set of values in: @@ -180,36 +179,6 @@ final class StartupCommandUtil { ); } - /** - * Generates the loaderArgs with arguments as expected by the - * containers that will receive them. - * - * TODO A better solution is to change the signature of all - * containers to receive a List of StartupCommands - * instead and delete the methods adaptStartupCommandsToLoaderArgs - * and retrieveCommandArguments along with the loaderArgs list. - */ - static List adaptStartupCommandsToLoaderArgs(List ofbizCommands) { - List loaderArgs = new ArrayList(); - final String LOAD_DATA = StartupCommandUtil.StartupOption.LOAD_DATA.getName(); - final String TEST = StartupCommandUtil.StartupOption.TEST.getName(); - - if(ofbizCommands.stream().anyMatch(command -> command.getName().equals(LOAD_DATA))) { - retrieveCommandArguments(ofbizCommands, LOAD_DATA).entrySet().stream().forEach(entry -> - loaderArgs.add("-" + entry.getKey() + "=" + entry.getValue())); - } else if(ofbizCommands.stream().anyMatch(command -> command.getName().equals(TEST))) { - retrieveCommandArguments(ofbizCommands, TEST).entrySet().stream().forEach(entry -> - loaderArgs.add("-" + entry.getKey() + "=" + entry.getValue())); - } - return loaderArgs; - } - - private static Map retrieveCommandArguments(List ofbizCommands, String commandName) { - return ofbizCommands.stream() - .filter(option-> option.getName().equals(commandName)) - .collect(Collectors.toList()).get(0).getProperties(); - } - private static final Options getOfbizStartupOptions() { OptionGroup ofbizCommandOptions = new OptionGroup(); ofbizCommandOptions.addOption(HELP); diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java index 52517e0e80..e4bba749ae 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java @@ -21,9 +21,7 @@ package org.apache.ofbiz.base.start; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import org.apache.ofbiz.base.start.Start.ServerState; @@ -61,17 +59,15 @@ final class StartupControlPanel { AtomicReference serverState, List ofbizCommands) throws StartupException { - List loaders = new ArrayList(); - List loaderArgs = StartupCommandUtil.adaptStartupCommandsToLoaderArgs(ofbizCommands); - Thread adminServer = createAdminServer(config, serverState, loaders); + StartupLoader loader = instantiateStartupLoader(config, Thread.currentThread().getContextClassLoader()); + Thread adminServer = createAdminServer(config, serverState, loader); Classpath classPath = createClassPath(config); - NativeLibClassLoader classLoader = createAndSetContextClassLoader(config, classPath); + createAndSetContextClassLoader(config, classPath); createLogDirectoryIfMissing(config); - createRuntimeShutdownHook(config, loaders, serverState); - loadStartupLoaders(config, loaders, loaderArgs, serverState, classLoader); - startStartupLoaders(loaders, serverState); - executeShutdownAfterLoadIfConfigured(config, loaders, serverState, adminServer); + createRuntimeShutdownHook(config, loader, serverState); + executeStartupLoadSequence(config, loader, ofbizCommands, serverState); + executeShutdownAfterLoadIfConfigured(config, loader, serverState, adminServer); } /** @@ -81,8 +77,8 @@ final class StartupControlPanel { * - Manually if requested by the client AdminClient * - Automatically if Config.shutdownAfterLoad is set to true */ - static void stop(List loaders, AtomicReference serverState, Thread adminServer) { - shutdownServer(loaders, serverState, adminServer); + static void stop(StartupLoader loader, AtomicReference serverState, Thread adminServer) { + shutdownServer(loader, serverState, adminServer); System.exit(0); } @@ -106,7 +102,7 @@ final class StartupControlPanel { System.exit(1); } - private static void shutdownServer(List loaders, AtomicReference serverState, Thread adminServer) { + private static void shutdownServer(StartupLoader loader, AtomicReference serverState, Thread adminServer) { ServerState currentState; do { currentState = serverState.get(); @@ -116,16 +112,10 @@ final class StartupControlPanel { } while (!serverState.compareAndSet(currentState, ServerState.STOPPING)); // The current thread was the one that successfully changed the state; // continue with further processing. - synchronized (loaders) { - // Unload in reverse order - for (int i = loaders.size(); i > 0; i--) { - StartupLoader loader = loaders.get(i - 1); - try { - loader.unload(); - } catch (Exception e) { - e.printStackTrace(); - } - } + try { + loader.unload(); + } catch (Exception e) { + e.printStackTrace(); } if (adminServer != null && adminServer.isAlive()) { adminServer.interrupt(); @@ -146,14 +136,26 @@ final class StartupControlPanel { } } + private static StartupLoader instantiateStartupLoader(Config config, ClassLoader classLoader) throws StartupException { + StartupLoader loader; + try { + String className = config.loader.get("class"); + Class loaderClass = classLoader.loadClass(className); + loader = (StartupLoader) loaderClass.newInstance(); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + throw new StartupException("Could not initiate a StartupLoader", e); + } + return loader; + } + private static Thread createAdminServer( Config config, AtomicReference serverState, - List loaders) throws StartupException { + StartupLoader loader) throws StartupException { Thread adminServer = null; if (config.adminPort > 0) { - adminServer = new AdminServer(loaders, serverState, config); + adminServer = new AdminServer(loader, serverState, config); adminServer.start(); } else { System.out.println("Admin socket not configured; set to port 0"); @@ -208,14 +210,14 @@ final class StartupControlPanel { private static void createRuntimeShutdownHook( Config config, - List loaders, + StartupLoader loader, AtomicReference serverState) { if (config.useShutdownHook) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - shutdownServer(loaders, serverState, this); + shutdownServer(loader, serverState, this); } }); } else { @@ -223,51 +225,13 @@ final class StartupControlPanel { } } - private static void loadStartupLoaders(Config config, - List loaders, - List loaderArgs, - AtomicReference serverState, - NativeLibClassLoader classloader) throws StartupException { - - String[] argsArray = loaderArgs.toArray(new String[loaderArgs.size()]); - synchronized (loaders) { - for (Map loaderMap : config.loaders) { - if (serverState.get() == ServerState.STOPPING) { - return; - } - try { - String loaderClassName = loaderMap.get("class"); - Class loaderClass = classloader.loadClass(loaderClassName); - StartupLoader loader = (StartupLoader) loaderClass.newInstance(); - loaders.add(loader); // add before loading, so unload can occur if error during loading - loader.load(config, argsArray); - } catch (ReflectiveOperationException e) { - throw new StartupException(e.getMessage(), e); - } - } - } - StringBuilder sb = new StringBuilder(); - for (String path : classloader.getNativeLibPaths()) { - if (sb.length() > 0) { - sb.append(File.pathSeparator); - } - sb.append(path); - } - System.setProperty("java.library.path", sb.toString()); - } - - private static void startStartupLoaders(List loaders, + private static void executeStartupLoadSequence(Config config, + StartupLoader loader, + List ofbizCommands, AtomicReference serverState) throws StartupException { - synchronized (loaders) { - // start the loaders - for (StartupLoader loader : loaders) { - if (serverState.get() == ServerState.STOPPING) { - return; - } else { - loader.start(); - } - } + if (serverState.get() != ServerState.STOPPING) { + loader.load(config, ofbizCommands); } if(!serverState.compareAndSet(ServerState.STARTING, ServerState.RUNNING)) { throw new StartupException("Error during start"); @@ -276,12 +240,12 @@ final class StartupControlPanel { private static void executeShutdownAfterLoadIfConfigured( Config config, - List loaders, + StartupLoader loader, AtomicReference serverState, Thread adminServer) { if (config.shutdownAfterLoad) { - stop(loaders, serverState, adminServer); + stop(loader, serverState, adminServer); } } } diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java index f88bccacfe..724b5d7cf3 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java @@ -18,6 +18,8 @@ *******************************************************************************/ package org.apache.ofbiz.base.start; +import java.util.List; + /** * An object that loads server startup classes. *

@@ -35,23 +37,15 @@ package org.apache.ofbiz.base.start; public interface StartupLoader { /** - * Load a startup class. + * Start a startup class. * * @param config Startup config. - * @param args Command-line arguments. + * @param ofbizCommands Command-line arguments. * @throws StartupException If an error was encountered. Throwing this exception * will halt loader loading, so it should be thrown only when OFBiz can't * operate without it. */ - public void load(Config config, String args[]) throws StartupException; - - /** - * Start the startup class. This method must not block - implementations - * that require thread blocking must create a separate thread and then return. - * - * @throws StartupException If an error was encountered. - */ - public void start() throws StartupException; + public void load(Config config, List ofbizCommands) throws StartupException; /** * Stop the startup class. This method must not block. diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties b/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties index 6ac70dc02a..fd743a8f37 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties @@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=framework/base/config,framework/base/dtd #ofbiz.container.config=framework/base/config/ofbiz-containers.xml # --- StartupLoader implementations to load (in order) -ofbiz.start.loader1=org.apache.ofbiz.base.container.ContainerLoader -ofbiz.start.loader1.loaders=load-data +ofbiz.start.loader=org.apache.ofbiz.base.container.ContainerLoader +ofbiz.start.loader.loaders=load-data # -- Enable the shutdown hook #ofbiz.enable.hook=false diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties b/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties index 91d13a2d07..0c991457f1 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties @@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=framework/base/config,framework/base/dtd #ofbiz.container.config=framework/base/config/ofbiz-containers.xml # --- StartupLoader implementations to load (in order) -ofbiz.start.loader1=org.apache.ofbiz.base.container.ContainerLoader -ofbiz.start.loader1.loaders=rmi +ofbiz.start.loader=org.apache.ofbiz.base.container.ContainerLoader +ofbiz.start.loader.loaders=rmi # -- Enable the shutdown hook #ofbiz.enable.hook=true diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties b/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties index 51fc87f05f..a3235118da 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties @@ -38,11 +38,11 @@ ofbiz.admin.key=so3du5kasd5dn #ofbiz.container.config=framework/base/config/ofbiz-containers.xml # --- StartupLoader implementations to load (in order) -ofbiz.start.loader1=org.apache.ofbiz.base.container.ContainerLoader +ofbiz.start.loader=org.apache.ofbiz.base.container.ContainerLoader # Because of the danger of Java deserialization when using RMI, the RMI component has been disabled in the default configuration of OFBiz. # If you need RMI you just need to uncomment those places - See OFBIZ-6942 for details --> #ofbiz.start.loader1.loaders=main,rmi -ofbiz.start.loader1.loaders=main +ofbiz.start.loader.loaders=main # -- Enable the shutdown hook #ofbiz.enable.hook=true diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties b/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties index f14a08d944..035d84e889 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties @@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=framework/base/config,framework/base/dtd #ofbiz.container.config=framework/base/config/ofbiz-containers.xml # --- StartupLoader implementations to load (in order) -ofbiz.start.loader1=org.apache.ofbiz.base.container.ContainerLoader -ofbiz.start.loader1.loaders=test +ofbiz.start.loader=org.apache.ofbiz.base.container.ContainerLoader +ofbiz.start.loader.loaders=test # -- Enable the shutdown hook #ofbiz.enable.hook=true diff --git a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java index eb2e2d01b8..537b723d19 100644 --- a/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java +++ b/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java @@ -24,6 +24,7 @@ import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import java.util.Map; import junit.framework.AssertionFailedError; @@ -39,6 +40,8 @@ import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; import org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.container.StartupCommandToArgsAdapter; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.entity.Delegator; @@ -59,7 +62,10 @@ public class TestRunContainer implements Container { private String name; @Override - public void init(String[] args, String name, String configFile) { + public void init(List ofbizCommands, String name, String configFile) { + // TODO: remove this hack and provide clean implementation + String[] args = StartupCommandToArgsAdapter.adaptStartupCommandsToLoaderArgs(ofbizCommands); + this.name = name; this.configFile = configFile; if (args != null) { diff --git a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java index 7a24c7ea18..ab1ebb35e7 100644 --- a/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java +++ b/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java @@ -18,10 +18,14 @@ *******************************************************************************/ package org.apache.ofbiz.webtools.artifactinfo; +import java.util.ArrayList; +import java.util.List; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.ofbiz.base.container.ContainerException; - +import org.apache.ofbiz.base.start.StartupCommand; +import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.testtools.*; /** @@ -38,15 +42,17 @@ public class RunTestEvents { String caseName = request.getParameter("caseName"); String result = null; - String[] args = null; + List ofbizCommands = new ArrayList(); if (caseName == null) { - args = new String[]{"-component=" + component, " -suitename=" + suiteName + " -loglevel=info"}; + ofbizCommands.add(new StartupCommand.Builder("test").properties( + UtilMisc.toMap("component", component, "suitename", suiteName)).build()); } else { - args = new String[]{"-component=" + component, " -suitename=" + suiteName, " -case=" + caseName, " -loglevel=info"}; + ofbizCommands.add(new StartupCommand.Builder("test").properties( + UtilMisc.toMap("component", component, "suitename", suiteName, "case", caseName)).build()); } TestRunContainer testRunContainer = new TestRunContainer(); - testRunContainer.init(args, "frontend test run", " "); + testRunContainer.init(ofbizCommands, "frontend test run", " "); if (testRunContainer.start() == false) { result = "error"; } else { @@ -56,4 +62,3 @@ public class RunTestEvents { return result; } } - diff --git a/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java b/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java index 4010d2a59e..132b2ebe1e 100644 --- a/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java +++ b/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java @@ -19,6 +19,7 @@ package org.apache.ofbiz.birt.container; import java.io.File; +import java.util.List; import java.util.logging.Level; import org.eclipse.birt.core.exception.BirtException; @@ -30,6 +31,7 @@ import org.eclipse.birt.report.engine.api.IReportEngineFactory; import org.apache.ofbiz.base.container.Container; import org.apache.ofbiz.base.container.ContainerConfig; import org.apache.ofbiz.base.container.ContainerException; +import org.apache.ofbiz.base.start.StartupCommand; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.birt.BirtFactory; @@ -42,7 +44,7 @@ public class BirtContainer implements Container { private String name; @Override - public void init(String[] args, String name, String configFile) throws ContainerException { + public void init(List ofbizCommands, String name, String configFile) throws ContainerException { this.name = name; this.configFile = configFile; } @@ -59,7 +61,7 @@ public class BirtContainer implements Container { throw new ContainerException("Unknown container config name"); } // get the container config - ContainerConfig.Container cc = ContainerConfig.getContainer(getName(), configFile); + ContainerConfig.Configuration cc = ContainerConfig.getConfiguration(getName(), configFile); if (cc == null) { throw new ContainerException("No " + getName() + " configuration found in container config!"); }