|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.dclausen.util.SignalInterceptor
A simple wrapper around the undocumented and unsupported
sun.misc.Signal*
classes which are present in most JVM
implementations. It can be used to trap OS signals such as SIGINT, SIGTERM,
and SIGHUP on these JVMs.
SignalInterceptor
provides a level of indirection
between your code and sun.misc.SignalHandler
which can
be useful for the following reasons:
sun.misc.Signal*
classes are not available, throwing a checked
exception out of the register
method, rather than awkward
LinkageErrors
durring class initialization.Some possible uses of this class are:
java.util.logging
package closes all of its files in its
ShutdownHook, which means your ShutdownHook might not be able to log
anything. Note that you would still need to deal with
System.exit()
, but there is a different hack available for
that ;)
.
Constructor Summary | |
protected |
SignalInterceptor()
|
Method Summary | |
protected abstract boolean |
handle(String signame)
Handle the given signal (which you had previously registered for). |
protected void |
register(String signame)
Register for the given signal. |
protected boolean |
registerQuietly(String signame)
A wrapper around register(String) which never throws an
exception. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected SignalInterceptor()
Method Detail |
protected void register(String signame) throws SignalInterceptorException
Register for the given signal. Note that the signal name should
not begin with SIG. For example, if you are interested in
SIGTERM, you should call register("TERM")
.
If the registration fails for any reason, a
SignalInterceptorException
will be thrown. This is usually
caused by one of the following conditions:
sun.misc.Signal*
classes are not available (e.g.
you are not using Sun's JVM).signame
is not a valid trappable signal name on this
OS (e.g. KILL can't be trapped, HUP does not exist on
Windows)signame
because it is
already being used for some other important purpose (e.g. QUIT
and/or BREAK cause the JVM to print diagnostic output).
SignalInterceptorException
protected boolean registerQuietly(String signame)
register(String)
which never throws an
exception. Instead, it returns true
if registration
succeeded, and false
if it failed.
protected abstract boolean handle(String signame)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |