01: package net.xoetrope.xui.build.conditional;
02:
03: import net.xoetrope.xui.build.BuildProperties;
04: import net.xoetrope.xui.XLifeCycleListener;
05:
06: /**
07: * This class is conditionally included as it relies on features only available
08: * in JDK1.3+. The class is instantiated at startup and creates a shutdown
09: * hook that causes the debug log summary to be invoked just before the
10: * application closes.
11: * <p>Copyright (c) Xoetrope Ltd., 2001-2004</p>
12: * $Revision: 1.15 $
13: */
14: public class ShutdownHook {
15: /**
16: * Force shutdown of the JVM if true.
17: */
18: public static boolean forceShutdown = false;
19:
20: private XLifeCycleListener lifeCycleListener;
21:
22: public ShutdownHook() {
23: try {
24: Runtime.getRuntime().addShutdownHook(new Thread() {
25: public void run() {
26: if (lifeCycleListener != null)
27: lifeCycleListener.shutdown();
28:
29: if (BuildProperties.DEBUG) {
30: net.xoetrope.debug.DebugLogger.dump();
31: }
32:
33: // Use of JDIC prevents shutdown, so we have to force shutdown
34: if (forceShutdown)
35: Runtime.getRuntime().halt(0);
36: }
37: });
38: } catch (Exception ex1) {
39: ex1.printStackTrace();
40: Runtime.getRuntime().halt(0);
41: }
42: }
43:
44: /**
45: * Add a listener for startup and shutdown events
46: * @param lcl
47: */
48: public void addLifeCycleListener(XLifeCycleListener lcl) {
49: lifeCycleListener = lcl;
50: }
51: }
|