svn commit: r1765127 [2/2] - in /ofbiz/trunk: framework/base/src/main/java/org/apache/ofbiz/base/component/ framework/base/src/main/java/org/apache/ofbiz/base/container/ framework/base/src/main/java/org/apache/ofbiz/base/lang/ framework/base/src/main/j...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1765127 [2/2] - in /ofbiz/trunk: framework/base/src/main/java/org/apache/ofbiz/base/component/ framework/base/src/main/java/org/apache/ofbiz/base/container/ framework/base/src/main/java/org/apache/ofbiz/base/lang/ framework/base/src/main/j...

Taher Alkhateeb
Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupControlPanel.java Sun Oct 16 09:07:08 2016
@@ -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> serverState,
             List<StartupCommand> ofbizCommands) throws StartupException {
 
-        List<StartupLoader> loaders = new ArrayList<StartupLoader>();
-        List<String> 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<StartupLoader> loaders, AtomicReference<ServerState> serverState, Thread adminServer) {
-        shutdownServer(loaders, serverState, adminServer);
+    static void stop(StartupLoader loader, AtomicReference<ServerState> 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<StartupLoader> loaders, AtomicReference<ServerState> serverState, Thread adminServer) {
+    private static void shutdownServer(StartupLoader loader, AtomicReference<ServerState> 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> serverState,
-            List<StartupLoader> 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<StartupLoader> loaders,
+            StartupLoader loader,
             AtomicReference<ServerState> 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<StartupLoader> loaders,
-            List<String> loaderArgs,
-            AtomicReference<ServerState> serverState,
-            NativeLibClassLoader classloader) throws StartupException {
-
-        String[] argsArray = loaderArgs.toArray(new String[loaderArgs.size()]);
-        synchronized (loaders) {
-            for (Map<String, String> 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<StartupLoader> loaders,
+    private static void executeStartupLoadSequence(Config config,
+            StartupLoader loader,
+            List<StartupCommand> ofbizCommands,
             AtomicReference<ServerState> 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<StartupLoader> loaders,
+            StartupLoader loader,
             AtomicReference<ServerState> serverState,
             Thread adminServer) {
 
         if (config.shutdownAfterLoad) {
-            stop(loaders, serverState, adminServer);
+            stop(loader, serverState, adminServer);
         }
     }
 }

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupLoader.java Sun Oct 16 09:07:08 2016
@@ -18,6 +18,8 @@
  *******************************************************************************/
 package org.apache.ofbiz.base.start;
 
+import java.util.List;
+
 /**
  * An object that loads server startup classes.
  * <p>
@@ -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<StartupCommand> ofbizCommands) throws StartupException;
 
     /**
      * Stop the startup class. This method must not block.

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/load-data.properties Sun Oct 16 09:07:08 2016
@@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=frame
 #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

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/rmi.properties Sun Oct 16 09:07:08 2016
@@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=frame
 #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

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/start.properties Sun Oct 16 09:07:08 2016
@@ -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

Modified: ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties (original)
+++ ofbiz/trunk/framework/start/src/main/java/org/apache/ofbiz/base/start/test.properties Sun Oct 16 09:07:08 2016
@@ -30,8 +30,8 @@ ofbiz.start.classpath.addComponent=frame
 #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

Modified: ofbiz/trunk/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java (original)
+++ ofbiz/trunk/framework/testtools/src/main/java/org/apache/ofbiz/testtools/TestRunContainer.java Sun Oct 16 09:07:08 2016
@@ -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.opt
 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
     private String name;
 
     @Override
-    public void init(String[] args, String name, String configFile) {
+    public void init(List<StartupCommand> 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) {

Modified: ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java (original)
+++ ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/artifactinfo/RunTestEvents.java Sun Oct 16 09:07:08 2016
@@ -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<StartupCommand> ofbizCommands = new ArrayList<StartupCommand>();
         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;
     }
 }
-

Modified: ofbiz/trunk/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java?rev=1765127&r1=1765126&r2=1765127&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java (original)
+++ ofbiz/trunk/specialpurpose/birt/src/main/java/org/apache/ofbiz/birt/container/BirtContainer.java Sun Oct 16 09:07:08 2016
@@ -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.ap
 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 Co
     private String name;
 
     @Override
-    public void init(String[] args, String name, String configFile) throws ContainerException {
+    public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException {
         this.name = name;
         this.configFile = configFile;
     }
@@ -59,7 +61,7 @@ public class BirtContainer implements Co
             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!");
         }