r9817 - in helma/helma/trunk: . src/helma/main

[email protected] Fri, 29 May 2009 17:06:14 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090529150614.76C8E3D0E3@mia>
Author: hannes
Date: 2009-05-29 17:06:14 +0200 (Fri, 29 May 2009)
New Revision: 9817

Modified:
   helma/helma/trunk/src/helma/main/ApplicationManager.java
   helma/helma/trunk/src/helma/main/JettyServer.java
   helma/helma/trunk/src/helma/main/Server.java
   helma/helma/trunk/src/helma/main/ServerConfig.java
   helma/helma/trunk/start.bat
   helma/helma/trunk/start.sh
Log:
Implement -a switch to helma launcher that allows to explicitly list applications to start, overriding the apps.properties file (application settings in the apps.properties file are still honored, though). Adapt start scripts to pass though additional arguments.

Details at http://dev.helma.org/trac/helma/changeset/9817

Modified: helma/helma/trunk/src/helma/main/ApplicationManager.java
===================================================================
--- helma/helma/trunk/src/helma/main/ApplicationManager.java	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/src/helma/main/ApplicationManager.java	2009-05-29 15:06:14 UTC (rev 9817)
@@ -79,7 +79,7 @@
      * to create and start new applications.
      */
     protected void checkForChanges() {
-        if (props.lastModified() > lastModified) {
+        if (props.lastModified() > lastModified && server.getApplicationsOption() == null) {
             try {
                 for (Enumeration e = props.keys(); e.hasMoreElements();) {
                     String appName = (String) e.nextElement();
@@ -152,18 +152,26 @@
      */
     public void startAll() {
         try {
-            for (Enumeration e = props.keys(); e.hasMoreElements();) {
-                String appName = (String) e.nextElement();
+            String[] apps = server.getApplicationsOption();
+            if (apps != null) {
+                for (int i = 0; i < apps.length; i++) {
+                    AppDescriptor desc = new AppDescriptor(apps[i]);
+                    desc.start();
+                }
+            } else {
+                for (Enumeration e = props.keys(); e.hasMoreElements();) {
+                    String appName = (String) e.nextElement();
 
-                if (appName.indexOf(".") == -1) {
-                    String appValue = props.getProperty(appName);
+                    if (appName.indexOf(".") == -1) {
+                        String appValue = props.getProperty(appName);
 
-                    if (appValue != null && appValue.length() > 0) {
-                        appName = appValue;
+                        if (appValue != null && appValue.length() > 0) {
+                            appName = appValue;
+                        }
+
+                        AppDescriptor desc = new AppDescriptor(appName);
+                        desc.start();
                     }
-
-                    AppDescriptor desc = new AppDescriptor(appName);
-                    desc.start();
                 }
             }
 

Modified: helma/helma/trunk/src/helma/main/JettyServer.java
===================================================================
--- helma/helma/trunk/src/helma/main/JettyServer.java	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/src/helma/main/JettyServer.java	2009-05-29 15:06:14 UTC (rev 9817)
@@ -27,6 +27,7 @@
 import java.net.URL;
 import java.net.InetSocketAddress;
 import java.io.IOException;
+import java.io.File;
 
 public class JettyServer {
 
@@ -36,11 +37,12 @@
     // the AJP13 Listener, used for connecting from external webserver to servlet via JK
     protected AJP13Listener ajp13;
 
-    public static JettyServer init(Server server) throws IOException {
-        if (server.configFile != null && server.configFile.exists()) {
-            return new JettyServer(server.configFile.toURI().toURL());
-        } else if (server.websrvPort != null || server.ajp13Port != null) {
-            return new JettyServer(server.websrvPort, server.ajp13Port, server);
+    public static JettyServer init(Server server, ServerConfig config) throws IOException {
+        File configFile = config.getConfigFile();
+        if (configFile != null && configFile.exists()) {
+            return new JettyServer(configFile.toURI().toURL());
+        } else if (config.hasWebsrvPort() || config.hasAjp13Port()) {
+            return new JettyServer(config.getWebsrvPort(), config.getAjp13Port(), server);
         }
         return null;
     }

Modified: helma/helma/trunk/src/helma/main/Server.java
===================================================================
--- helma/helma/trunk/src/helma/main/Server.java	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/src/helma/main/Server.java	2009-05-29 15:06:14 UTC (rev 9817)
@@ -66,15 +66,9 @@
     private Vector extensions;
     private Thread mainThread;
 
-    // server ports
-    InetSocketAddress rmiPort = null;
-    InetSocketAddress xmlrpcPort = null;
-    InetSocketAddress websrvPort = null;
-    InetSocketAddress ajp13Port = null;
+    // configuration
+    ServerConfig config;
 
-    // Jetty configuration file
-    File configFile = null;
-    
     // map of server-wide database sources
     Hashtable dbSources;
 
@@ -97,12 +91,11 @@
         server = this;
         starttime = System.currentTimeMillis();
 
-        rmiPort    = config.getRmiPort();
-        xmlrpcPort = config.getXmlrpcPort();
-        websrvPort = config.getWebsrvPort();
-        ajp13Port  = config.getAjp13Port();
+        this.config = config;
         hopHome    = config.getHomeDir();
-        configFile = config.getConfigFile();
+        if (hopHome == null) {
+            throw new RuntimeException("helma.home property not set");
+        }
 
         // create system properties
         sysProps = new ResourceProperties();
@@ -243,6 +236,8 @@
                 config.setHomeDir(new File(args[++i]));
             } else if (args[i].equals("-f") && ((i + 1) < args.length)) {
                 config.setPropFile(new File(args[++i]));
+            } else if (args[i].equals("-a") && ((i + 1) < args.length)) {
+                config.setApps(StringUtils.split(args[++i]));
             } else if (args[i].equals("-p") && ((i + 1) < args.length)) {
                 try {
                     config.setRmiPort(getInetSocketAddress(args[++i]));
@@ -333,8 +328,9 @@
         System.out.println("");
         System.out.println("Usage: java helma.main.Server [options]");
         System.out.println("Possible options:");
-        System.out.println("  -h dir       Specify hop home directory");
-        System.out.println("  -f file      Specify server.properties file");
+        System.out.println("  -a app[,...]      Specify applications to start");
+        System.out.println("  -h dir            Specify hop home directory");
+        System.out.println("  -f file           Specify server.properties file");
         System.out.println("  -c jetty.xml      Specify Jetty XML configuration file");
         System.out.println("  -w [ip:]port      Specify embedded web server address/port");
         System.out.println("  -x [ip:]port      Specify XML-RPC address/port");
@@ -478,7 +474,7 @@
         if (sysProps.getProperty("extensions") != null) {
             initExtensions();
         }
-        jetty = JettyServer.init(this);
+        jetty = JettyServer.init(this, config);
     }
 
 
@@ -562,7 +558,8 @@
      */
     public void run() {
         try {
-            if (xmlrpcPort != null) {
+            if (config.hasXmlrpcPort()) {
+                InetSocketAddress xmlrpcPort = config.getXmlrpcPort();
                 String xmlparser = sysProps.getProperty("xmlparser");
 
                 if (xmlparser != null) {
@@ -591,7 +588,8 @@
                 logger.info("Starting XML-RPC server on port " + (xmlrpcPort));
             }
 
-            if (rmiPort != null) {
+            if (config.hasRmiPort()) {
+                InetSocketAddress rmiPort = config.getRmiPort();
                 if (paranoid) {
                     HelmaSocketFactory factory = new HelmaSocketFactory();
                     String rallow = sysProps.getProperty("allowWeb");
@@ -732,6 +730,14 @@
     }
 
     /**
+     * Get the explicit list of apps if started with -a option
+     * @return
+     */
+    public String[] getApplicationsOption() {
+        return config.getApps();
+    }
+
+    /**
      * Get the main Server instance.
      */
     public static Server getServer() {

Modified: helma/helma/trunk/src/helma/main/ServerConfig.java
===================================================================
--- helma/helma/trunk/src/helma/main/ServerConfig.java	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/src/helma/main/ServerConfig.java	2009-05-29 15:06:14 UTC (rev 9817)
@@ -32,11 +32,16 @@
     private File propFile   = null;
     private File homeDir    = null;
     private File configFile = null;
+    private String[] apps = null;
 
     public boolean hasPropFile() {
         return (propFile != null);
     }
 
+    public boolean hasConfigFile() {
+        return (configFile != null);
+    }
+
     public boolean hasHomeDir() {
         return (homeDir != null);
     }
@@ -57,6 +62,10 @@
         return (ajp13Port != null);
     }
 
+    public boolean hasApps() {
+        return (apps != null);
+    }
+
     public InetSocketAddress getRmiPort() {
         return rmiPort;
     }
@@ -112,4 +121,12 @@
 	public void setConfigFile(File configFile) {
 		this.configFile = configFile == null ? null : configFile.getAbsoluteFile();
 	}
+
+    public String[] getApps() {
+        return apps;
+    }
+
+    public void setApps(String[] apps) {
+        this.apps = apps;
+    }
 }

Modified: helma/helma/trunk/start.bat
===================================================================
--- helma/helma/trunk/start.bat	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/start.bat	2009-05-29 15:06:14 UTC (rev 9817)
@@ -76,4 +76,4 @@
 )
 
 :: Invoking the Java virtual machine
-%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS%
+%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS% %*

Modified: helma/helma/trunk/start.sh
===================================================================
--- helma/helma/trunk/start.sh	2009-05-29 13:47:15 UTC (rev 9816)
+++ helma/helma/trunk/start.sh	2009-05-29 15:06:14 UTC (rev 9817)
@@ -75,4 +75,4 @@
 fi
 
 # Invoke the Java VM
-$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES
+$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES $*