Package net.sf.basedb.core.signal
Class DelegatingSignalHandler
java.lang.Object
net.sf.basedb.core.signal.AbstractSignalHandler
net.sf.basedb.core.signal.DelegatingSignalHandler
- All Implemented Interfaces:
SignalHandler
,Action
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 Summary
-
Constructor Summary
ConstructorDescriptionCreate a new delegating signal handler.DelegatingSignalHandler
(SignalHandler... handlers) Create a new delegating signal handler and register the given handlers as delegates. -
Method Summary
Modifier and TypeMethodDescriptionGet the list of received signals.Get all signals that are supported by this handler.void
handleSignal
(Signal signal) Handler the given signal by invokingSignalHandler.handleSignal(Signal)
on each registered signal handler.boolean
hasReceived
(Signal signal) Check if the given signal has been received by this signal handler.boolean
Check if any signals has been received by this handler.void
registerSignalHandler
(SignalHandler handler) Register a signal handler to delegate to.boolean
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
-
Field Details
-
logger
Log signals processing. -
handlers
Holds the registered signal handlers. -
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 withregisterSignalHandler(SignalHandler)
. -
DelegatingSignalHandler
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
Description copied from interface:SignalHandler
Get all signals that are supported by this handler.- Specified by:
getSupportedSignals
in interfaceSignalHandler
- Overrides:
getSupportedSignals
in classAbstractSignalHandler
- Returns:
- A collection containing all signals that have at least one registered handler
-
supports
Check if at least one handler has been registered for the given signal.- Specified by:
supports
in interfaceSignalHandler
- Overrides:
supports
in classAbstractSignalHandler
- Parameters:
signal
- The signal to check- Returns:
- TRUE if the signal is supported, FALSE otherwise
-
handleSignal
Handler the given signal by invokingSignalHandler.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
Register a signal handler to delegate to. The handler is registered for all signals it supports.- Parameters:
handler
- The handler to register
-
unregisterSignalHandler
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
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
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
-