Code cleanup in helma.main package. Made most methods in Server non-static

for the sake of consistency.
This commit is contained in:
hns 2003-12-15 17:07:06 +00:00
parent 09d983bd29
commit a4ba238530
4 changed files with 44 additions and 46 deletions

View file

@ -19,8 +19,6 @@ package helma.main;
import helma.framework.core.*; import helma.framework.core.*;
import helma.util.StringUtils; import helma.util.StringUtils;
import helma.util.SystemProperties; import helma.util.SystemProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xmlrpc.XmlRpcHandler; import org.apache.xmlrpc.XmlRpcHandler;
import org.mortbay.http.*; import org.mortbay.http.*;
import org.mortbay.http.handler.*; import org.mortbay.http.handler.*;
@ -36,8 +34,7 @@ public class ApplicationManager implements XmlRpcHandler {
private Hashtable descriptors; private Hashtable descriptors;
private Hashtable applications; private Hashtable applications;
private Hashtable xmlrpcHandlers; private Hashtable xmlrpcHandlers;
private int port; private int rmiPort;
private File hopHome;
private SystemProperties props; private SystemProperties props;
private Server server; private Server server;
private long lastModified; private long lastModified;
@ -45,17 +42,15 @@ public class ApplicationManager implements XmlRpcHandler {
/** /**
* Creates a new ApplicationManager object. * Creates a new ApplicationManager object.
* *
* @param hopHome The Helma home directory
* @param props the properties defining the running apps * @param props the properties defining the running apps
* @param server the server instance * @param server the server instance
* @param port The RMI port we're binding to * @param port The RMI port we're binding to
*/ */
public ApplicationManager(File hopHome, SystemProperties props, public ApplicationManager(SystemProperties props,
Server server, int port) { Server server, int port) {
this.hopHome = hopHome;
this.props = props; this.props = props;
this.server = server; this.server = server;
this.port = port; this.rmiPort = port;
descriptors = new Hashtable(); descriptors = new Hashtable();
applications = new Hashtable(); applications = new Hashtable();
xmlrpcHandlers = new Hashtable(); xmlrpcHandlers = new Hashtable();
@ -99,7 +94,7 @@ public class ApplicationManager implements XmlRpcHandler {
} }
} }
} catch (Exception mx) { } catch (Exception mx) {
Server.getLogger().error("Error checking applications: " + mx); server.getLogger().error("Error checking applications: " + mx);
} }
lastModified = System.currentTimeMillis(); lastModified = System.currentTimeMillis();
@ -163,7 +158,7 @@ public class ApplicationManager implements XmlRpcHandler {
lastModified = System.currentTimeMillis(); lastModified = System.currentTimeMillis();
} catch (Exception mx) { } catch (Exception mx) {
Server.getLogger().error("Error starting applications: " + mx); server.getLogger().error("Error starting applications: " + mx);
mx.printStackTrace(); mx.printStackTrace();
} }
} }
@ -324,7 +319,7 @@ public class ApplicationManager implements XmlRpcHandler {
void start() { void start() {
Server.getLogger().info("Building application " + appName); server.getLogger().info("Building application " + appName);
try { try {
// create the application instance // create the application instance
@ -344,13 +339,13 @@ public class ApplicationManager implements XmlRpcHandler {
app.start(); app.start();
} catch (Exception x) { } catch (Exception x) {
Server.getLogger().error("Error creating application " + appName + ": " + x); server.getLogger().error("Error creating application " + appName + ": " + x);
x.printStackTrace(); x.printStackTrace();
} }
} }
void stop() { void stop() {
Server.getLogger().info("Stopping application " + appName); server.getLogger().info("Stopping application " + appName);
// unbind application // unbind application
unbind(); unbind();
@ -358,9 +353,9 @@ public class ApplicationManager implements XmlRpcHandler {
// stop application // stop application
try { try {
app.stop(); app.stop();
Server.getLogger().info("Stopped application " + appName); server.getLogger().info("Stopped application " + appName);
} catch (Exception x) { } catch (Exception x) {
Server.getLogger().error("Couldn't stop app: " + x); server.getLogger().error("Couldn't stop app: " + x);
} }
descriptors.remove(appName); descriptors.remove(appName);
@ -369,11 +364,11 @@ public class ApplicationManager implements XmlRpcHandler {
void bind() { void bind() {
try { try {
Server.getLogger().info("Binding application " + appName); server.getLogger().info("Binding application " + appName);
// bind to RMI server // bind to RMI server
if (port > 0) { if (rmiPort > 0) {
Naming.rebind("//:" + port + "/" + appName, new RemoteApplication(app)); Naming.rebind("//:" + rmiPort + "/" + appName, new RemoteApplication(app));
} }
// bind to Jetty HTTP server // bind to Jetty HTTP server
@ -384,7 +379,7 @@ public class ApplicationManager implements XmlRpcHandler {
if (encode) { if (encode) {
// FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2 // FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2
// context.addHandler(new ContentEncodingHandler()); // context.addHandler(new ContentEncodingHandler());
Server.getLogger().warn("Warning: disabling response encoding for Jetty 4.2 compatibility"); server.getLogger().warn("Warning: disabling response encoding for Jetty 4.2 compatibility");
} }
ServletHandler handler = new ServletHandler(); ServletHandler handler = new ServletHandler();
@ -417,7 +412,7 @@ public class ApplicationManager implements XmlRpcHandler {
protectedContent = new File(server.getHopHome(), protectedStaticDir); protectedContent = new File(server.getHopHome(), protectedStaticDir);
} }
context.setResourceBase(protectedContent.getAbsolutePath()); context.setResourceBase(protectedContent.getAbsolutePath());
Server.getLogger().info("Serving protected static from " + server.getLogger().info("Serving protected static from " +
protectedContent.getAbsolutePath()); protectedContent.getAbsolutePath());
context.addHandler(new ResourceHandler()); context.addHandler(new ResourceHandler());
} }
@ -432,9 +427,9 @@ public class ApplicationManager implements XmlRpcHandler {
staticContent = new File(server.getHopHome(), staticDir); staticContent = new File(server.getHopHome(), staticDir);
} }
Server.getLogger().info("Serving static from " + server.getLogger().info("Serving static from " +
staticContent.getAbsolutePath()); staticContent.getAbsolutePath());
Server.getLogger().info("Mounting static at " + server.getLogger().info("Mounting static at " +
staticMountpoint); staticMountpoint);
context = server.http.addContext(staticMountpoint); context = server.http.addContext(staticMountpoint);
@ -454,18 +449,18 @@ public class ApplicationManager implements XmlRpcHandler {
xmlrpcHandlers.put(xmlrpcHandlerName, app); xmlrpcHandlers.put(xmlrpcHandlerName, app);
// app.start(); // app.start();
} catch (Exception x) { } catch (Exception x) {
Server.getLogger().error("Couldn't bind app: " + x); server.getLogger().error("Couldn't bind app: " + x);
x.printStackTrace(); x.printStackTrace();
} }
} }
void unbind() { void unbind() {
Server.getLogger().info("Unbinding application " + appName); server.getLogger().info("Unbinding application " + appName);
try { try {
// unbind from RMI server // unbind from RMI server
if (port > 0) { if (rmiPort > 0) {
Naming.unbind("//:" + port + "/" + appName); Naming.unbind("//:" + rmiPort + "/" + appName);
} }
// unbind from Jetty HTTP server // unbind from Jetty HTTP server
@ -490,7 +485,7 @@ public class ApplicationManager implements XmlRpcHandler {
// unregister as XML-RPC handler // unregister as XML-RPC handler
xmlrpcHandlers.remove(xmlrpcHandlerName); xmlrpcHandlers.remove(xmlrpcHandlerName);
} catch (Exception x) { } catch (Exception x) {
Server.getLogger().error("Couldn't unbind app: " + x); server.getLogger().error("Couldn't unbind app: " + x);
} }
} }

View file

@ -17,7 +17,6 @@
package helma.main; package helma.main;
import helma.util.*; import helma.util.*;
import java.util.List;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
/** /**
@ -41,7 +40,7 @@ public class HelmaShutdownHook extends Thread {
public void run() { public void run() {
System.err.println("Shutting down Helma - please stand by..."); System.err.println("Shutting down Helma - please stand by...");
Server.getLogger().info("Shutting down Helma"); Server.getServer().getLogger().info("Shutting down Helma");
appmgr.stopAll(); appmgr.stopAll();

View file

@ -45,7 +45,7 @@ public class HelmaSocketFactory extends RMISocketFactory {
try { try {
filter.addAddress(address); filter.addAddress(address);
} catch (IOException x) { } catch (IOException x) {
Server.getLogger().error("Could not add " + address + Server.getServer().getLogger().error("Could not add " + address +
" to Socket Filter: invalid address."); " to Socket Filter: invalid address.");
} }
} }

View file

@ -40,26 +40,29 @@ import java.util.*;
* Helma server main class. * Helma server main class.
*/ */
public class Server implements IPathElement, Runnable { public class Server implements IPathElement, Runnable {
// version string
public static final String version = "1.3.2-pre2 (2003/12/01)"; public static final String version = "1.3.2-pre2 (2003/12/01)";
// server-wide properties
static SystemProperties appsProps;
static SystemProperties dbProps;
static SystemProperties sysProps;
// static server instance // static server instance
private static Server server; private static Server server;
protected static File hopHome = null;
// Server home directory
protected File hopHome;
// server-wide properties
SystemProperties appsProps;
SystemProperties dbProps;
SystemProperties sysProps;
// our logger // our logger
private static Log logger; private Log logger;
// are we using helma.util.Logging? // are we using helma.util.Logging?
private static boolean helmaLogging; private boolean helmaLogging;
// server start time // server start time
public final long starttime; public final long starttime;
// if true we only accept RMI and XML-RPC connections from // if paranoid == true we only accept RMI and XML-RPC connections from
// explicitly listed hosts. // explicitly listed hosts.
public boolean paranoid; public boolean paranoid;
private ApplicationManager appManager; private ApplicationManager appManager;
@ -91,7 +94,7 @@ public class Server implements IPathElement, Runnable {
public Server(String[] args) { public Server(String[] args) {
starttime = System.currentTimeMillis(); starttime = System.currentTimeMillis();
String homeDir = null; String homeDir = System.getProperty("helma.home");
boolean usageError = false; boolean usageError = false;
@ -350,9 +353,10 @@ public class Server implements IPathElement, Runnable {
// 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 javaVersion = System.getProperty("java.version"); String javaVersion = System.getProperty("java.version");
if ((javaVersion == null) || javaVersion.startsWith("1.1") || if ((javaVersion == null) || javaVersion.startsWith("1.2")
javaVersion.startsWith("1.0")) { || javaVersion.startsWith("1.1")
System.err.println("This version of Helma requires Java 1.2 or greater."); || javaVersion.startsWith("1.0")) {
System.err.println("This version of Helma requires Java 1.3 or greater.");
if (javaVersion == 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.");
@ -503,10 +507,10 @@ public class Server implements IPathElement, Runnable {
LocateRegistry.createRegistry(rmiPort.getPort()); LocateRegistry.createRegistry(rmiPort.getPort());
// create application manager which binds to the given RMI port // create application manager which binds to the given RMI port
appManager = new ApplicationManager(hopHome, appsProps, this, rmiPort.getPort()); appManager = new ApplicationManager(appsProps, this, rmiPort.getPort());
} else { } else {
// create application manager with RMI port 0 // create application manager with RMI port 0
appManager = new ApplicationManager(hopHome, appsProps, this, 0); appManager = new ApplicationManager(appsProps, this, 0);
} }
if (xmlrpc != null) { if (xmlrpc != null) {
@ -589,7 +593,7 @@ public class Server implements IPathElement, Runnable {
/** /**
* Get a logger to use for output in this server. * Get a logger to use for output in this server.
*/ */
public static Log getLogger() { public Log getLogger() {
if (logger == null) { if (logger == null) {
if (helmaLogging) { if (helmaLogging) {
// set up system properties for helma.util.Logging // set up system properties for helma.util.Logging