Package net.sf.basedb.core.signal
Class LocalSignalReceiver
java.lang.Object
net.sf.basedb.core.signal.AbstractSignalReceiver
net.sf.basedb.core.signal.LocalSignalReceiver
- All Implemented Interfaces:
SignalReceiver
A signal receiver implementation that can receive signals from the
local virtual machine only. The corresponding transporter class
is
LocalSignalTransporter
.- Version:
- 2.6
- Author:
- nicklas
- Last modified
- $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final Logger
Log signals processing.private String
private static Map<String,
LocalSignalReceiver> Holds all registered signal receivers. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close
(int wait) Close this signal receiver.static LocalSignalReceiver
Get a signal receiver with a given ID.Class<? extends SignalTransporter>
Get the signal transporter class that should be used to send signals to this receiver.void
Initialise the signal receiver.void
Send the signal to a registered handler.Methods inherited from class net.sf.basedb.core.signal.AbstractSignalReceiver
getGlobalSignalId, getLocalSignalHandlerId, getReceiverId, getSignalHandler, processSignalMessage, registerSignalHandler, sendToAll, unregisterSignalHandler
-
Field Details
-
logger
Log signals processing. -
receivers
Holds all registered signal receivers. -
receiverId
-
-
Constructor Details
-
LocalSignalReceiver
public LocalSignalReceiver()Create a new local signal receiver. Before it can be used it must be initialised withinit(String)
.
-
-
Method Details
-
getSignalReceiver
Get a signal receiver with a given ID.- Parameters:
id
- The ID of the signal receiver- Returns:
- A signal receiver, or null if no receiver with the given ID exists.
-
init
Initialise the signal receiver. The given parameter becomes the ID of the receiver. When this method return the signal receiver is ready to register signal handlers and receive signals.- Specified by:
init
in interfaceSignalReceiver
- Overrides:
init
in classAbstractSignalReceiver
- Parameters:
params
- The ID of the signal receiver, needed if the default ID generation should be used
-
close
public void close(int wait) Description copied from class:AbstractSignalReceiver
Close this signal receiver. If a subclass overrides this method it should callsuper.close()
if it wants to use the default shutdown notification to signal handlers. This implementation will start a separate notification thread that first sends theSignal.SHUTDOWN
signal to all registered handlers, and thenSignal.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.- Specified by:
close
in interfaceSignalReceiver
- Overrides:
close
in classAbstractSignalReceiver
- Parameters:
wait
- Number of milliseconds to wait for registered jobs to abort, use a negative value to disable notification, and 0 to disable waiting
-
getSignalTransporterClass
Description copied from interface:SignalReceiver
Get the signal transporter class that should be used to send signals to this receiver.- Returns:
LocalSignalTransporter
-
send
Send the signal to a registered handler. If no handler with the given ID is found this method does nothing. The signal will be processed by the handler in the current thread.- Parameters:
handlerId
- The ID of a registered handlersignal
- The signal to send
-