Class AsynchronousExecution
- All Implemented Interfaces:
Serializable
Executor
).
May be thrown from Queue.Executable.run()
after doing any preparatory work synchronously.
Executor.isActive()
will remain true (even though Thread.isAlive()
is not) until completed(java.lang.Throwable)
is called.
The thrower could hold on to a reference to this instance as a handle to call completed(java.lang.Throwable)
,
or look it up later via Executor.getAsynchronousExecution()
.
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.
Mainly intended for use with OneOffExecutor
(from a 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.
ResourceController
/ResourceActivity
/ResourceList
/Resource
are not currently supported.
Nor are Queue.Task.getSubTasks()
other than the primary task.
- Since:
- 1.607
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
Allows an executable to indicate whether it is currently doing something which should prevent Jenkins from being shut down safely.final void
To be called when the task is actually complete.abstract boolean
Allows an executable to control whether or not to displayexecutorCell.jelly
.final Executor
Obtains the associated executor.abstract void
interrupt
(boolean forShutdown) Called in lieu ofThread.interrupt()
byExecutor.interrupt()
and its overloads.final void
If there is a pending completion notification, deliver it to the executor.final void
setExecutorWithoutCompleting
(Executor executor) Set the executor without notifying it about task completion.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
AsynchronousExecution
protected AsynchronousExecution()Constructor for subclasses.
-
-
Method Details
-
interrupt
public abstract void interrupt(boolean forShutdown) Called in lieu ofThread.interrupt()
byExecutor.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 callExecutor.recordCauseOfInterruption(hudson.model.Run<?, ?>, hudson.model.TaskListener)
ongetExecutor()
.- Parameters:
forShutdown
- if true, this interruption is because Jenkins is shutting down (and thusComputer.interrupt()
was called fromJenkins.cleanUp()
); otherwise, a normal interrupt such as byExecutor.doStop()
-
blocksRestart
public abstract boolean blocksRestart()Allows an executable to indicate whether it is currently doing something which should prevent Jenkins from being shut down safely. You may return false if it is fine for an administrator to exit/restart Jenkins despite this executable still being running. (If so,interrupt(boolean)
will be passedforShutdown=true
.)- Returns:
- traditionally always true
- See Also:
-
displayCell
public abstract boolean displayCell()Allows an executable to control whether or not to displayexecutorCell.jelly
.If this method returns false, the asynchronous execution becomes invisible from UI.
- Returns:
- traditionally always true
-
getExecutor
Obtains the associated executor.- Returns:
- Associated Executor. May be
null
ifsetExecutorWithoutCompleting(hudson.model.Executor)
has not been called yet.
-
setExecutorWithoutCompleting
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void setExecutorWithoutCompleting(@NonNull Executor executor) Set the executor without notifying it about task completion. The caller must also callmaybeComplete()
after releasing any problematic locks. -
maybeComplete
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final void maybeComplete()If there is a pending completion notification, deliver it to the executor. Must be called aftersetExecutorWithoutCompleting(Executor)
. -
completed
To be called when the task is actually complete.- Parameters:
error
- normally null (preferable to handle errors yourself), but may be specified to simulate an exception fromQueue.Executable.run()
, as perExecutorListener.taskCompletedWithProblems(hudson.model.Executor, hudson.model.Queue.Task, long, java.lang.Throwable)
-