Rewrite Server.stop() to actually try to stop the server.
Rewrite HelmaShutdownHook to use Server.stop().
This commit is contained in:
parent
59bec76b45
commit
5646c3881a
2 changed files with 34 additions and 18 deletions
|
@ -23,16 +23,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
* ShutdownHook that shuts down all running Helma applications on exit.
|
||||
*/
|
||||
public class HelmaShutdownHook extends Thread {
|
||||
ApplicationManager appmgr;
|
||||
|
||||
/**
|
||||
* Creates a new HelmaShutdownHook object.
|
||||
*
|
||||
* @param appmgr ...
|
||||
*/
|
||||
public HelmaShutdownHook(ApplicationManager appmgr) {
|
||||
this.appmgr = appmgr;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,12 +31,9 @@ public class HelmaShutdownHook extends Thread {
|
|||
public void run() {
|
||||
System.err.println("Shutting down Helma - please stand by...");
|
||||
|
||||
Server.getServer().getLogger().info("Shutting down Helma");
|
||||
|
||||
appmgr.stopAll();
|
||||
|
||||
if (LogFactory.getFactory() instanceof Logging) {
|
||||
Logging.shutdown();
|
||||
Server server = Server.getServer();
|
||||
if (server != null) {
|
||||
server.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,8 @@ public class Server implements IPathElement, Runnable {
|
|||
|
||||
// the XML-RPC server
|
||||
protected WebServer xmlrpc;
|
||||
|
||||
Thread shutdownhook;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -503,15 +505,40 @@ public class Server implements IPathElement, Runnable {
|
|||
|
||||
|
||||
|
||||
protected void start() {
|
||||
public void start() {
|
||||
// Start running, finishing setup and then entering a loop to check changes
|
||||
// in the apps.properties file.
|
||||
mainThread = new Thread(this);
|
||||
mainThread.start();
|
||||
}
|
||||
|
||||
protected void stop() {
|
||||
public void stop() {
|
||||
mainThread = null;
|
||||
|
||||
getLogger().info("Shutting down Helma");
|
||||
|
||||
appManager.stopAll();
|
||||
|
||||
if (http != null) {
|
||||
try {
|
||||
http.stop();
|
||||
http.destroy();
|
||||
} catch (InterruptedException irx) {
|
||||
// http.stop() interrupted by another thread. ignore.
|
||||
}
|
||||
}
|
||||
|
||||
if (helmaLogging) {
|
||||
Logging.shutdown();
|
||||
}
|
||||
|
||||
try {
|
||||
Runtime.getRuntime().removeShutdownHook(shutdownhook);
|
||||
} catch (Exception x) {
|
||||
// invalid shutdown hook or already shutting down. ignore.
|
||||
}
|
||||
|
||||
server = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -646,7 +673,8 @@ public class Server implements IPathElement, Runnable {
|
|||
}
|
||||
|
||||
// add shutdown hook to close running apps and servers on exit
|
||||
Runtime.getRuntime().addShutdownHook(new HelmaShutdownHook(appManager));
|
||||
shutdownhook = new HelmaShutdownHook();
|
||||
Runtime.getRuntime().addShutdownHook(shutdownhook);
|
||||
} catch (Exception gx) {
|
||||
logger.error("Error initializing embedded database: " + gx);
|
||||
gx.printStackTrace();
|
||||
|
|
Loading…
Add table
Reference in a new issue