* 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.
* @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()}
*/
@Overridevoidrun()throwsAsynchronousExecution;
publicabstractvoidinterrupt(booleanforShutdown);
/**
* 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.
* 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()}
*/
publicabstractvoidinterrupt(booleanforShutdown);
/**
* Obtains the associated executor.
*/
publicfinalExecutorgetExecutor(){
returnexecutor;
}
@Restricted(NoExternalUse.class)
publicfinalvoidsetExecutor(Executorexecutor){
this.executor=executor;
}
publicfinalExecutorgetExecutor(){
returnexecutor;
}
/**
* 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}
* 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}