|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.signal.AbstractSignalReceiver
public abstract class AbstractSignalReceiver
Abstract base class that is useful when implementing signal receivers.
This class helps with keeping track of signal handlers and with generating
return values for the registerSignalHandler(SignalHandler)
method.
This class will generate values in the form of URI
:s.
signal://handlerId@receiverId/?supportedSignals
.
init(String)
method and must be set by the implementing
subclass.
getLocalSignalHandlerId(SignalHandler)
.
This method may be overridden by subclasses that needs a different method of
local ID generation. The important thing is that the ID is unique among all
registered signal handlers.
SignalHandler.getSupportedSignals()
into a comma-separated string.
AbstractSignalTransporter
contains methods for parsing this scheme
and make the information available to subclasses as a URI
and
as higher-level objects.
Subclasses should override the getGlobalSignalId(SignalHandler)
if they
want to use a different ID generation scheme.
Field Summary | |
---|---|
private Map<String,SignalHandler> |
handlers
Maps local signal handler ID to -> signal handler itself. |
private static Logger |
logger
Log signals processing. |
private Thread |
notifyThread
|
private String |
receiverId
|
Constructor Summary | |
---|---|
protected |
AbstractSignalReceiver()
Create a new signal receiver. |
Method Summary | |
---|---|
void |
close(int wait)
Close this signal receiver. |
protected String |
getGlobalSignalId(SignalHandler handler)
Generate a signal ID string. |
protected String |
getLocalSignalHandlerId(SignalHandler handler)
Get the local signal handler id of the given signal handler. |
protected String |
getReceiverId()
Get the receiver ID that was passed to the init(String)
method. |
protected SignalHandler |
getSignalHandler(String localId)
Get the signal handler with a given ID. |
void |
init(String receiverId)
Initialise the signal receiver. |
protected void |
processSignalMessage(String message)
Process a signal message. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.basedb.core.signal.SignalReceiver |
---|
getSignalTransporterClass |
Field Detail |
---|
private static final Logger logger
private Map<String,SignalHandler> handlers
private String receiverId
private Thread notifyThread
Constructor Detail |
---|
protected AbstractSignalReceiver()
Method Detail |
---|
public void init(String receiverId)
init
in interface SignalReceiver
receiverId
- The ID of the signal receiver, needed if the default
ID generation should be usedpublic void close(int wait)
super.close()
if it wants to
use the default shutdown notification to signal handlers. This
implementation will start a separate notification thread that first sends
the Signal.SHUTDOWN
signal to all registered handlers, and then
Signal.ABORT
signal to all that are still alive after the shutdown signal.
The current thread will wait at most the given time. If the number of registered handlers
goes down to 0 before the time has ended the current thread will be awakened
so it can continue. Note that the notification thread will usually finish in
a short time, but it may take longer for all worker thread of each job to
react to the signal.
close
in interface SignalReceiver
wait
- Number of milliseconds to wait for registered jobs to abort,
use a negative value to disable notification, and 0 to disable waitingpublic String registerSignalHandler(SignalHandler handler)
registerSignalHandler
in interface SignalReceiver
handler
- The signal handler to register
AbstractSignalReceiver
public void unregisterSignalHandler(SignalHandler handler)
unregisterSignalHandler
in interface SignalReceiver
handler
- The signal handler to unregister@Deprecated public void sendToAll(Signal signal)
sendToAll(SignalSender)
instead
SignalReceiver
Signal.ABORT
when the system is shutting down.
sendToAll
in interface SignalReceiver
signal
- The signal to sendpublic void sendToAll(SignalSender sender)
SignalReceiver
sendToAll
in interface SignalReceiver
sender
- A signal sender implementationprotected String getReceiverId()
init(String)
method.
protected String getGlobalSignalId(SignalHandler handler)
registerSignalHandler(SignalHandler)
method and is used
in SignalTransporter.init(String)
method to initialise
a transporter object so that it can send signals to the specified handler.
See the class documentation for a description of the format of the
generated string. The string is of the format:
signal://handlerId@receiverId/?supportedSignals
See class description for detailed information.
handler
- The signal handler to generate the ID for
protected String getLocalSignalHandlerId(SignalHandler handler)
handler
- The handler to get the id for
protected SignalHandler getSignalHandler(String localId)
localId
- The local signal handler ID as
returned by the getLocalSignalHandlerId(SignalHandler)
method
protected void processSignalMessage(String message)
message
- The message to process, the format of the message
must be compatible with the message that AbstractSignalTransporter.generateSignalMessage(Signal)
generates
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |