File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\node_monitors\NodeMonitorUpdater.java.html

1 package hudson.node_monitors;
2
3 import hudson.Extension;
4 import hudson.model.Computer;
5 import hudson.model.TaskListener;
6 import hudson.slaves.ComputerListener;
7 import hudson.util.DaemonThreadFactory;
8 import jenkins.model.Jenkins;
9
10 import java.io.IOException;
11 import java.util.concurrent.ScheduledExecutorService;
12 import java.util.concurrent.ScheduledThreadPoolExecutor;
13 import java.util.concurrent.TimeUnit;
14
15 /**
16 * When a slave is connected, redo the node monitoring.
17 *
18 * @author Kohsuke Kawaguchi
19 */
20 @Extension
21 public class NodeMonitorUpdater extends ComputerListener {
22 // TODO: shutdown hook to kill off this timer
23 private final ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1,new DaemonThreadFactory());
24
25 private volatile long timestamp;
26
27 /**
28 * Triggers the update with 5 seconds quiet period, to avoid triggering data check too often
29 * when multiple slaves become online at about the same time.
30 */
31 @Override
32 public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
33 timestamp = System.currentTimeMillis();
34 timer.schedule(new Runnable() {
35 public void run() {
36 if (System.currentTimeMillis()-timestamp<4000)
37 return;
38
39 for (NodeMonitor nm : Jenkins.getInstance().getComputer().getMonitors()) {
40 nm.triggerUpdate();
41 }
42 }
43 }, 5, TimeUnit.SECONDS);
44 }
45 }
46