/*******************************************************************************
*
* Copyright (c) 2004-2010 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*
*
*******************************************************************************/
package hudson.model;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import java.io.IOException;
/**
* Extension point that allows plugins to veto the restart.
*
* @author Kohsuke Kawaguchi
* @since 1.376
*/
public abstract class RestartListener implements ExtensionPoint {
/**
* Called periodically during the safe restart.
*
* @return false to block the restart
*/
public abstract boolean isReadyToRestart() throws IOException, InterruptedException;
/**
* Called immediately before the restart is actually triggered.
*/
public void onRestart() {
}
/**
* Returns all the registered {@link LabelFinder}s.
*/
public static ExtensionList<RestartListener> all() {
return Hudson.getInstance().getExtensionList(RestartListener.class);
}
/**
* Returns true iff all the listeners OKed the restart.
*/
public static boolean isAllReady() throws IOException, InterruptedException {
for (RestartListener listener : all()) {
if (!listener.isReadyToRestart()) {
return false;
}
}
return true;
}
/**
* Default logic. Wait for all the executors to become idle.
*/
@Extension
public static class Default extends RestartListener {
@Override
public boolean isReadyToRestart() throws IOException, InterruptedException {
Hudson h = Hudson.getInstance();
return h.overallLoad.computeTotalExecutors() <= h.overallLoad.computeIdleExecutors();
}
}
}