From 17a0a7a93ce717a9952abc28e48b1ee3c5d0cd98 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 12 Jul 2002 17:53:08 +0000 Subject: [PATCH] Cleaned up class quite a bit. Added -x parameter to specify port of XML-RPC server independently from RMI server port. --- src/helma/main/Server.java | 155 +++++++++++++++++++++---------------- 1 file changed, 89 insertions(+), 66 deletions(-) diff --git a/src/helma/main/Server.java b/src/helma/main/Server.java index ea8d4696..60f0c158 100644 --- a/src/helma/main/Server.java +++ b/src/helma/main/Server.java @@ -15,109 +15,131 @@ import helma.framework.*; import helma.framework.core.*; import helma.xmlrpc.*; import helma.util.*; +import Acme.Serve.Serve; /** * Helma server main class. */ - + public class Server implements IPathElement, Runnable { - public static final String version = "1.2pre3 2002/06/27"; - public static final long starttime = System.currentTimeMillis(); + public static final String version = "1.2pre4 2002/07/12"; + public long starttime; - public static boolean useTransactions = true; - public static boolean paranoid; - public static String dbFilename = "hop.db"; + // if true we only accept RMI and XML-RPC connections from + // explicitly listed hosts. + public boolean paranoid; private ApplicationManager appManager; - + private Vector extensions; - private Thread mainThread; + private Thread mainThread; - static String propfile; - static String dbPropfile = "db.properties"; - static String appsPropfile; + // server-wide properties static SystemProperties appsProps; static SystemProperties dbProps; static SystemProperties sysProps; - static int port = 5055; - static int webport = 0; - Acme.Serve.Serve websrv; + // server ports + int rmiPort = 5055; + int xmlrpcPort = 5056; + int websrvPort = 0; - static Hashtable dbSources; + // map of server-wide database sources + Hashtable dbSources; + // static server instance private static Server server; protected static File hopHome = null; + // our logger private static Logger logger; - protected static WebServer xmlrpc; + // the embedded web server + protected Serve websrv; + + // the XML-RPC server + protected WebServer xmlrpc; + + /** + * static main entry point. + */ public static void main (String args[]) throws IOException { // check if we are running on a Java 2 VM - otherwise exit with an error message - String jversion = System.getProperty ("java.version"); - if (jversion == null || jversion.startsWith ("1.1") || jversion.startsWith ("1.0")) { + String javaVersion = System.getProperty ("java.version"); + if (javaVersion == null || javaVersion.startsWith ("1.1") || javaVersion.startsWith ("1.0")) { System.err.println ("This version of Helma requires Java 1.2 or greater."); - if (jversion == null) // don't think this will ever happen, but you never know + if (javaVersion == null) // don't think this will ever happen, but you never know System.err.println ("Your Java Runtime did not provide a version number. Please update to a more recent version."); else - System.err.println ("Your Java Runtime is version "+jversion+". Please update to a more recent version."); - System.exit (1); + System.err.println ("Your Java Runtime is version "+javaVersion+". Please update to a more recent version."); + System.exit (1); } - + + // create new server instance + server = new Server (args); + } + + /** + * Constructs a new Server instance with an array of command line options. + */ + public Server (String[] args) { + + starttime = System.currentTimeMillis(); String homeDir = null; boolean usageError = false; - useTransactions = true; + // file names of various property files + String propfile = null; + String dbPropfile = "db.properties"; + String appsPropfile = null; + // parse arguments for (int i=0; i 0) { - websrv = new Acme.Serve.Serve (webport, sysProps); + if (websrvPort > 0) { + websrv = new Acme.Serve.Serve (websrvPort, sysProps); } - String xmlparser = sysProps.getProperty ("xmlparser"); + String xmlparser = sysProps.getProperty ("xmlparser"); if (xmlparser != null) XmlRpc.setDriver (xmlparser); // XmlRpc.setDebug (true); - xmlrpc = new WebServer (port+1); + xmlrpc = new WebServer (xmlrpcPort); if (paranoid) { xmlrpc.setParanoid (true); String xallow = sysProps.getProperty ("allowXmlRpc"); @@ -235,7 +259,7 @@ import helma.util.*; xmlrpc.acceptClient (st.nextToken ()); } } - getLogger().log ("Starting XML-RPC server on port "+(port+1)); + getLogger().log ("Starting XML-RPC server on port "+(xmlrpcPort)); // the following seems not to be necessary after all ... // System.setSecurityManager(new RMISecurityManager()); @@ -251,14 +275,13 @@ import helma.util.*; } if (websrv == null) { - getLogger().log ("Starting server on port "+port); - LocateRegistry.createRegistry (port); + getLogger().log ("Starting RMI server on port "+rmiPort); + LocateRegistry.createRegistry (rmiPort); } - // start application framework - appsProps = new SystemProperties (appsPropfile); - appManager = new ApplicationManager (port, hopHome, appsProps, this); + // create application manager + appManager = new ApplicationManager (rmiPort, hopHome, appsProps, this); } catch (Exception gx) { @@ -296,7 +319,7 @@ import helma.util.*; public Object[] getApplications () { return appManager.getApplications (); } - + /** * Get an Application by name */ @@ -326,22 +349,22 @@ import helma.util.*; /** * Get the Home directory of this server. */ - public static File getHopHome () { + public File getHopHome () { return hopHome; } - /** - * Get the main Server + /** + * Get the main Server instance. */ - public static Server getServer() { - return server; - } + public static Server getServer() { + return server; + } /** * Get the Server's XML-RPC web server. */ public static WebServer getXmlRpcServer() { - return xmlrpc; + return server.xmlrpc; } /** @@ -349,7 +372,7 @@ import helma.util.*; */ private void checkRunning () throws Exception { try { - java.net.Socket socket = new java.net.Socket ("localhost", port); + java.net.Socket socket = new java.net.Socket ("localhost", rmiPort); } catch (Exception x) { return; } @@ -357,15 +380,15 @@ import helma.util.*; throw new Exception ("Error: Server already running on this port"); } - public static String getProperty( String key ) { - return (String)sysProps.get(key); + public String getProperty( String key ) { + return (String)sysProps.get(key); } - - public static SystemProperties getProperties() { + + public SystemProperties getProperties() { return sysProps; } - public static File getAppsHome() { + public File getAppsHome() { String appHome = sysProps.getProperty ("appHome"); if (appHome != null && !"".equals (appHome.trim())) return new File (appHome); @@ -381,7 +404,7 @@ import helma.util.*; appManager.start (name); appManager.register (name); } - + public void stopApplication(String name) { appManager.stop (name); }