Class SignalInterceptor

  extended bynet.dclausen.util.SignalInterceptor
Direct Known Subclasses:

public abstract class SignalInterceptor
extends Object

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:

  1. It gracefully handles the situation when the sun.misc.Signal* classes are not available, throwing a checked exception out of the register method, rather than awkward LinkageErrors durring class initialization.
  2. It has a simple technique for chaining signal handlers.
  3. It is documented and has gone through some testing.

Some possible uses of this class are:

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:



protected boolean registerQuietly(String signame)
A wrapper around 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)
Handle the given signal (which you had previously registered for). If this method return false, or throws an exception, subsequent handlers in the chain will not be called.