提交 d073f799 编写于 作者: J Jesse Glick

Abandoning Executable2; doing everything in AsynchronousExecution.

上级 09f7a2d3
......@@ -30,6 +30,8 @@ import hudson.EnvVars;
import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.console.AnnotatedLargeText;
import hudson.console.ExpandableDetailsNote;
import hudson.console.ModelHyperlinkNote;
import hudson.model.Fingerprint.BuildPtr;
import hudson.model.Fingerprint.RangeSet;
......@@ -68,6 +70,7 @@ import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.AbstractSet;
import java.util.ArrayList;
......@@ -90,7 +93,6 @@ import static java.util.logging.Level.WARNING;
import jenkins.model.lazy.BuildReference;
import jenkins.model.lazy.LazyBuildMixIn;
import jenkins.model.queue.Executable2;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
......@@ -102,7 +104,7 @@ import org.kohsuke.accmod.restrictions.DoNotUse;
* @author Kohsuke Kawaguchi
* @see AbstractProject
*/
public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Run<P,R> implements Executable2, LazyBuildMixIn.LazyLoadingRun<P,R> {
public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Run<P,R> implements Queue.Executable, LazyBuildMixIn.LazyLoadingRun<P,R> {
/**
* Set if we want the blame information to flow from upstream to downstream build.
......
......@@ -60,7 +60,7 @@ import static hudson.model.queue.Executables.*;
import static java.util.logging.Level.*;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.queue.Executable2.AsynchronousExecution;
import jenkins.model.queue.AsynchronousExecution;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
......
......@@ -120,7 +120,7 @@ import org.kohsuke.accmod.restrictions.DoNotUse;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
import javax.annotation.CheckForNull;
import jenkins.model.queue.Executable2;
import jenkins.model.queue.AsynchronousExecution;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.interceptor.RequirePOST;
......@@ -1479,9 +1479,10 @@ public class Queue extends ResourceController implements Saveable {
@Nonnull SubTask getParent();
/**
* Called by {@link Executor} to perform the task
* Called by {@link Executor} to perform the task.
* @throws AsynchronousExecution if you would like to continue without consuming a thread
*/
@Override void run();
@Override void run() throws AsynchronousExecution;
/**
* Estimate of how long will it take to execute this executable.
......
......@@ -28,7 +28,6 @@ import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.ExecutorListener;
import hudson.model.OneOffExecutor;
import hudson.model.Queue;
import hudson.model.Resource;
import hudson.model.ResourceActivity;
import hudson.model.ResourceController;
......@@ -39,64 +38,51 @@ import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
/**
* Extended interface for running tasks with some additional logic.
* Special means of indicating that an executable will proceed in the background without consuming a native thread ({@link Executor}).
* May be thrown from {@link hudson.model.Queue.Executable#run} after doing any preparatory work synchronously.
* <p>{@link Executor#isActive} will remain true (even though {@link Executor#isAlive} is not) until {@link #completed} is called.
* The thrower will need to hold on to a reference to this instance as a handle to call {@link #completed}.
* <p>The execution may not extend into another Jenkins session; if you wish to model a long-running execution, you must schedule a new task after restart.
* This class is not serializable anyway.
* <p>Mainly intended for use with {@link OneOffExecutor} (from a {@link hudson.model.Queue.FlyweightTask}), of which there could be many,
* but could also be used with a heavyweight executor even though the number of executors is bounded by node configuration.
* <p>{@link ResourceController}/{@link ResourceActivity}/{@link ResourceList}/{@link Resource} are not currently supported.
* Nor are {@link hudson.model.Queue.Task#getSubTasks} other than the primary task.
* @since TODO
*/
public interface Executable2 extends Queue.Executable {
public abstract class AsynchronousExecution extends RuntimeException {
private Executor executor;
/** Constructor for subclasses. */
protected AsynchronousExecution() {}
/**
* {@inheritDoc}
* @throws AsynchronousExecution if you would like to continue without consuming a thread
* Called in lieu of {@link Thread#interrupt} by {@link Executor#interrupt()} and its overloads.
* As with the standard Java method, you are requested to cease work as soon as possible, but there is no enforcement of this.
* You might also want to call {@link Executor#recordCauseOfInterruption} on {@link #getExecutor}.
* @param forShutdown if true, this interruption is because Jenkins is shutting down (and thus {@link Computer#interrupt} was called from {@link Jenkins#cleanUp}); otherwise, a normal interrupt such as by {@link Executor#doStop()}
*/
@Override void run() throws AsynchronousExecution;
public abstract void interrupt(boolean forShutdown);
/**
* Special means of indicating that an executable will proceed in the background without consuming a native thread ({@link Executor}).
* May be thrown from {@link Executable2#run} after doing any preparatory work synchronously.
* <p>{@link Executor#isActive} will remain true (even though {@link Executor#isAlive} is not) until {@link #completed} is called.
* The thrower will need to hold on to a reference to this instance as a handle to call {@link #completed}.
* <p>The execution may not extend into another Jenkins session; if you wish to model a long-running execution, you must schedule a new task after restart.
* This class is not serializable anyway.
* <p>Mainly intended for use with {@link OneOffExecutor} (from a {@link hudson.model.Queue.FlyweightTask}), of which there could be many,
* but could also be used with a heavyweight executor even though the number of executors is bounded by node configuration.
* <p>{@link ResourceController}/{@link ResourceActivity}/{@link ResourceList}/{@link Resource} are not currently supported.
* Nor are {@link hudson.model.Queue.Task#getSubTasks} other than the primary task.
* Obtains the associated executor.
*/
abstract class AsynchronousExecution extends RuntimeException {
private Executor executor;
/** Constructor for subclasses. */
protected AsynchronousExecution() {}
/**
* Called in lieu of {@link Thread#interrupt} by {@link Executor#interrupt()} and its overloads.
* As with the standard Java method, you are requested to cease work as soon as possible, but there is no enforcement of this.
* You might also want to call {@link Executor#recordCauseOfInterruption} on {@link #getExecutor}.
* @param forShutdown if true, this interruption is because Jenkins is shutting down (and thus {@link Computer#interrupt} was called from {@link Jenkins#cleanUp}); otherwise, a normal interrupt such as by {@link Executor#doStop()}
*/
public abstract void interrupt(boolean forShutdown);
/**
* Obtains the associated executor.
*/
public final Executor getExecutor() {
return executor;
}
@Restricted(NoExternalUse.class)
public final void setExecutor(Executor executor) {
this.executor = executor;
}
public final Executor getExecutor() {
return executor;
}
/**
* To be called when the task is actually complete.
* @param error normally null (preferable to handle errors yourself), but may be specified to simulate an exception from {@link Executable2#run}, as per {@link ExecutorListener#taskCompletedWithProblems}
*/
public final void completed(@CheckForNull Throwable error) {
executor.completedAsynchronous(error);
}
@Restricted(NoExternalUse.class)
public final void setExecutor(Executor executor) {
this.executor = executor;
}
/**
* To be called when the task is actually complete.
* @param error normally null (preferable to handle errors yourself), but may be specified to simulate an exception from {@link hudson.model.Queue.Executable#run}, as per {@link ExecutorListener#taskCompletedWithProblems}
*/
public final void completed(@CheckForNull Throwable error) {
executor.completedAsynchronous(error);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册