Changeset 5399


Ignore:
Timestamp:
Sep 2, 2010, 2:09:15 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1502: Add Signal.SHUTDOWN to plug-in signal system

The SHUTDOWN signal is now defined in the system and the job agent and internal job queue use this when shutting down (if supported by the plug-in, otherwise the ABORT signal is used).

No currently existing plug-ins support the SHUTDOWN signal and there is not support in the core or job agents to resume a job when the server starts up.

Location:
trunk/src
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/Agent.java

    r5384 r5399  
    935935    log.info("Stopping running jobs. " + activeJobs.size() + " job(s) still active.");
    936936   
    937     // Send ABORT to all jobs, that support signals
     937    // Send SHUTDOWN/ABORT to all jobs, that support signals
    938938    signalReceiver.close(closeTimeout);
    939939  }
  • trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/executors/ProcessJobExecutor.java

    r4512 r5399  
    3131import java.util.ArrayList;
    3232import java.util.Arrays;
     33import java.util.Collection;
    3334import java.util.List;
    3435
     
    4041import net.sf.basedb.core.PluginDefinition;
    4142import net.sf.basedb.core.SessionControl;
     43import net.sf.basedb.core.signal.EnhancedThreadSignalHandler;
    4244import net.sf.basedb.core.signal.Signal;
    4345import net.sf.basedb.core.signal.SignalHandler;
    4446import net.sf.basedb.core.signal.SignalReceiver;
    4547import net.sf.basedb.core.signal.SignalTransporter;
    46 import net.sf.basedb.core.signal.ThreadSignalHandler;
    4748import net.sf.basedb.util.Values;
    4849
     
    213214      {
    214215        log.info("Waiting for process to end");
    215         signalHandler = new ThreadSignalHandler();
     216        // This handler will listen for SHUTDOWN signals only
     217        signalHandler = new EnhancedThreadSignalHandler(Signal.SHUTDOWN);
    216218        signalReceiver.registerSignalHandler(signalHandler);
    217219        int exitCode = process.waitFor();
     
    233235      catch (InterruptedException ex)
    234236      {
    235         log.info("Job was interrupted: " + job, ex);
    236         // First, send ABORT to the job if it supports it
     237        log.info("Job was interrupted (job agent is shutting down): " + job, ex);
     238        // First, send SHUTDOWN/ABORT to the job if it supports it
    237239        dc = sc.newDbControl();
    238240        job = Job.getById(dc, job.getId());
     
    240242        if (signalTransporter != null)
    241243        {
    242           signalTransporter.send(Signal.ABORT);
     244          Collection<Signal> supported = signalTransporter.getSupportedSignals();
     245          if (supported == null || supported.contains(Signal.SHUTDOWN))
     246          {
     247            signalTransporter.send(Signal.SHUTDOWN);
     248          }
     249          else
     250          {
     251            signalTransporter.send(Signal.ABORT);
     252          }
    243253        }
    244254        else
  • trunk/src/clients/web/net/sf/basedb/clients/web/util/SimpleSignalProgressReporter.java

    r5384 r5399  
    2525import net.sf.basedb.core.ProgressReporter;
    2626import net.sf.basedb.core.SimpleProgressReporter;
     27import net.sf.basedb.core.signal.ShutdownSignalSender;
    2728import net.sf.basedb.core.signal.Signal;
    2829import net.sf.basedb.core.signal.SignalException;
    2930import net.sf.basedb.core.signal.SignalHandler;
    3031import net.sf.basedb.core.signal.SignalReceiver;
     32import net.sf.basedb.core.signal.SignalSender;
    3133import net.sf.basedb.core.signal.SignalTransporter;
     34import net.sf.basedb.core.signal.SimpleSignalSender;
    3235
    3336/**
     
    7376            public void run()
    7477            {
    75               sendToAll(Signal.ABORT);
     78              sendToAll(new ShutdownSignalSender());
    7679            }
    7780          }
     
    132135  }
    133136
    134   /*  (non-Javadoc)
    135       @see net.sf.basedb.core.signal.SignalReceiver#sendToAll(net.sf.basedb.core.signal.Signal)
    136    */
    137137  @Override
    138138  public void sendToAll(Signal signal)
    139139  {
    140     if (handler == null) return;
    141     logger.info("Sending " + signal);
    142     // Copy the signal handler to a temporary collection,
    143     // since sending a signal may cause a handler to get
    144     // unregistered, which may fail or block due to synchronization
    145     SignalHandler tempHandler = null;
    146     synchronized (handler)
    147     {
    148       try
    149       {     
    150         tempHandler = handler.getClass().newInstance();
    151         if (tempHandler.supports(signal)) tempHandler.handleSignal(signal);
    152       }
    153       catch (Throwable th)
    154       {}
    155     }   
     140    sendToAll(new SimpleSignalSender(signal));
     141  }
     142 
     143  @Override
     144  public void sendToAll(SignalSender sender)
     145  {
     146    // Copy the signal handler to a temporary variable,
     147    // since other threads may unregister the handler
     148    // while we are executing this method
     149    SignalHandler tempHandler = handler;
     150    if (tempHandler == null) return;
     151    logger.info("Sending " + sender);
     152    sender.sendTo(tempHandler);
    156153  }
    157154
  • trunk/src/core/net/sf/basedb/core/InternalJobQueue.java

    r5384 r5399  
    409409    sc.logout();
    410410
    411     // Send ABORT to all jobs that supports signalling
     411    // Send SHUTDOWN/ABORT to all jobs that supports signalling
    412412    signalReceiver.close(closeTimeout);
    413413  }
  • trunk/src/core/net/sf/basedb/core/signal/AbstractSignalReceiver.java

    r4516 r5399  
    104104    should call <code>super.close()</code> if it wants to
    105105    use the default shutdown notification to signal handlers. This
    106     implementation will start a separate notification thread that sends
    107     the {@link Signal#ABORT} signal to all registered handlers. The current
    108     thread will wait at most the given time. If the number of registered handlers
     106    implementation will start a separate notification thread that first sends
     107    the {@link Signal#SHUTDOWN} signal to all registered handlers, and then
     108    {@link Signal#ABORT} signal to all that are still alive after the shutdown signal.
     109    The current thread will wait at most the given time. If the number of registered handlers
    109110    goes down to 0 before the time has ended the current thread will be awakened
    110111    so it can continue. Note that the notification thread will usually finish in
     
    125126          public void run()
    126127          {
    127             logger.info("Sending ABORT to all handlers");
    128             sendToAll(Signal.ABORT);
     128            logger.info("Sending SHUTDOWN/ABORT to all handlers");
     129            sendToAll(new ShutdownSignalSender());
    129130          }
    130131        }
     
    202203  }
    203204 
     205  /**
     206    @deprecated In 2.16, use {@link #sendToAll(SignalSender)} instead
     207  */
     208  @Override
     209  @Deprecated
    204210  public void sendToAll(Signal signal)
    205211  {
     212    sendToAll(new SimpleSignalSender(signal));
     213  }
     214 
     215  @Override
     216  public void sendToAll(SignalSender sender)
     217  {
    206218    if (handlers == null) return;
    207     logger.info("Sending " + signal + " to " + (handlers.size()) + " handlers");
     219    logger.info("Using " + sender + " to " + (handlers.size()) + " handlers");
    208220    // Copy the signal handlers to a temporary collection,
    209221    // since sending a signal may cause a handler to get
     
    216228    for (SignalHandler handler : temp)
    217229    {
    218       if (handler.supports(signal)) handler.handleSignal(signal);
     230      sender.sendTo(handler);
    219231    }
    220232  }
  • trunk/src/core/net/sf/basedb/core/signal/Signal.java

    r4516 r5399  
    4242  /**
    4343    The ABORT signal, that requests that the receiver should
    44     clean up and die.
     44    clean up and die. This signal is typically sent to a plug-in
     45    when the user manually requests that a job is aborted. It is
     46    also sent when the system is shutting down to plug-ins that
     47    doesn't support the {@link #SHUTDOWN} signal.
    4548  */
    4649  public static final Signal ABORT =
     
    5053    );
    5154
     55  /**
     56    The SHUTDOWN signal, that requests that the receiver should
     57    clean up and die. When the system is up again the receiver
     58    may continue were it was stopped if supported. Otherwise,
     59    this signal should be treated as {@link #ABORT}.
     60    @since 2.16
     61  */
     62  public static final Signal SHUTDOWN =
     63    registerSignal("SHUTDOWN", "Shutdown",
     64      "Sending this signal indicates that the system is shutting " +
     65      "down. The receiver should stop whatever it is doing, " +
     66      "cleanup allocated resource and exit. When the system is back " +
     67      "up again, the reciever may continue working were it was stopped."
     68    );
     69
     70 
    5271  /**
    5372    Holds all registered signals.
  • trunk/src/core/net/sf/basedb/core/signal/SignalReceiver.java

    r4516 r5399  
    102102    the {@link Signal#ABORT} when the system is shutting down.
    103103    @param signal The signal to send
     104    @deprecated In 2.16, use {@link #sendToAll(SignalSender)} instead
    104105  */
     106  @Deprecated
    105107  public void sendToAll(Signal signal);
    106108 
     109  /**
     110    Let the signal sender send one or more signals to all registered
     111    signal handlers on this reciever.
     112    @param sender A signal sender implementation
     113    @since 2.16
     114  */
     115  public void sendToAll(SignalSender sender);
     116 
    107117}
Note: See TracChangeset for help on using the changeset viewer.