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.
|
* ShutdownHook that shuts down all running Helma applications on exit.
|
||||||
*/
|
*/
|
||||||
public class HelmaShutdownHook extends Thread {
|
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() {
|
public void run() {
|
||||||
System.err.println("Shutting down Helma - please stand by...");
|
System.err.println("Shutting down Helma - please stand by...");
|
||||||
|
|
||||||
Server.getServer().getLogger().info("Shutting down Helma");
|
Server server = Server.getServer();
|
||||||
|
if (server != null) {
|
||||||
appmgr.stopAll();
|
server.stop();
|
||||||
|
|
||||||
if (LogFactory.getFactory() instanceof Logging) {
|
|
||||||
Logging.shutdown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,8 @@ public class Server implements IPathElement, Runnable {
|
||||||
// the XML-RPC server
|
// the XML-RPC server
|
||||||
protected WebServer xmlrpc;
|
protected WebServer xmlrpc;
|
||||||
|
|
||||||
|
Thread shutdownhook;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Server instance with an array of command line options.
|
* Constructs a new Server instance with an array of command line options.
|
||||||
|
@ -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
|
// Start running, finishing setup and then entering a loop to check changes
|
||||||
// in the apps.properties file.
|
// in the apps.properties file.
|
||||||
mainThread = new Thread(this);
|
mainThread = new Thread(this);
|
||||||
mainThread.start();
|
mainThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stop() {
|
public void stop() {
|
||||||
mainThread = null;
|
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
|
// 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) {
|
} catch (Exception gx) {
|
||||||
logger.error("Error initializing embedded database: " + gx);
|
logger.error("Error initializing embedded database: " + gx);
|
||||||
gx.printStackTrace();
|
gx.printStackTrace();
|
||||||
|
|
Loading…
Add table
Reference in a new issue