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

1 package hudson.model;
2
3 import hudson.Extension;
4 import hudson.ExtensionList;
5 import hudson.ExtensionPoint;
6 import jenkins.model.Jenkins;
7
8 import java.io.IOException;
9
10 /**
11 * Extension point that allows plugins to veto the restart.
12 *
13 * @author Kohsuke Kawaguchi
14 * @since 1.376
15 */
16 public abstract class RestartListener implements ExtensionPoint {
17 /**
18 * Called periodically during the safe restart.
19 *
20 * @return false to block the restart
21 */
22 public abstract boolean isReadyToRestart() throws IOException, InterruptedException;
23
24 /**
25 * Called immediately before the restart is actually triggered.
26 */
27 public void onRestart() {}
28
29 /**
30 * Returns all the registered {@link LabelFinder}s.
31 */
32 public static ExtensionList<RestartListener> all() {
33 return Jenkins.getInstance().getExtensionList(RestartListener.class);
34 }
35
36 /**
37 * Returns true iff all the listeners OKed the restart.
38 */
39 public static boolean isAllReady() throws IOException, InterruptedException {
40 for (RestartListener listener : all()) {
41 if (!listener.isReadyToRestart())
42 return false;
43 }
44 return true;
45 }
46
47 /**
48 * Default logic. Wait for all the executors to become idle.
49 */
50 @Extension
51 public static class Default extends RestartListener {
52 @Override
53 public boolean isReadyToRestart() throws IOException, InterruptedException {
54 Jenkins h = Jenkins.getInstance();
55 return h.overallLoad.computeTotalExecutors() <= h.overallLoad.computeIdleExecutors();
56 }
57 }
58 }
59