Class AsynchronousExecution
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- jenkins.model.queue.AsynchronousExecution
-
- All Implemented Interfaces:
Serializable
public abstract class AsynchronousExecution extends RuntimeException
Special means of indicating that an executable will proceed in the background without consuming a native thread (Executor
). May be thrown fromQueue.Executable.run()
after doing any preparatory work synchronously.Executor.isActive()
will remain true (even thoughThread.isAlive()
is not) untilcompleted(java.lang.Throwable)
is called. The thrower could hold on to a reference to this instance as a handle to callcompleted(java.lang.Throwable)
, or look it up later viaExecutor.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 aQueue.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 areQueue.Task.getSubTasks()
other than the primary task.- Since:
- 1.607
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AsynchronousExecution()
Constructor for subclasses.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
blocksRestart()
Allows an executable to indicate whether it is currently doing something which should prevent Jenkins from being shut down safely.void
completed(Throwable error)
To be called when the task is actually complete.abstract boolean
displayCell()
Allows an executable to control whether or not to displayexecutorCell.jelly
.Executor
getExecutor()
Obtains the associated executor.abstract void
interrupt(boolean forShutdown)
Called in lieu ofThread.interrupt()
byExecutor.interrupt()
and its overloads.void
maybeComplete()
If there is a pending completion notification, deliver it to the executor.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
-
-
-
-
Method Detail
-
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:
RestartListener.Default.isReadyToRestart()
-
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
@CheckForNull public final Executor 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
public final void completed(@CheckForNull Throwable error)
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)
-
-