Class LocalSignalReceiver

java.lang.Object
net.sf.basedb.core.signal.AbstractSignalReceiver
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: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
      Log signals processing.
    • receivers

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

      private String receiverId
  • Constructor Details

    • LocalSignalReceiver

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

    • 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