public class SignalInterceptor
extends java.lang.Object
A
to signal X
, then attach the handler
B
to X
as well, then all raised signals of type
X
will first call B
, then A
, then the
original handler.
Signal handlers are Callable
s, which return
booleans. If the signal handler returns true
, the call chain
will continue. If the signal handler returns false
or throws an
Exception, the call chain will stop (and no Exception will be thrown). If the
signal handler throws an Error, the Error will not be caught.
com.hypirion.io 0.3.0
Constructor and Description |
---|
SignalInterceptor() |
Modifier and Type | Method and Description |
---|---|
static void |
register(java.lang.String signame,
java.util.concurrent.Callable fn)
Registers the
Callable object to the POSIX
signal signame . |
static boolean |
tryRegister(java.lang.String signame,
java.util.concurrent.Callable fn)
Registers the
Callable object to the POSIX
signal signame . |
public static void register(java.lang.String signame, java.util.concurrent.Callable fn) throws SignalInterceptorException
Callable
object to the POSIX
signal signame
. The POSIX signal must be in upper case,
with the beginning SIG
part omitted.
E.g. an interception to SIGINT
be converted to the symbol
"INT"
.
signame
- the POSIX signal name with SIG
omitted.fn
- the Callable
to call. The Callable
should return either true
or false
.SignalInterceptorException
- if there is no signal with the name
signame
, or if the JVM doesn't implement the most common JVM
signal handling facilities.public static boolean tryRegister(java.lang.String signame, java.util.concurrent.Callable fn)
Callable
object to the POSIX
signal signame
. If successful, will return true. If the
registering fails, returns false. The POSIX signal must be in upper case,
with the beginning SIG
part omitted.
E.g. an interception to SIGINT
be converted to the symbol
"INT"
.
signame
- the POSIX signal name with SIG
omitted.fn
- the Callable
to call. The Callable
should return either true
or false
.