* Make Server.getAppsProperties() return the whole properties if appName argument is null.

* Code cleanup: make ServerConfig fields private and add getters and setters.
This commit is contained in:
hns 2008-04-04 11:44:29 +00:00
parent 35ed7a58f8
commit a96a4444a6
3 changed files with 128 additions and 55 deletions

View file

@ -45,15 +45,15 @@ public class CommandlineRunner {
// get possible environment setting for helma home // get possible environment setting for helma home
if (System.getProperty("helma.home")!=null) { if (System.getProperty("helma.home")!=null) {
config.homeDir = new File(System.getProperty("helma.home")); config.setHomeDir(new File(System.getProperty("helma.home")));
} }
// parse arguments // 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)) {
config.homeDir = new File(args[++i]); config.setHomeDir(new File(args[++i]));
} else if (args[i].equals("-f") && ((i + 1) < args.length)) { } else if (args[i].equals("-f") && ((i + 1) < args.length)) {
config.propFile = new File(args[++i]); config.setPropFile(new File(args[++i]));
} else if (commandStr != null) { } else if (commandStr != null) {
// we're past the command str, all args for the function // we're past the command str, all args for the function
funcArgs.add (args[i]); funcArgs.add (args[i]);

View file

@ -32,6 +32,11 @@ import java.io.*;
import java.rmi.registry.*; import java.rmi.registry.*;
import java.rmi.server.*; import java.rmi.server.*;
import java.util.*; import java.util.*;
import java.net.Socket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.InetSocketAddress;
import helma.util.ResourceProperties; import helma.util.ResourceProperties;
/** /**
@ -96,15 +101,15 @@ public class Server implements Runnable {
server = this; server = this;
starttime = System.currentTimeMillis(); starttime = System.currentTimeMillis();
rmiPort = config.rmiPort; rmiPort = config.getRmiPort();
xmlrpcPort = config.xmlrpcPort; xmlrpcPort = config.getXmlrpcPort();
websrvPort = config.websrvPort; websrvPort = config.getWebsrvPort();
ajp13Port = config.ajp13Port; ajp13Port = config.getAjp13Port();
hopHome = config.homeDir; hopHome = config.getHomeDir();
// create system properties // create system properties
sysProps = new ResourceProperties(); sysProps = new ResourceProperties();
sysProps.addResource(new FileResource(config.propFile)); sysProps.addResource(new FileResource(config.getPropFile()));
} }
@ -171,7 +176,7 @@ public class Server implements Runnable {
// get possible environment setting for helma home // get possible environment setting for helma home
if (System.getProperty("helma.home")!=null) { if (System.getProperty("helma.home")!=null) {
config.homeDir = new File(System.getProperty("helma.home")); config.setHomeDir(new File(System.getProperty("helma.home")));
} }
parseArgs(config, args); parseArgs(config, args);
@ -180,36 +185,36 @@ public class Server implements Runnable {
// create system properties // create system properties
ResourceProperties sysProps = new ResourceProperties(); ResourceProperties sysProps = new ResourceProperties();
sysProps.addResource(new FileResource(config.propFile)); sysProps.addResource(new FileResource(config.getPropFile()));
// check if there's a property setting for those ports not specified via command line // check if there's a property setting for those ports not specified via command line
if ((config.websrvPort == null) && (sysProps.getProperty("webPort") != null)) { if (!config.hasWebsrvPort() && sysProps.getProperty("webPort") != null) {
try { try {
config.websrvPort = new InetAddrPort(sysProps.getProperty("webPort")); config.setWebsrvPort(new InetAddrPort(sysProps.getProperty("webPort")));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing web server port property from server.properties: " + portx); throw new Exception("Error parsing web server port property from server.properties: " + portx);
} }
} }
if ((config.ajp13Port == null) && (sysProps.getProperty("ajp13Port") != null)) { if (!config.hasAjp13Port() && sysProps.getProperty("ajp13Port") != null) {
try { try {
config.ajp13Port = new InetAddrPort(sysProps.getProperty("ajp13Port")); config.setAjp13Port(new InetAddrPort(sysProps.getProperty("ajp13Port")));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing AJP1.3 server port property from server.properties: " + portx); throw new Exception("Error parsing AJP1.3 server port property from server.properties: " + portx);
} }
} }
if ((config.rmiPort == null) && (sysProps.getProperty("rmiPort") != null)) { if (!config.hasRmiPort() && sysProps.getProperty("rmiPort") != null) {
try { try {
config.rmiPort = new InetAddrPort(sysProps.getProperty("rmiPort")); config.setRmiPort(new InetAddrPort(sysProps.getProperty("rmiPort")));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing RMI server port property from server.properties: " + portx); throw new Exception("Error parsing RMI server port property from server.properties: " + portx);
} }
} }
if ((config.xmlrpcPort == null) && (sysProps.getProperty("xmlrpcPort") != null)) { if (!config.hasXmlrpcPort() && sysProps.getProperty("xmlrpcPort") != null) {
try { try {
config.xmlrpcPort = new InetAddrPort(sysProps.getProperty("xmlrpcPort")); config.setXmlrpcPort(new InetAddrPort(sysProps.getProperty("xmlrpcPort")));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing XML-RPC server port property from server.properties: " + portx); throw new Exception("Error parsing XML-RPC server port property from server.properties: " + portx);
} }
@ -227,30 +232,30 @@ public class Server implements Runnable {
public static void parseArgs(ServerConfig config, String[] args) throws Exception { public static void parseArgs(ServerConfig config, String[] args) throws Exception {
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)) {
config.homeDir = new File(args[++i]); config.setHomeDir(new File(args[++i]));
} else if (args[i].equals("-f") && ((i + 1) < args.length)) { } else if (args[i].equals("-f") && ((i + 1) < args.length)) {
config.propFile = new File(args[++i]); config.setPropFile(new File(args[++i]));
} else if (args[i].equals("-p") && ((i + 1) < args.length)) { } else if (args[i].equals("-p") && ((i + 1) < args.length)) {
try { try {
config.rmiPort = new InetAddrPort(args[++i]); config.setRmiPort(new InetAddrPort(args[++i]));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing RMI server port property: " + portx); throw new Exception("Error parsing RMI server port property: " + portx);
} }
} else if (args[i].equals("-x") && ((i + 1) < args.length)) { } else if (args[i].equals("-x") && ((i + 1) < args.length)) {
try { try {
config.xmlrpcPort = new InetAddrPort(args[++i]); config.setXmlrpcPort(new InetAddrPort(args[++i]));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing XML-RPC server port property: " + portx); throw new Exception("Error parsing XML-RPC server port property: " + portx);
} }
} else if (args[i].equals("-w") && ((i + 1) < args.length)) { } else if (args[i].equals("-w") && ((i + 1) < args.length)) {
try { try {
config.websrvPort = new InetAddrPort(args[++i]); config.setWebsrvPort(new InetAddrPort(args[++i]));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing web server port property: " + portx); throw new Exception("Error parsing web server port property: " + portx);
} }
} else if (args[i].equals("-jk") && ((i + 1) < args.length)) { } else if (args[i].equals("-jk") && ((i + 1) < args.length)) {
try { try {
config.ajp13Port = new InetAddrPort(args[++i]); config.setAjp13Port(new InetAddrPort(args[++i]));
} catch (Exception portx) { } catch (Exception portx) {
throw new Exception("Error parsing AJP1.3 server port property: " + portx); throw new Exception("Error parsing AJP1.3 server port property: " + portx);
} }
@ -270,26 +275,26 @@ public class Server implements Runnable {
*/ */
public static void guessConfig(ServerConfig config) throws Exception { public static void guessConfig(ServerConfig config) throws Exception {
// get property file from hopHome: // get property file from hopHome:
if (config.propFile == null) { if (!config.hasPropFile()) {
if (config.homeDir != null) { if (config.hasHomeDir()) {
config.propFile = new File(config.homeDir, "server.properties"); config.setPropFile(new File(config.getHomeDir(), "server.properties"));
} else { } else {
config.propFile = new File("server.properties"); config.setPropFile(new File("server.properties"));
} }
} }
// create system properties // create system properties
ResourceProperties sysProps = new ResourceProperties(); ResourceProperties sysProps = new ResourceProperties();
sysProps.addResource(new FileResource(config.propFile)); sysProps.addResource(new FileResource(config.getPropFile()));
// try to get hopHome from property file // try to get hopHome from property file
if (config.homeDir == null && sysProps.getProperty("hophome") != null) { if (!config.hasHomeDir() && sysProps.getProperty("hophome") != null) {
config.homeDir = new File(sysProps.getProperty("hophome")); config.setHomeDir(new File(sysProps.getProperty("hophome")));
} }
// use the directory where server.properties is located: // use the directory where server.properties is located:
if (config.homeDir == null && config.propFile != null) { if (!config.hasHomeDir() && config.hasPropFile()) {
config.homeDir = config.propFile.getAbsoluteFile().getParentFile(); config.setHomeDir(config.getPropFile().getAbsoluteFile().getParentFile());
} }
if (!config.hasPropFile()) { if (!config.hasPropFile()) {
@ -302,9 +307,9 @@ public class Server implements Runnable {
// try to transform hopHome directory to its canonical representation // try to transform hopHome directory to its canonical representation
try { try {
config.homeDir = config.homeDir.getCanonicalFile(); config.setHomeDir(config.getHomeDir().getCanonicalFile());
} catch (IOException iox) { } catch (IOException iox) {
config.homeDir = config.homeDir.getAbsoluteFile(); config.setHomeDir(config.getHomeDir().getAbsoluteFile());
} }
} }
@ -350,20 +355,20 @@ public class Server implements Runnable {
public static void checkRunning(ServerConfig config) { public static void checkRunning(ServerConfig config) {
// check if any of the specified server ports is in use already // check if any of the specified server ports is in use already
try { try {
if (config.websrvPort != null) { if (config.hasWebsrvPort()) {
checkPort(config.websrvPort); checkPort(config.getWebsrvPort());
} }
if (config.rmiPort != null) { if (config.hasRmiPort()) {
checkPort(config.rmiPort); checkPort(config.getRmiPort());
} }
if (config.xmlrpcPort != null) { if (config.hasXmlrpcPort()) {
checkPort(config.xmlrpcPort); checkPort(config.getXmlrpcPort());
} }
if (config.ajp13Port != null) { if (config.hasAjp13Port()) {
checkPort(config.ajp13Port); checkPort(config.getAjp13Port());
} }
} catch (Exception running) { } catch (Exception running) {
System.out.println(running.getMessage()); System.out.println(running.getMessage());
@ -379,8 +384,6 @@ public class Server implements Runnable {
private static void checkPort(InetAddrPort addrPort) throws Exception { private static void checkPort(InetAddrPort addrPort) throws Exception {
// checkRunning is disabled until we find a fix for the socket creation // checkRunning is disabled until we find a fix for the socket creation
// timeout problems reported on the list. // timeout problems reported on the list.
return;
/* /*
InetAddress addr = addrPort.getInetAddress(); InetAddress addr = addrPort.getInetAddress();
if (addr == null) { if (addr == null) {
@ -392,8 +395,11 @@ public class Server implements Runnable {
} }
} }
try { try {
new Socket(addr, addrPort.getPort()); Socket sock = new Socket();
} catch (IOException x) { // this should fix the timeout problems reported here:
// http://grazia.helma.at/pipermail/helma-user/2003-December/005602.html
sock.connect(new InetSocketAddress(addr, addrPort.getPort()), 1000);
} catch (Exception x) {
// we couldn't connect to the socket because no server // we couldn't connect to the socket because no server
// is running on it yet. Everything's ok. // is running on it yet. Everything's ok.
return; return;
@ -821,7 +827,11 @@ public class Server implements Runnable {
* @return the apps.properties subproperties for the given app * @return the apps.properties subproperties for the given app
*/ */
public ResourceProperties getAppsProperties(String appName) { public ResourceProperties getAppsProperties(String appName) {
return appsProps.getSubProperties(appName + "."); if (appName == null) {
return appsProps;
} else {
return appsProps.getSubProperties(appName + ".");
}
} }
/** /**

View file

@ -25,12 +25,12 @@ import java.io.File;
public class ServerConfig { public class ServerConfig {
InetAddrPort rmiPort = null; private InetAddrPort rmiPort = null;
InetAddrPort xmlrpcPort = null; private InetAddrPort xmlrpcPort = null;
InetAddrPort websrvPort = null; private InetAddrPort websrvPort = null;
InetAddrPort ajp13Port = null; private InetAddrPort ajp13Port = null;
File propFile = null; private File propFile = null;
File homeDir = null; private File homeDir = null;
public boolean hasPropFile() { public boolean hasPropFile() {
return (propFile != null); return (propFile != null);
@ -40,4 +40,67 @@ public class ServerConfig {
return (homeDir != null); return (homeDir != null);
} }
public boolean hasRmiPort() {
return (rmiPort != null);
}
public boolean hasXmlrpcPort() {
return (xmlrpcPort != null);
}
public boolean hasWebsrvPort() {
return (websrvPort != null);
}
public boolean hasAjp13Port() {
return (ajp13Port != null);
}
public InetAddrPort getRmiPort() {
return rmiPort;
}
public void setRmiPort(InetAddrPort rmiPort) {
this.rmiPort = rmiPort;
}
public InetAddrPort getXmlrpcPort() {
return xmlrpcPort;
}
public void setXmlrpcPort(InetAddrPort xmlrpcPort) {
this.xmlrpcPort = xmlrpcPort;
}
public InetAddrPort getWebsrvPort() {
return websrvPort;
}
public void setWebsrvPort(InetAddrPort websrvPort) {
this.websrvPort = websrvPort;
}
public InetAddrPort getAjp13Port() {
return ajp13Port;
}
public void setAjp13Port(InetAddrPort ajp13Port) {
this.ajp13Port = ajp13Port;
}
public File getPropFile() {
return propFile;
}
public void setPropFile(File propFile) {
this.propFile = propFile;
}
public File getHomeDir() {
return homeDir;
}
public void setHomeDir(File homeDir) {
this.homeDir = homeDir;
}
} }