2.17.2: 2011-06-17

net.sf.basedb.core.signal
Class LocalSignalReceiver

java.lang.Object
  extended by net.sf.basedb.core.signal.AbstractSignalReceiver
      extended by net.sf.basedb.core.signal.LocalSignalReceiver
All Implemented Interfaces:
SignalReceiver

public class LocalSignalReceiver
extends AbstractSignalReceiver

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: 2008-09-11 22:09:17 +0200 (Thu, 11 Sep 2008) $

Field Summary
private static Logger logger
          Log signals processing.
private  String receiverId
           
private static Map<String,LocalSignalReceiver> receivers
          Holds all registered signal receivers.
 
Constructor Summary
LocalSignalReceiver()
          Create a new local signal receiver.
 
Method Summary
 void close(int wait)
          Close this signal receiver.
static LocalSignalReceiver getSignalReceiver(String id)
          Get a signal receiver with a given ID.
 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.
 void send(String handlerId, Signal signal)
          Send the signal to a registered handler.
 
Methods inherited from class net.sf.basedb.core.signal.AbstractSignalReceiver
getGlobalSignalId, getLocalSignalHandlerId, getReceiverId, getSignalHandler, processSignalMessage, registerSignalHandler, sendToAll, sendToAll, unregisterSignalHandler
 
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.


receivers

private static Map<String,LocalSignalReceiver> receivers
Holds all registered signal receivers.


receiverId

private String receiverId
Constructor Detail

LocalSignalReceiver

public LocalSignalReceiver()
Create a new local signal receiver. Before it can be used it must be initialised with init(String).

Method Detail

getSignalReceiver

public static LocalSignalReceiver getSignalReceiver(String id)
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

public void init(String params)
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 interface SignalReceiver
Overrides:
init in class AbstractSignalReceiver
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 call 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.

Specified by:
close in interface SignalReceiver
Overrides:
close in class AbstractSignalReceiver
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

public Class<? extends SignalTransporter> getSignalTransporterClass()
Description copied from interface: SignalReceiver
Get the signal transporter class that should be used to send signals to this receiver.

Returns:
LocalSignalTransporter

send

public void send(String handlerId,
                 Signal signal)
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 handler
signal - The signal to send

2.17.2: 2011-06-17