提交 0a474675 编写于 作者: K kohsuke

needs NOOP for the master.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@9404 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d86ffdeb
...@@ -287,7 +287,8 @@ public abstract class Computer extends AbstractModelObject { ...@@ -287,7 +287,8 @@ public abstract class Computer extends AbstractModelObject {
* {@link RetentionStrategy} associated with this computer. * {@link RetentionStrategy} associated with this computer.
* *
* @return * @return
* never null. * never null. This method return {@code RetentionStrategy<? super T>} where
* {@code T=this.getClass()}.
*/ */
public abstract RetentionStrategy getRetentionStrategy(); public abstract RetentionStrategy getRetentionStrategy();
......
...@@ -2357,7 +2357,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node, ...@@ -2357,7 +2357,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
} }
public RetentionStrategy getRetentionStrategy() { public RetentionStrategy getRetentionStrategy() {
return RetentionStrategy.Always.INSTANCE; return RetentionStrategy.NOOP;
} }
@Override @Override
......
...@@ -34,6 +34,18 @@ public abstract class RetentionStrategy<T extends Computer> implements Describab ...@@ -34,6 +34,18 @@ public abstract class RetentionStrategy<T extends Computer> implements Describab
Always.DESCRIPTOR Always.DESCRIPTOR
); );
/**
* Dummy instance that doesn't do any attempt to retention.
*/
public static final RetentionStrategy<Computer> NOOP = new RetentionStrategy<Computer>() {
public long check(Computer c) {
return 1;
}
public Descriptor<RetentionStrategy<?>> getDescriptor() {
throw new UnsupportedOperationException();
}
};
/** /**
* {@link RetentionStrategy} that tries to keep the node online all the time. * {@link RetentionStrategy} that tries to keep the node online all the time.
......
package hudson.slaves;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Slave;
import hudson.util.DescriptorList;
import org.kohsuke.stapler.DataBoundConstructor;
/**
* Slave availability strategy
*/
public abstract class SlaveAvailabilityStrategy implements Describable<SlaveAvailabilityStrategy>, ExtensionPoint {
/**
* This method will be called periodically to allow this strategy to decide what to do with it's owning slave.
* The default implementation takes the slave on-line every time it's off-line.
*
* @param slave The slave that owns this strategy, i.e. {@code slave.getAvailabilityStrategy() == this}
* @param state Some state information that may be useful in deciding what to do.
* @return The number of minutes after which the strategy would like to be checked again. The strategy may be
* rechecked earlier or later that this!
*/
public abstract long check(Slave slave, State state);
/**
* All registered {@link SlaveAvailabilityStrategy} implementations.
*/
public static final DescriptorList<SlaveAvailabilityStrategy> LIST = new DescriptorList<SlaveAvailabilityStrategy>(
Always.DESCRIPTOR
);
public static final class State {
private final boolean jobWaiting;
private final boolean jobRunning;
public State(boolean jobWaiting, boolean jobRunning) {
this.jobWaiting = jobWaiting;
this.jobRunning = jobRunning;
}
public boolean isJobWaiting() {
return jobWaiting;
}
public boolean isJobRunning() {
return jobRunning;
}
}
/**
* {@link SlaveAvailabilityStrategy} that tries to keep the node online all the time.
*/
public static class Always extends SlaveAvailabilityStrategy {
@DataBoundConstructor
public Always() {
}
public long check(Slave slave, State state) {
SlaveComputer c = slave.getComputer();
if (c != null && c.isOffline() && c.isLaunchSupported())
c.tryReconnect();
return 5;
}
public Descriptor<SlaveAvailabilityStrategy> getDescriptor() {
return DESCRIPTOR;
}
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
private static class DescriptorImpl extends Descriptor<SlaveAvailabilityStrategy> {
public DescriptorImpl() {
super(Always.class);
}
public String getDisplayName() {
return "Keep this slave on-line as much as possible";
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册