Class DelegatingSignalHandler

java.lang.Object
net.sf.basedb.core.signal.AbstractSignalHandler
net.sf.basedb.core.signal.DelegatingSignalHandler
All Implemented Interfaces:
SignalHandler, Action

public class DelegatingSignalHandler extends AbstractSignalHandler
A signal handler implementation that can delegate to other signal handlers, depending on which signal it receives. Multiple signal handlers may be registered for each signal. The order in which they are called is not specified, but it is probably different from the order they are registered.
Version:
2.6
Author:
nicklas
Last modified
$Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
  • Field Details

    • logger

      private static final Logger logger
      Log signals processing.
    • handlers

      private Map<Signal,Set<SignalHandler>> handlers
      Holds the registered signal handlers.
    • received

      private final List<Signal> received
      List holding received signals.
      Since:
      2.16
  • Constructor Details

    • DelegatingSignalHandler

      public DelegatingSignalHandler()
      Create a new delegating signal handler. Signal handlers to delegate to should be registered with registerSignalHandler(SignalHandler).
    • DelegatingSignalHandler

      public DelegatingSignalHandler(SignalHandler... handlers)
      Create a new delegating signal handler and register the given handlers as delegates.
      Parameters:
      handlers - An array with signal handlers that signal should be delegated to
      Since:
      2.16
  • Method Details

    • getSupportedSignals

      public Collection<Signal> getSupportedSignals()
      Description copied from interface: SignalHandler
      Get all signals that are supported by this handler.
      Specified by:
      getSupportedSignals in interface SignalHandler
      Overrides:
      getSupportedSignals in class AbstractSignalHandler
      Returns:
      A collection containing all signals that have at least one registered handler
    • supports

      public boolean supports(Signal signal)
      Check if at least one handler has been registered for the given signal.
      Specified by:
      supports in interface SignalHandler
      Overrides:
      supports in class AbstractSignalHandler
      Parameters:
      signal - The signal to check
      Returns:
      TRUE if the signal is supported, FALSE otherwise
    • handleSignal

      public void handleSignal(Signal signal)
      Handler the given signal by invoking SignalHandler.handleSignal(Signal) on each registered signal handler. The order of the invokation is not predictable.
      Parameters:
      signal - The signal to handle
      Throws:
      UnsupportedSignalException - If no handler has been registered for the given signal
    • registerSignalHandler

      public void registerSignalHandler(SignalHandler handler)
      Register a signal handler to delegate to. The handler is registered for all signals it supports.
      Parameters:
      handler - The handler to register
    • unregisterSignalHandler

      public void unregisterSignalHandler(SignalHandler handler)
      Unregister a signal handler.
      Parameters:
      handler - The handler to unregister
    • hasReceivedSignals

      public boolean hasReceivedSignals()
      Check if any signals has been received by this handler.
      Returns:
      TRUE if at least one signal has been received, FALSE otherwise
      Since:
      2.16
    • getReceivedSignals

      public List<Signal> getReceivedSignals()
      Get the list of received signals. Calling this method clears the internal list and if no signals are received in the meantime, the next call to this method will return null.
      Returns:
      A list with signals in the order they were received, or null if no signals has been received
      Since:
      2.16
    • hasReceived

      public boolean hasReceived(Signal signal)
      Check if the given signal has been received by this signal handler.
      Parameters:
      signal - The signal to check for
      Returns:
      TRUE if the signal has been received, FALSE otherwise
      Since:
      2.16