2.17.2: 2011-06-17

net.sf.basedb.core.signal
Interface SignalReceiver

All Known Implementing Classes:
AbstractSignalReceiver, AgentSignalReceiver, LocalSignalReceiver, SimpleSignalProgressReporter, SocketSignalReceiver

public interface SignalReceiver

A signal receiver is a class that knows how to receive a Signal from a SignalTransporter and how to distribute this to a SignalHandler. Signal receivers are needed to decouple the actual signal handling from the transportation of signals. A signal receiver implementation usually comes in pair with a singal transporter implementation. See, for example, the SocketSignalReceiver and SocketSignalTransporter implementations which uses network sockets to transport signals.

Signal receivers must be thread safe since a single receiver may be used to handle signals for multiple jobs at the same time.

Version:
2.6
Author:
nicklas
See Also:
SignalTransporter, SignalHandler
Last modified
$Date: 2010-09-02 14:09:15 +0200 (Thu, 02 Sep 2010) $

Method Summary
 void close(int wait)
          Close the receiver.
 Class<? extends SignalTransporter> getSignalTransporterClass()
          Get the signal transporter class that should be used to send signals to this receiver.
 void init(String params)
          Initialise the signal receiver.
 String registerSignalHandler(SignalHandler handler)
          Register a signal handler with this receiver.
 void sendToAll(Signal signal)
          Deprecated. In 2.16, use sendToAll(SignalSender) instead
 void sendToAll(SignalSender sender)
          Let the signal sender send one or more signals to all registered signal handlers on this reciever.
 void unregisterSignalHandler(SignalHandler handler)
          Unregister a signal handler from this receiever.
 

Method Detail

init

void init(String params)
Initialise the signal receiver. The syntax and meaning of the parameter sent to it is implementation-dependant. When this method return the signal receiver is ready to register signal handlers and receive signals.

Parameters:
params - Parameters needed to initialise the receiver

close

void close(int wait)
Close the receiver. The receiver should close and cleanup any opened resources, unregister itself if neccesary and stop listening for signals.

Parameters:
wait - If the value is zero or positive, the Signal.ABORT should be sent to all registered signal handlers. The signal receiver should then wait at most the specified number of milliseconds for all signal handlers to get unregistered. If the timeout expires before all signal handlers has processed the signal, the signal receiver should continue it's shutdown.

getSignalTransporterClass

Class<? extends SignalTransporter> getSignalTransporterClass()
Get the signal transporter class that should be used to send signals to this receiver.

Returns:
A class objects that must be a subclass of SignalTransporter

registerSignalHandler

String registerSignalHandler(SignalHandler handler)
Register a signal handler with this receiver. The receiver should return a string, that, when used with the SignalTransporter.init(String) method lets the transporter know how to send a signal to the specific handler. The SocketSignalReceiver will for example, include the IP number and port the transporter should connect to and a unique ID that allows the receiver to locate the signal hander the signal is intended for. The format of the ID is implementation specific and need only to be understandable by the receiver and transporter implementations.

Parameters:
handler - The signal handler that should receive signals through this receiver
Returns:
A string that allows a transporter instance locate and send a signal to the given signal handler
See Also:
AbstractSignalReceiver

unregisterSignalHandler

void unregisterSignalHandler(SignalHandler handler)
Unregister a signal handler from this receiever. After this method returns, the receiver must not send any more signals to the specified handler.

Parameters:
handler - The handler to unregister

sendToAll

@Deprecated
void sendToAll(Signal signal)
Deprecated. In 2.16, use sendToAll(SignalSender) instead

Send a signal to all registered signal handlers that supports it. The main purpose of this method is to be able to send the Signal.ABORT when the system is shutting down.

Parameters:
signal - The signal to send

sendToAll

void sendToAll(SignalSender sender)
Let the signal sender send one or more signals to all registered signal handlers on this reciever.

Parameters:
sender - A signal sender implementation
Since:
2.16

2.17.2: 2011-06-17