提交 f07fb853 编写于 作者: S Stephen Connolly

Allow Node and RetentionStrategy to contribute to Computer#isAcceptingTasks

上级 582128b9
......@@ -24,6 +24,8 @@
*/
package hudson.model;
import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;
import edu.umd.cs.findbugs.annotations.When;
import hudson.EnvVars;
import hudson.Launcher.ProcStarter;
import hudson.Util;
......@@ -1318,9 +1320,13 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* scheduling that does not overlap with being offline.
*
* @return {@code true} if the computer is accepting tasks
* @see hudson.slaves.RetentionStrategy#isAcceptingTasks(Computer)
* @see hudson.model.Node#isAcceptingTasks()
*/
@OverrideMustInvoke(When.ANYTIME)
public boolean isAcceptingTasks() {
return true;
final Node node = getNode();
return getRetentionStrategy().isAcceptingTasks(this) && (node == null || node.isAcceptingTasks());
}
/**
......
......@@ -194,6 +194,19 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable
*/
protected abstract Computer createComputer();
/**
* Returns {@code true} if the node is accepting tasks. Needed to allow slaves programmatic suspension of task
* scheduling that does not overlap with being offline. Called by {@link Computer#isAcceptingTasks()}.
* This method is distinct from {@link Computer#isAcceptingTasks()} as sometimes the {@link Node} concrete
* class may not have control over the {@link hudson.model.Computer} concrete class associated with it.
*
* @return {@code true} if the node is accepting tasks.
* @see Computer#isAcceptingTasks()
*/
public boolean isAcceptingTasks() {
return true;
}
/**
* Let Nodes be aware of the lifecycle of their own {@link Computer}.
*/
......
......@@ -67,6 +67,19 @@ public abstract class RetentionStrategy<T extends Computer> extends AbstractDesc
return true;
}
/**
* Returns {@code true} if the computer is accepting tasks. Needed to allow retention strategies programmatic
* suspension of task scheduling that in preparation for going offline. Called by
* {@link hudson.model.Computer#isAcceptingTasks()}
*
* @param c the computer.
* @return {@code true} if the computer is accepting tasks
* @see hudson.model.Computer#isAcceptingTasks()
*/
public boolean isAcceptingTasks(T c) {
return true;
}
/**
* Called when a new {@link Computer} object is introduced (such as when Hudson started, or when
* a new slave is added.)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册