Cleaned up class quite a bit.
Added -x parameter to specify port of XML-RPC server independently from RMI server port.
This commit is contained in:
parent
010f71e201
commit
17a0a7a93c
1 changed files with 89 additions and 66 deletions
|
@ -15,109 +15,131 @@ import helma.framework.*;
|
||||||
import helma.framework.core.*;
|
import helma.framework.core.*;
|
||||||
import helma.xmlrpc.*;
|
import helma.xmlrpc.*;
|
||||||
import helma.util.*;
|
import helma.util.*;
|
||||||
|
import Acme.Serve.Serve;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helma server main class.
|
* Helma server main class.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Server implements IPathElement, Runnable {
|
public class Server implements IPathElement, Runnable {
|
||||||
|
|
||||||
public static final String version = "1.2pre3 2002/06/27";
|
public static final String version = "1.2pre4 2002/07/12";
|
||||||
public static final long starttime = System.currentTimeMillis();
|
public long starttime;
|
||||||
|
|
||||||
public static boolean useTransactions = true;
|
// if true we only accept RMI and XML-RPC connections from
|
||||||
public static boolean paranoid;
|
// explicitly listed hosts.
|
||||||
public static String dbFilename = "hop.db";
|
public boolean paranoid;
|
||||||
|
|
||||||
private ApplicationManager appManager;
|
private ApplicationManager appManager;
|
||||||
|
|
||||||
private Vector extensions;
|
private Vector extensions;
|
||||||
|
|
||||||
private Thread mainThread;
|
private Thread mainThread;
|
||||||
|
|
||||||
static String propfile;
|
// server-wide properties
|
||||||
static String dbPropfile = "db.properties";
|
|
||||||
static String appsPropfile;
|
|
||||||
static SystemProperties appsProps;
|
static SystemProperties appsProps;
|
||||||
static SystemProperties dbProps;
|
static SystemProperties dbProps;
|
||||||
static SystemProperties sysProps;
|
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;
|
private static Server server;
|
||||||
|
|
||||||
protected static File hopHome = null;
|
protected static File hopHome = null;
|
||||||
|
|
||||||
|
// our logger
|
||||||
private static Logger 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 {
|
public static void main (String args[]) throws IOException {
|
||||||
|
|
||||||
// check if we are running on a Java 2 VM - otherwise exit with an error message
|
// check if we are running on a Java 2 VM - otherwise exit with an error message
|
||||||
String jversion = System.getProperty ("java.version");
|
String javaVersion = System.getProperty ("java.version");
|
||||||
if (jversion == null || jversion.startsWith ("1.1") || jversion.startsWith ("1.0")) {
|
if (javaVersion == null || javaVersion.startsWith ("1.1") || javaVersion.startsWith ("1.0")) {
|
||||||
System.err.println ("This version of Helma requires Java 1.2 or greater.");
|
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.");
|
System.err.println ("Your Java Runtime did not provide a version number. Please update to a more recent version.");
|
||||||
else
|
else
|
||||||
System.err.println ("Your Java Runtime is version "+jversion+". Please update to a more recent version.");
|
System.err.println ("Your Java Runtime is version "+javaVersion+". Please update to a more recent version.");
|
||||||
System.exit (1);
|
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;
|
String homeDir = null;
|
||||||
|
|
||||||
boolean usageError = false;
|
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<args.length; i++) {
|
for (int i=0; i<args.length; i++) {
|
||||||
if (args[i].equals ("-h") && i+1<args.length)
|
if (args[i].equals ("-h") && i+1<args.length)
|
||||||
homeDir = args[++i];
|
homeDir = args[++i];
|
||||||
else if (args[i].equals ("-f") && i+1<args.length)
|
else if (args[i].equals ("-f") && i+1<args.length)
|
||||||
propfile = args[++i];
|
propfile = args[++i];
|
||||||
else if (args[i].equals ("-t"))
|
|
||||||
useTransactions = false;
|
|
||||||
else if (args[i].equals ("-p") && i+1<args.length) {
|
else if (args[i].equals ("-p") && i+1<args.length) {
|
||||||
try {
|
try {
|
||||||
port = Integer.parseInt (args[++i]);
|
rmiPort = Integer.parseInt (args[++i]);
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
usageError = true;
|
usageError = true;
|
||||||
|
}
|
||||||
|
} else if (args[i].equals ("-x") && i+1<args.length) {
|
||||||
|
try {
|
||||||
|
xmlrpcPort = Integer.parseInt (args[++i]);
|
||||||
|
} catch (Exception portx) {
|
||||||
|
usageError = true;
|
||||||
}
|
}
|
||||||
} else if (args[i].equals ("-w") && i+1<args.length) {
|
} else if (args[i].equals ("-w") && i+1<args.length) {
|
||||||
try {
|
try {
|
||||||
webport = Integer.parseInt (args[++i]);
|
websrvPort = Integer.parseInt (args[++i]);
|
||||||
} catch (Exception portx) {
|
} catch (Exception portx) {
|
||||||
usageError = true;
|
usageError = true;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
usageError = true;
|
usageError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usageError ) {
|
if (usageError ) {
|
||||||
System.out.println ("usage: java helma.objectmodel.db.Server [-h dir] [-f file] [-p port] [-w port] [-t]");
|
System.out.println ("usage: java helma.objectmodel.db.Server [-h dir] [-f file] [-p port] [-w port] [-x port]");
|
||||||
System.out.println (" -h dir Specify hop home directory");
|
System.out.println (" -h dir Specify hop home directory");
|
||||||
System.out.println (" -f file Specify server.properties file");
|
System.out.println (" -f file Specify server.properties file");
|
||||||
System.out.println (" -p port Specify TCP port number");
|
System.out.println (" -p port Specify RMI port number");
|
||||||
System.out.println (" -w port Start embedded Web server on that port");
|
System.out.println (" -w port Specify port number for embedded Web server");
|
||||||
System.out.println (" -t Disable Berkeley DB Transactions");
|
System.out.println (" -x port Specify XML-RPC port number");
|
||||||
getLogger().log ("Usage Error - exiting");
|
getLogger().log ("Usage Error - exiting");
|
||||||
System.exit (0);
|
System.exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
server = new Server (homeDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Server (String home) {
|
|
||||||
|
|
||||||
String homeDir = home;
|
|
||||||
|
|
||||||
// get main property file from home dir or vice versa, depending on what we have.
|
// get main property file from home dir or vice versa, depending on what we have.
|
||||||
// get property file from hopHome
|
// get property file from hopHome
|
||||||
if (propfile == null) {
|
if (propfile == null) {
|
||||||
|
@ -126,8 +148,9 @@ import helma.util.*;
|
||||||
else
|
else
|
||||||
propfile = new File ("server.properties").getAbsolutePath ();
|
propfile = new File ("server.properties").getAbsolutePath ();
|
||||||
}
|
}
|
||||||
|
// create system properties
|
||||||
sysProps = new SystemProperties (propfile);
|
sysProps = new SystemProperties (propfile);
|
||||||
|
|
||||||
// get hopHome from property file
|
// get hopHome from property file
|
||||||
if (homeDir == null)
|
if (homeDir == null)
|
||||||
homeDir = sysProps.getProperty ("hophome");
|
homeDir = sysProps.getProperty ("hophome");
|
||||||
|
@ -157,6 +180,7 @@ import helma.util.*;
|
||||||
else
|
else
|
||||||
helper = new File (hopHome, "apps.properties");
|
helper = new File (hopHome, "apps.properties");
|
||||||
appsPropfile = helper.getAbsolutePath ();
|
appsPropfile = helper.getAbsolutePath ();
|
||||||
|
appsProps = new SystemProperties (appsPropfile);
|
||||||
getLogger().log ("appsPropfile = "+appsPropfile);
|
getLogger().log ("appsPropfile = "+appsPropfile);
|
||||||
|
|
||||||
paranoid = "true".equalsIgnoreCase (sysProps.getProperty ("paranoid"));
|
paranoid = "true".equalsIgnoreCase (sysProps.getProperty ("paranoid"));
|
||||||
|
@ -217,15 +241,15 @@ import helma.util.*;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// start embedded web server if port is specified
|
// start embedded web server if port is specified
|
||||||
if (webport > 0) {
|
if (websrvPort > 0) {
|
||||||
websrv = new Acme.Serve.Serve (webport, sysProps);
|
websrv = new Acme.Serve.Serve (websrvPort, sysProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
String xmlparser = sysProps.getProperty ("xmlparser");
|
String xmlparser = sysProps.getProperty ("xmlparser");
|
||||||
if (xmlparser != null)
|
if (xmlparser != null)
|
||||||
XmlRpc.setDriver (xmlparser);
|
XmlRpc.setDriver (xmlparser);
|
||||||
// XmlRpc.setDebug (true);
|
// XmlRpc.setDebug (true);
|
||||||
xmlrpc = new WebServer (port+1);
|
xmlrpc = new WebServer (xmlrpcPort);
|
||||||
if (paranoid) {
|
if (paranoid) {
|
||||||
xmlrpc.setParanoid (true);
|
xmlrpc.setParanoid (true);
|
||||||
String xallow = sysProps.getProperty ("allowXmlRpc");
|
String xallow = sysProps.getProperty ("allowXmlRpc");
|
||||||
|
@ -235,7 +259,7 @@ import helma.util.*;
|
||||||
xmlrpc.acceptClient (st.nextToken ());
|
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 ...
|
// the following seems not to be necessary after all ...
|
||||||
// System.setSecurityManager(new RMISecurityManager());
|
// System.setSecurityManager(new RMISecurityManager());
|
||||||
|
@ -251,14 +275,13 @@ import helma.util.*;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (websrv == null) {
|
if (websrv == null) {
|
||||||
getLogger().log ("Starting server on port "+port);
|
getLogger().log ("Starting RMI server on port "+rmiPort);
|
||||||
LocateRegistry.createRegistry (port);
|
LocateRegistry.createRegistry (rmiPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// start application framework
|
// create application manager
|
||||||
appsProps = new SystemProperties (appsPropfile);
|
appManager = new ApplicationManager (rmiPort, hopHome, appsProps, this);
|
||||||
appManager = new ApplicationManager (port, hopHome, appsProps, this);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception gx) {
|
} catch (Exception gx) {
|
||||||
|
@ -296,7 +319,7 @@ import helma.util.*;
|
||||||
public Object[] getApplications () {
|
public Object[] getApplications () {
|
||||||
return appManager.getApplications ();
|
return appManager.getApplications ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an Application by name
|
* Get an Application by name
|
||||||
*/
|
*/
|
||||||
|
@ -326,22 +349,22 @@ import helma.util.*;
|
||||||
/**
|
/**
|
||||||
* Get the Home directory of this server.
|
* Get the Home directory of this server.
|
||||||
*/
|
*/
|
||||||
public static File getHopHome () {
|
public File getHopHome () {
|
||||||
return hopHome;
|
return hopHome;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the main Server
|
* Get the main Server instance.
|
||||||
*/
|
*/
|
||||||
public static Server getServer() {
|
public static Server getServer() {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Server's XML-RPC web server.
|
* Get the Server's XML-RPC web server.
|
||||||
*/
|
*/
|
||||||
public static WebServer getXmlRpcServer() {
|
public static WebServer getXmlRpcServer() {
|
||||||
return xmlrpc;
|
return server.xmlrpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -349,7 +372,7 @@ import helma.util.*;
|
||||||
*/
|
*/
|
||||||
private void checkRunning () throws Exception {
|
private void checkRunning () throws Exception {
|
||||||
try {
|
try {
|
||||||
java.net.Socket socket = new java.net.Socket ("localhost", port);
|
java.net.Socket socket = new java.net.Socket ("localhost", rmiPort);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -357,15 +380,15 @@ import helma.util.*;
|
||||||
throw new Exception ("Error: Server already running on this port");
|
throw new Exception ("Error: Server already running on this port");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProperty( String key ) {
|
public String getProperty( String key ) {
|
||||||
return (String)sysProps.get(key);
|
return (String)sysProps.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SystemProperties getProperties() {
|
public SystemProperties getProperties() {
|
||||||
return sysProps;
|
return sysProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getAppsHome() {
|
public File getAppsHome() {
|
||||||
String appHome = sysProps.getProperty ("appHome");
|
String appHome = sysProps.getProperty ("appHome");
|
||||||
if (appHome != null && !"".equals (appHome.trim()))
|
if (appHome != null && !"".equals (appHome.trim()))
|
||||||
return new File (appHome);
|
return new File (appHome);
|
||||||
|
@ -381,7 +404,7 @@ import helma.util.*;
|
||||||
appManager.start (name);
|
appManager.start (name);
|
||||||
appManager.register (name);
|
appManager.register (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopApplication(String name) {
|
public void stopApplication(String name) {
|
||||||
appManager.stop (name);
|
appManager.stop (name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue