diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-06-22 12:32:41 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-06-22 12:32:41 -0230 |
commit | eca8dda24e1836c2ad393cd5096a9e079075cf6e (patch) | |
tree | 7cdfbceda6c189affb7edec35d39e8e68605fef8 /java/src/Ice/Application.java | |
parent | Bug 2265. (diff) | |
download | ice-eca8dda24e1836c2ad393cd5096a9e079075cf6e.tar.bz2 ice-eca8dda24e1836c2ad393cd5096a9e079075cf6e.tar.xz ice-eca8dda24e1836c2ad393cd5096a9e079075cf6e.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=2179 - Add option to disable signal handling in Ice::Application
Diffstat (limited to 'java/src/Ice/Application.java')
-rw-r--r-- | java/src/Ice/Application.java | 111 |
1 files changed, 78 insertions, 33 deletions
diff --git a/java/src/Ice/Application.java b/java/src/Ice/Application.java index 8e83712269e..72018dc776a 100644 --- a/java/src/Ice/Application.java +++ b/java/src/Ice/Application.java @@ -16,6 +16,12 @@ public abstract class Application { } + public + Application(boolean useCtrlCHandler) + { + _useCtrlCHandler = useCtrlCHandler; + } + // // This main() must be called by the global main(). main() // initializes the Communicator, calls run(), and destroys @@ -109,7 +115,10 @@ public abstract class Application // // The default is to destroy when a signal is received. // - destroyOnInterrupt(); + if(_useCtrlCHandler) + { + destroyOnInterrupt(); + } status = run(argHolder.value); } @@ -136,7 +145,10 @@ public abstract class Application } // This clears any set interrupt. - defaultInterrupt(); + if(_useCtrlCHandler) + { + defaultInterrupt(); + } synchronized(_mutex) { @@ -227,49 +239,65 @@ public abstract class Application public static void destroyOnInterrupt() { - synchronized(_mutex) + if(_useCtrlCHandler) { - // - // As soon as the destroy hook ends all the threads are - // terminated. So the destroy hook will join the current - // thread before to end. - // - try - { - changeHook(new DestroyHook()); - } - catch(java.lang.IllegalStateException ex) + synchronized(_mutex) { - if(_communicator != null) + // + // As soon as the destroy hook ends all the threads are + // terminated. So the destroy hook will join the current + // thread before to end. + // + try { - _communicator.destroy(); + changeHook(new DestroyHook()); + } + catch(java.lang.IllegalStateException ex) + { + if(_communicator != null) + { + _communicator.destroy(); + } } } } + else + { + System.err.println(_appName + + ": warning: interrupt method called on Application configured to not handle interrupts."); + } } public static void shutdownOnInterrupt() { - synchronized(_mutex) + if(_useCtrlCHandler) { - // - // As soon as the shutdown hook ends all the threads are - // terminated. So the shutdown hook will join the current - // thread before to end. - // - try + synchronized(_mutex) { - changeHook(new ShutdownHook()); - } - catch(java.lang.IllegalStateException ex) - { - if(_communicator != null) + // + // As soon as the shutdown hook ends all the threads are + // terminated. So the shutdown hook will join the current + // thread before to end. + // + try + { + changeHook(new ShutdownHook()); + } + catch(java.lang.IllegalStateException ex) { - _communicator.shutdown(); + if(_communicator != null) + { + _communicator.shutdown(); + } } } } + else + { + System.err.println(_appName + + ": warning: interrupt method called on Application configured to not handle interrupts."); + } } // @@ -284,13 +312,21 @@ public abstract class Application public static void setInterruptHook(java.lang.Thread newHook) // Pun intended. { - try + if(_useCtrlCHandler) { - changeHook(new CustomHook(newHook)); + try + { + changeHook(new CustomHook(newHook)); + } + catch(java.lang.IllegalStateException ex) + { + // Ignore. + } } - catch(java.lang.IllegalStateException ex) + else { - // Ignore. + System.err.println(_appName + + ": warning: interrupt method called on Application configured to not handle interrupts."); } } @@ -300,7 +336,15 @@ public abstract class Application public static void defaultInterrupt() { - changeHook(null); + if(_useCtrlCHandler) + { + changeHook(null); + } + else + { + System.err.println(_appName + + ": warning: interrupt method called on Application configured to not handle interrupts."); + } } public static boolean @@ -502,4 +546,5 @@ public abstract class Application private static boolean _callbackInProgress = false; private static boolean _destroyed = false; private static boolean _interrupted = false; + private static boolean _useCtrlCHandler = true; } |