Changeset 5399
- Timestamp:
- Sep 2, 2010, 2:09:15 PM (13 years ago)
- 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 935 935 log.info("Stopping running jobs. " + activeJobs.size() + " job(s) still active."); 936 936 937 // Send ABORT to all jobs, that support signals937 // Send SHUTDOWN/ABORT to all jobs, that support signals 938 938 signalReceiver.close(closeTimeout); 939 939 } -
trunk/src/clients/jobagent/net/sf/basedb/clients/jobagent/executors/ProcessJobExecutor.java
r4512 r5399 31 31 import java.util.ArrayList; 32 32 import java.util.Arrays; 33 import java.util.Collection; 33 34 import java.util.List; 34 35 … … 40 41 import net.sf.basedb.core.PluginDefinition; 41 42 import net.sf.basedb.core.SessionControl; 43 import net.sf.basedb.core.signal.EnhancedThreadSignalHandler; 42 44 import net.sf.basedb.core.signal.Signal; 43 45 import net.sf.basedb.core.signal.SignalHandler; 44 46 import net.sf.basedb.core.signal.SignalReceiver; 45 47 import net.sf.basedb.core.signal.SignalTransporter; 46 import net.sf.basedb.core.signal.ThreadSignalHandler;47 48 import net.sf.basedb.util.Values; 48 49 … … 213 214 { 214 215 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); 216 218 signalReceiver.registerSignalHandler(signalHandler); 217 219 int exitCode = process.waitFor(); … … 233 235 catch (InterruptedException ex) 234 236 { 235 log.info("Job was interrupted : " + job, ex);236 // First, send ABORT to the job if it supports it237 log.info("Job was interrupted (job agent is shutting down): " + job, ex); 238 // First, send SHUTDOWN/ABORT to the job if it supports it 237 239 dc = sc.newDbControl(); 238 240 job = Job.getById(dc, job.getId()); … … 240 242 if (signalTransporter != null) 241 243 { 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 } 243 253 } 244 254 else -
trunk/src/clients/web/net/sf/basedb/clients/web/util/SimpleSignalProgressReporter.java
r5384 r5399 25 25 import net.sf.basedb.core.ProgressReporter; 26 26 import net.sf.basedb.core.SimpleProgressReporter; 27 import net.sf.basedb.core.signal.ShutdownSignalSender; 27 28 import net.sf.basedb.core.signal.Signal; 28 29 import net.sf.basedb.core.signal.SignalException; 29 30 import net.sf.basedb.core.signal.SignalHandler; 30 31 import net.sf.basedb.core.signal.SignalReceiver; 32 import net.sf.basedb.core.signal.SignalSender; 31 33 import net.sf.basedb.core.signal.SignalTransporter; 34 import net.sf.basedb.core.signal.SimpleSignalSender; 32 35 33 36 /** … … 73 76 public void run() 74 77 { 75 sendToAll( Signal.ABORT);78 sendToAll(new ShutdownSignalSender()); 76 79 } 77 80 } … … 132 135 } 133 136 134 /* (non-Javadoc)135 @see net.sf.basedb.core.signal.SignalReceiver#sendToAll(net.sf.basedb.core.signal.Signal)136 */137 137 @Override 138 138 public void sendToAll(Signal signal) 139 139 { 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); 156 153 } 157 154 -
trunk/src/core/net/sf/basedb/core/InternalJobQueue.java
r5384 r5399 409 409 sc.logout(); 410 410 411 // Send ABORT to all jobs that supports signalling411 // Send SHUTDOWN/ABORT to all jobs that supports signalling 412 412 signalReceiver.close(closeTimeout); 413 413 } -
trunk/src/core/net/sf/basedb/core/signal/AbstractSignalReceiver.java
r4516 r5399 104 104 should call <code>super.close()</code> if it wants to 105 105 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 109 110 goes down to 0 before the time has ended the current thread will be awakened 110 111 so it can continue. Note that the notification thread will usually finish in … … 125 126 public void run() 126 127 { 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()); 129 130 } 130 131 } … … 202 203 } 203 204 205 /** 206 @deprecated In 2.16, use {@link #sendToAll(SignalSender)} instead 207 */ 208 @Override 209 @Deprecated 204 210 public void sendToAll(Signal signal) 205 211 { 212 sendToAll(new SimpleSignalSender(signal)); 213 } 214 215 @Override 216 public void sendToAll(SignalSender sender) 217 { 206 218 if (handlers == null) return; 207 logger.info(" Sending " + signal+ " to " + (handlers.size()) + " handlers");219 logger.info("Using " + sender + " to " + (handlers.size()) + " handlers"); 208 220 // Copy the signal handlers to a temporary collection, 209 221 // since sending a signal may cause a handler to get … … 216 228 for (SignalHandler handler : temp) 217 229 { 218 if (handler.supports(signal)) handler.handleSignal(signal);230 sender.sendTo(handler); 219 231 } 220 232 } -
trunk/src/core/net/sf/basedb/core/signal/Signal.java
r4516 r5399 42 42 /** 43 43 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. 45 48 */ 46 49 public static final Signal ABORT = … … 50 53 ); 51 54 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 52 71 /** 53 72 Holds all registered signals. -
trunk/src/core/net/sf/basedb/core/signal/SignalReceiver.java
r4516 r5399 102 102 the {@link Signal#ABORT} when the system is shutting down. 103 103 @param signal The signal to send 104 @deprecated In 2.16, use {@link #sendToAll(SignalSender)} instead 104 105 */ 106 @Deprecated 105 107 public void sendToAll(Signal signal); 106 108 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 107 117 }
Note: See TracChangeset
for help on using the changeset viewer.