2.17.2: 2011-06-17

net.sf.basedb.core.signal
Class DelegatingSignalHandler

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

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: 2010-09-13 12:36:49 +0200 (Mon, 13 Sep 2010) $

Field Summary
private  Map<Signal,Set<SignalHandler>> handlers
          Holds the registered signal handlers.
private static Logger logger
          Log signals processing.
private  List<Signal> received
          List holding received signals.
 
Constructor Summary
DelegatingSignalHandler()
          Create a new delegating signal handler.
DelegatingSignalHandler(SignalHandler... handlers)
          Create a new delegating signal handler and register the given handlers as delegates.
 
Method Summary
 List<Signal> getReceivedSignals()
          Get the list of received signals.
 Collection<Signal> getSupportedSignals()
          Get all signals that are supported by this handler.
 void handleSignal(Signal signal)
          Handler the given signal by invoking SignalHandler.handleSignal(Signal) on each registered signal handler.
 boolean hasReceived(Signal signal)
          Check if the given signal has been received by this signal handler.
 boolean hasReceivedSignals()
          Check if any signals has been received by this handler.
 void registerSignalHandler(SignalHandler handler)
          Register a signal handler to delegate to.
 boolean supports(Signal signal)
          Check if at least one handler has been registered for the given signal.
 void unregisterSignalHandler(SignalHandler handler)
          Unregister a signal handler.
 
Methods inherited from class net.sf.basedb.core.signal.AbstractSignalHandler
addSignal, removeSignal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

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 Detail

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

2.17.2: 2011-06-17