Author: hannes
Date: 2008-12-13 02:39:10 +0100 (Sat, 13 Dec 2008)
New Revision: 9429
Modified:
helma/helma/trunk/src/helma/main/CommandlineRunner.java
helma/helma/trunk/src/helma/main/HelmaShutdownHook.java
helma/helma/trunk/src/helma/main/Server.java
helma/helma/trunk/src/helma/main/launcher/Main.java
Log:
Make launcher Main class compatible with jsvc (apache commons daemon) and adapt Server lifecycle API.
Details at http://dev.helma.org/trac/helma/changeset/9429
Modified: helma/helma/trunk/src/helma/main/CommandlineRunner.java
===================================================================
--- helma/helma/trunk/src/helma/main/CommandlineRunner.java 2008-12-13 00:14:45 UTC (rev 9428)
+++ helma/helma/trunk/src/helma/main/CommandlineRunner.java 2008-12-13 01:39:10 UTC (rev 9429)
@@ -107,6 +107,7 @@
// stop the application and server
server.stop();
+ server.shutdown();
}
Modified: helma/helma/trunk/src/helma/main/HelmaShutdownHook.java
===================================================================
--- helma/helma/trunk/src/helma/main/HelmaShutdownHook.java 2008-12-13 00:14:45 UTC (rev 9428)
+++ helma/helma/trunk/src/helma/main/HelmaShutdownHook.java 2008-12-13 01:39:10 UTC (rev 9429)
@@ -34,6 +34,7 @@
Server server = Server.getServer();
if (server != null) {
server.stop();
+ server.shutdown();
}
}
}
Modified: helma/helma/trunk/src/helma/main/Server.java
===================================================================
--- helma/helma/trunk/src/helma/main/Server.java 2008-12-13 00:14:45 UTC (rev 9428)
+++ helma/helma/trunk/src/helma/main/Server.java 2008-12-13 01:39:10 UTC (rev 9429)
@@ -92,6 +92,8 @@
/**
* Constructs a new Server instance with an array of command line options.
+ * TODO make this a singleton
+ * @param config the configuration
*/
public Server(ServerConfig config) {
server = this;
@@ -113,9 +115,23 @@
/**
- * static main entry point.
+ * Static main entry point.
+ * @param args the command line arguments
*/
public static void main(String[] args) {
+ loadServer(args);
+ // parse properties files etc
+ server.init();
+ // start the server main thread
+ server.start();
+ }
+
+ /**
+ * Entry point used by launcher.jar to load a server instance
+ * @param args the command line arguments
+ * @return the server instance
+ */
+ public static Server loadServer(String[] args) {
checkJavaVersion();
ServerConfig config = null;
@@ -130,12 +146,7 @@
// create new server instance
server = new Server(config);
-
- // parse properties files etc
- server.init();
-
- // start the server main thread
- server.start();
+ return server;
}
@@ -513,11 +524,12 @@
public void stop() {
mainThread = null;
-
+ appManager.stopAll();
+ }
+
+ public void shutdown() {
getLogger().info("Shutting down Helma");
- appManager.stopAll();
-
if (jetty != null) {
try {
jetty.stop();
Modified: helma/helma/trunk/src/helma/main/launcher/Main.java
===================================================================
--- helma/helma/trunk/src/helma/main/launcher/Main.java 2008-12-13 00:14:45 UTC (rev 9428)
+++ helma/helma/trunk/src/helma/main/launcher/Main.java 2008-12-13 01:39:10 UTC (rev 9429)
@@ -44,6 +44,12 @@
"tagsoup.jar"
};
+ private Class serverClass;
+ private Object server;
+
+ private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
+ private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
+
/**
* Helma boot method. This retrieves the Helma home directory, creates the
* classpath and invokes main() in helma.main.Server.
@@ -52,28 +58,68 @@
*
*/
public static void main(String[] args) {
+ Main main = new Main();
+ main.init(args);
+ main.start();
+ }
+
+ public void init(String[] args) {
try {
String installDir = getInstallDir(args);
-
ClassLoader loader = createClassLoader(installDir);
-
// get the main server class
- Class clazz = loader.loadClass("helma.main.Server");
+ serverClass = loader.loadClass("helma.main.Server");
Class[] cargs = new Class[]{args.getClass()};
- Method main = clazz.getMethod("main", cargs);
+ Method loadServer = serverClass.getMethod("loadServer", cargs);
Object[] nargs = new Object[]{args};
+ // and invoke the static loadServer(String[]) method
+ server = loadServer.invoke(null, nargs);
+ Method init = serverClass.getMethod("init", EMPTY_CLASS_ARRAY);
+ init.invoke(server, EMPTY_OBJECT_ARRAY);
+ } catch (Exception x) {
+ // unable to get Helma installation dir from launcher jar
+ System.err.println("Unable to load Helma: ");
+ x.printStackTrace();
+ System.exit(2);
+ }
+ }
- // and invoke the static main(String, String[]) method
- main.invoke(null, nargs);
+ public void start() {
+ try {
+ Method start = serverClass.getMethod("start", EMPTY_CLASS_ARRAY);
+ start.invoke(server, EMPTY_OBJECT_ARRAY);
} catch (Exception x) {
// unable to get Helma installation dir from launcher jar
- System.err.println("Unable to get Helma installation directory: ");
+ System.err.println("Unable to start Helma: ");
x.printStackTrace();
System.exit(2);
}
}
+ public void stop() {
+ try {
+ Method start = serverClass.getMethod("stop", EMPTY_CLASS_ARRAY);
+ start.invoke(server, EMPTY_OBJECT_ARRAY);
+ } catch (Exception x) {
+ // unable to get Helma installation dir from launcher jar
+ System.err.println("Unable to stop Helma: ");
+ x.printStackTrace();
+ System.exit(2);
+ }
+ }
+ public void destroy() {
+ try {
+ Method start = serverClass.getMethod("shutdown", EMPTY_CLASS_ARRAY);
+ start.invoke(server, EMPTY_OBJECT_ARRAY);
+ } catch (Exception x) {
+ // unable to get Helma installation dir from launcher jar
+ System.err.println("Unable to shutdown Helma: ");
+ x.printStackTrace();
+ System.exit(2);
+ }
+ }
+
/**
* Create a server-wide ClassLoader from our install directory.
* This will be used as parent ClassLoader for all application
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.