Code cleanup in helma.main package. Made most methods in Server non-static
for the sake of consistency.
This commit is contained in:
parent
09d983bd29
commit
a4ba238530
4 changed files with 44 additions and 46 deletions
|
@ -19,8 +19,6 @@ package helma.main;
|
|||
import helma.framework.core.*;
|
||||
import helma.util.StringUtils;
|
||||
import helma.util.SystemProperties;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.xmlrpc.XmlRpcHandler;
|
||||
import org.mortbay.http.*;
|
||||
import org.mortbay.http.handler.*;
|
||||
|
@ -36,8 +34,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
private Hashtable descriptors;
|
||||
private Hashtable applications;
|
||||
private Hashtable xmlrpcHandlers;
|
||||
private int port;
|
||||
private File hopHome;
|
||||
private int rmiPort;
|
||||
private SystemProperties props;
|
||||
private Server server;
|
||||
private long lastModified;
|
||||
|
@ -45,17 +42,15 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
/**
|
||||
* Creates a new ApplicationManager object.
|
||||
*
|
||||
* @param hopHome The Helma home directory
|
||||
* @param props the properties defining the running apps
|
||||
* @param server the server instance
|
||||
* @param port The RMI port we're binding to
|
||||
*/
|
||||
public ApplicationManager(File hopHome, SystemProperties props,
|
||||
public ApplicationManager(SystemProperties props,
|
||||
Server server, int port) {
|
||||
this.hopHome = hopHome;
|
||||
this.props = props;
|
||||
this.server = server;
|
||||
this.port = port;
|
||||
this.rmiPort = port;
|
||||
descriptors = new Hashtable();
|
||||
applications = new Hashtable();
|
||||
xmlrpcHandlers = new Hashtable();
|
||||
|
@ -99,7 +94,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
}
|
||||
}
|
||||
} catch (Exception mx) {
|
||||
Server.getLogger().error("Error checking applications: " + mx);
|
||||
server.getLogger().error("Error checking applications: " + mx);
|
||||
}
|
||||
|
||||
lastModified = System.currentTimeMillis();
|
||||
|
@ -163,7 +158,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
|
||||
lastModified = System.currentTimeMillis();
|
||||
} catch (Exception mx) {
|
||||
Server.getLogger().error("Error starting applications: " + mx);
|
||||
server.getLogger().error("Error starting applications: " + mx);
|
||||
mx.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +319,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
|
||||
|
||||
void start() {
|
||||
Server.getLogger().info("Building application " + appName);
|
||||
server.getLogger().info("Building application " + appName);
|
||||
|
||||
try {
|
||||
// create the application instance
|
||||
|
@ -344,13 +339,13 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
|
||||
app.start();
|
||||
} catch (Exception x) {
|
||||
Server.getLogger().error("Error creating application " + appName + ": " + x);
|
||||
server.getLogger().error("Error creating application " + appName + ": " + x);
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
Server.getLogger().info("Stopping application " + appName);
|
||||
server.getLogger().info("Stopping application " + appName);
|
||||
|
||||
// unbind application
|
||||
unbind();
|
||||
|
@ -358,9 +353,9 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
// stop application
|
||||
try {
|
||||
app.stop();
|
||||
Server.getLogger().info("Stopped application " + appName);
|
||||
server.getLogger().info("Stopped application " + appName);
|
||||
} catch (Exception x) {
|
||||
Server.getLogger().error("Couldn't stop app: " + x);
|
||||
server.getLogger().error("Couldn't stop app: " + x);
|
||||
}
|
||||
|
||||
descriptors.remove(appName);
|
||||
|
@ -369,11 +364,11 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
|
||||
void bind() {
|
||||
try {
|
||||
Server.getLogger().info("Binding application " + appName);
|
||||
server.getLogger().info("Binding application " + appName);
|
||||
|
||||
// bind to RMI server
|
||||
if (port > 0) {
|
||||
Naming.rebind("//:" + port + "/" + appName, new RemoteApplication(app));
|
||||
if (rmiPort > 0) {
|
||||
Naming.rebind("//:" + rmiPort + "/" + appName, new RemoteApplication(app));
|
||||
}
|
||||
|
||||
// bind to Jetty HTTP server
|
||||
|
@ -384,7 +379,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
if (encode) {
|
||||
// FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2
|
||||
// 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();
|
||||
|
@ -417,7 +412,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
protectedContent = new File(server.getHopHome(), protectedStaticDir);
|
||||
}
|
||||
context.setResourceBase(protectedContent.getAbsolutePath());
|
||||
Server.getLogger().info("Serving protected static from " +
|
||||
server.getLogger().info("Serving protected static from " +
|
||||
protectedContent.getAbsolutePath());
|
||||
context.addHandler(new ResourceHandler());
|
||||
}
|
||||
|
@ -432,9 +427,9 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
staticContent = new File(server.getHopHome(), staticDir);
|
||||
}
|
||||
|
||||
Server.getLogger().info("Serving static from " +
|
||||
server.getLogger().info("Serving static from " +
|
||||
staticContent.getAbsolutePath());
|
||||
Server.getLogger().info("Mounting static at " +
|
||||
server.getLogger().info("Mounting static at " +
|
||||
staticMountpoint);
|
||||
|
||||
context = server.http.addContext(staticMountpoint);
|
||||
|
@ -454,18 +449,18 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
xmlrpcHandlers.put(xmlrpcHandlerName, app);
|
||||
// app.start();
|
||||
} catch (Exception x) {
|
||||
Server.getLogger().error("Couldn't bind app: " + x);
|
||||
server.getLogger().error("Couldn't bind app: " + x);
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void unbind() {
|
||||
Server.getLogger().info("Unbinding application " + appName);
|
||||
server.getLogger().info("Unbinding application " + appName);
|
||||
|
||||
try {
|
||||
// unbind from RMI server
|
||||
if (port > 0) {
|
||||
Naming.unbind("//:" + port + "/" + appName);
|
||||
if (rmiPort > 0) {
|
||||
Naming.unbind("//:" + rmiPort + "/" + appName);
|
||||
}
|
||||
|
||||
// unbind from Jetty HTTP server
|
||||
|
@ -490,7 +485,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
|||
// unregister as XML-RPC handler
|
||||
xmlrpcHandlers.remove(xmlrpcHandlerName);
|
||||
} catch (Exception x) {
|
||||
Server.getLogger().error("Couldn't unbind app: " + x);
|
||||
server.getLogger().error("Couldn't unbind app: " + x);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package helma.main;
|
||||
|
||||
import helma.util.*;
|
||||
import java.util.List;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +40,7 @@ public class HelmaShutdownHook extends Thread {
|
|||
public void run() {
|
||||
System.err.println("Shutting down Helma - please stand by...");
|
||||
|
||||
Server.getLogger().info("Shutting down Helma");
|
||||
Server.getServer().getLogger().info("Shutting down Helma");
|
||||
|
||||
appmgr.stopAll();
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public class HelmaSocketFactory extends RMISocketFactory {
|
|||
try {
|
||||
filter.addAddress(address);
|
||||
} catch (IOException x) {
|
||||
Server.getLogger().error("Could not add " + address +
|
||||
Server.getServer().getLogger().error("Could not add " + address +
|
||||
" to Socket Filter: invalid address.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,26 +40,29 @@ import java.util.*;
|
|||
* Helma server main class.
|
||||
*/
|
||||
public class Server implements IPathElement, Runnable {
|
||||
// version string
|
||||
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
|
||||
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
|
||||
private static Log logger;
|
||||
private Log logger;
|
||||
// are we using helma.util.Logging?
|
||||
private static boolean helmaLogging;
|
||||
private boolean helmaLogging;
|
||||
|
||||
// server start time
|
||||
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.
|
||||
public boolean paranoid;
|
||||
private ApplicationManager appManager;
|
||||
|
@ -91,7 +94,7 @@ public class Server implements IPathElement, Runnable {
|
|||
public Server(String[] args) {
|
||||
starttime = System.currentTimeMillis();
|
||||
|
||||
String homeDir = null;
|
||||
String homeDir = System.getProperty("helma.home");
|
||||
|
||||
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
|
||||
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 ((javaVersion == null) || javaVersion.startsWith("1.2")
|
||||
|| javaVersion.startsWith("1.1")
|
||||
|| 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
|
||||
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());
|
||||
|
||||
// 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 {
|
||||
// create application manager with RMI port 0
|
||||
appManager = new ApplicationManager(hopHome, appsProps, this, 0);
|
||||
appManager = new ApplicationManager(appsProps, this, 0);
|
||||
}
|
||||
|
||||
if (xmlrpc != null) {
|
||||
|
@ -589,7 +593,7 @@ public class Server implements IPathElement, Runnable {
|
|||
/**
|
||||
* Get a logger to use for output in this server.
|
||||
*/
|
||||
public static Log getLogger() {
|
||||
public Log getLogger() {
|
||||
if (logger == null) {
|
||||
if (helmaLogging) {
|
||||
// set up system properties for helma.util.Logging
|
||||
|
|
Loading…
Add table
Reference in a new issue