PageRenderTime 23ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/hudson-core/src/main/java/hudson/model/RestartListener.java

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