Package hudson.model
Class Executor
- java.lang.Object
-
- java.lang.Thread
-
- hudson.model.Executor
-
- All Implemented Interfaces:
ModelObject
,Runnable
- Direct Known Subclasses:
OneOffExecutor
@ExportedBean public class Executor extends Thread implements ModelObject
Thread that executes builds. Since 1.536,Executor
s start threads on-demand.Callers should use
isActive()
instead ofThread.isAlive()
.- Author:
- Kohsuke Kawaguchi
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected Computer
owner
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Result
abortResult()
void
completedAsynchronous(Throwable error)
static Executor
currentExecutor()
Returns the executor of the current thread or null if current thread is not an executor.org.kohsuke.stapler.HttpResponse
doStop()
Stops the current build.
You can usedoStopBuild(String)
instead to ensure what will be interrupted is actually what you want to interrupt.void
doStop(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Deprecated.as of 1.489 UsedoStop()
ordoStopBuild(String)
.org.kohsuke.stapler.HttpResponse
doStopBuild(String runExtId)
Stops the current build, if matching the specified external id (or no id is specified, or the currentQueue.Executable
is not aRun
).org.kohsuke.stapler.HttpResponse
doYank()
Deprecated.now a no-opApi
getApi()
Exposes the executor to the remote API.AsynchronousExecution
getAsynchronousExecution()
If currently running in asynchronous mode, returns that handle.Throwable
getCauseOfDeath()
Deprecated.no longer usedCollection<CauseOfInterruption>
getCausesOfInterruption()
Returns causes of interruption.Queue.Executable
getCurrentExecutable()
Returns the current build this executor is running.Queue.Executable
getCurrentExecutableForApi()
Same asgetCurrentExecutable()
but checksItem.READ
.FilePath
getCurrentWorkspace()
If current executable isAbstractBuild
, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.WorkUnit
getCurrentWorkUnit()
Returns the currentWorkUnit
(ofthe current executable
) that this executor is running.String
getDisplayName()
Human readable name of the Jenkins executor.long
getElapsedTime()
static long
getEstimatedDurationFor(Queue.Executable e)
Deprecated.callQueue.Executable.getEstimatedDuration()
directlyString
getEstimatedRemainingTime()
Computes a human-readable text that shows the expected remaining time until the build completes.long
getEstimatedRemainingTimeMillis()
The same asgetEstimatedRemainingTime()
but return it as a number of milli-seconds.long
getIdleStartMilliseconds()
Returns when this executor started or should start being idle.int
getNumber()
Gets the executor number that uniquely identifies it among otherExecutor
s for the same computer.Computer
getOwner()
int
getProgress()
Returns the progress of the current build in the number between 0-100.long
getTimeSpentInQueue()
Returns the number of milli-seconds the currently executing job spent in the queue waiting for an available executor.String
getTimestampString()
Gets the string that says how long since this build has started.boolean
hasStopPermission()
Checks if the current user has a permission to stop this build.void
interrupt()
void
interrupt(Result result)
Interrupt the execution, but instead of marking the build as aborted, mark it as specified result.void
interrupt(Result result, CauseOfInterruption... causes)
Interrupt the execution.boolean
isActive()
Check if executor is ready to accept tasks.boolean
isBusy()
The opposite ofisIdle()
— the executor is doing some work.boolean
isDisplayCell()
If this executor is running anAsynchronousExecution
and that execution wants to hide the display cell for the executor (because there is another executor displaying the job progress and we don't want to confuse the user) then this method will returnfalse
to indicate toexecutors.jelly
that the executor cell should be hidden.boolean
isIdle()
Returns true if thisExecutor
is ready for action.boolean
isLikelyStuck()
Returns true if the current build is likely stuck.boolean
isParking()
Returns true if this executor is waiting for a task to execute.<T> T
newImpersonatingProxy(Class<T> type, T core)
Creates a proxy object that executes the callee in the context that impersonates this executor.static Executor
of(Queue.Executable executable)
Finds the executor currently running a given process.void
recordCauseOfInterruption(Run<?,?> build, TaskListener listener)
report cause of interruption and record it to the build, if available.void
run()
void
start()
Can't start executor like you normally start a thread.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
owner
@NonNull protected final Computer owner
-
-
Constructor Detail
-
Executor
public Executor(@NonNull Computer owner, int n)
-
-
Method Detail
-
interrupt
public void interrupt(Result result)
Interrupt the execution, but instead of marking the build as aborted, mark it as specified result.- Since:
- 1.417
-
interrupt
public void interrupt(Result result, CauseOfInterruption... causes)
Interrupt the execution. Mark the cause and the status accordingly.
-
abortResult
public Result abortResult()
-
recordCauseOfInterruption
public void recordCauseOfInterruption(Run<?,?> build, TaskListener listener)
report cause of interruption and record it to the build, if available.- Since:
- 1.425
-
completedAsynchronous
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void completedAsynchronous(@CheckForNull Throwable error)
-
getCurrentExecutable
@CheckForNull public Queue.Executable getCurrentExecutable()
Returns the current build this executor is running.- Returns:
- null if the executor is idle.
-
getCurrentExecutableForApi
@Exported(name="currentExecutable") @Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public Queue.Executable getCurrentExecutableForApi()
Same asgetCurrentExecutable()
but checksItem.READ
.
-
getCausesOfInterruption
@NonNull public Collection<CauseOfInterruption> getCausesOfInterruption()
Returns causes of interruption.- Returns:
- Unmodifiable collection of causes of interruption.
- Since:
- 1.617
-
getCurrentWorkUnit
@CheckForNull public WorkUnit getCurrentWorkUnit()
Returns the currentWorkUnit
(ofthe current executable
) that this executor is running.- Returns:
- null if the executor is idle.
-
getCurrentWorkspace
public FilePath getCurrentWorkspace()
If current executable isAbstractBuild
, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.
-
getDisplayName
public String getDisplayName()
Human readable name of the Jenkins executor. For the Java thread name useThread.getName()
.- Specified by:
getDisplayName
in interfaceModelObject
-
getNumber
@Exported public int getNumber()
Gets the executor number that uniquely identifies it among otherExecutor
s for the same computer.- Returns:
- a sequential number starting from 0.
-
isIdle
@Exported public boolean isIdle()
Returns true if thisExecutor
is ready for action.
-
isBusy
public boolean isBusy()
The opposite ofisIdle()
— the executor is doing some work.
-
isActive
public boolean isActive()
Check if executor is ready to accept tasks. This method becomes the critical one since 1.536, which introduces the on-demand creation of executor threads. Callers should use this method instead ofThread.isAlive()
, which would be incorrect for non-started threads or runningAsynchronousExecution
.- Returns:
- true if the executor is available for tasks (usually true)
- Since:
- 1.536
-
getAsynchronousExecution
@CheckForNull public AsynchronousExecution getAsynchronousExecution()
If currently running in asynchronous mode, returns that handle.- Since:
- 1.607
-
isDisplayCell
public boolean isDisplayCell()
If this executor is running anAsynchronousExecution
and that execution wants to hide the display cell for the executor (because there is another executor displaying the job progress and we don't want to confuse the user) then this method will returnfalse
to indicate toexecutors.jelly
that the executor cell should be hidden.- Returns:
true
iff theexecutorCell.jelly
for thisExecutor
should be displayed inexecutors.jelly
.- Since:
- 1.607
- See Also:
AsynchronousExecution.displayCell()
-
isParking
public boolean isParking()
Returns true if this executor is waiting for a task to execute.
-
getCauseOfDeath
@Deprecated @CheckForNull public Throwable getCauseOfDeath()
Deprecated.no longer used
-
getProgress
@Exported public int getProgress()
Returns the progress of the current build in the number between 0-100.- Returns:
- -1 if it's impossible to estimate the progress.
-
isLikelyStuck
@Exported public boolean isLikelyStuck()
Returns true if the current build is likely stuck.This is a heuristics based approach, but if the build is suspiciously taking for a long time, this method returns true.
-
getElapsedTime
public long getElapsedTime()
-
getTimeSpentInQueue
public long getTimeSpentInQueue()
Returns the number of milli-seconds the currently executing job spent in the queue waiting for an available executor. This excludes the quiet period time of the job.- Since:
- 1.440
-
getTimestampString
public String getTimestampString()
Gets the string that says how long since this build has started.- Returns:
- string like "3 minutes" "1 day" etc.
-
getEstimatedRemainingTime
public String getEstimatedRemainingTime()
Computes a human-readable text that shows the expected remaining time until the build completes.
-
getEstimatedRemainingTimeMillis
public long getEstimatedRemainingTimeMillis()
The same asgetEstimatedRemainingTime()
but return it as a number of milli-seconds.
-
start
public void start()
Can't start executor like you normally start a thread.- Overrides:
start
in classThread
- See Also:
start(WorkUnit)
-
doStop
@Deprecated public void doStop(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException
Deprecated.as of 1.489 UsedoStop()
ordoStopBuild(String)
.- Throws:
IOException
javax.servlet.ServletException
-
doStop
public org.kohsuke.stapler.HttpResponse doStop()
Stops the current build.
You can usedoStopBuild(String)
instead to ensure what will be interrupted is actually what you want to interrupt.- Since:
- 1.489
- See Also:
doStopBuild(String)
-
doStopBuild
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.kohsuke.stapler.HttpResponse doStopBuild(@CheckForNull @QueryParameter(fixEmpty=true) String runExtId)
Stops the current build, if matching the specified external id (or no id is specified, or the currentQueue.Executable
is not aRun
).- Parameters:
runExtId
- if not null, the externalizable id (Run.getExternalizableId()
) of the build the user expects to interrupt- Since:
- 2.209
-
doYank
@Deprecated public org.kohsuke.stapler.HttpResponse doYank()
Deprecated.now a no-op
-
hasStopPermission
public boolean hasStopPermission()
Checks if the current user has a permission to stop this build.
-
getOwner
@NonNull public Computer getOwner()
-
getIdleStartMilliseconds
public long getIdleStartMilliseconds()
Returns when this executor started or should start being idle.
-
getApi
public Api getApi()
Exposes the executor to the remote API.
-
newImpersonatingProxy
public <T> T newImpersonatingProxy(Class<T> type, T core)
Creates a proxy object that executes the callee in the context that impersonates this executor. Useful to export an object to a remote channel.
-
currentExecutor
@CheckForNull public static Executor currentExecutor()
Returns the executor of the current thread or null if current thread is not an executor.
-
of
@CheckForNull public static Executor of(Queue.Executable executable)
Finds the executor currently running a given process.- Parameters:
executable
- a possibly running executable- Returns:
- the executor (possibly a
OneOffExecutor
) whosegetCurrentExecutable()
matches that, or null if it could not be found (for example because the execution has already completed) - Since:
- 1.607
-
getEstimatedDurationFor
@Deprecated public static long getEstimatedDurationFor(Queue.Executable e)
Deprecated.callQueue.Executable.getEstimatedDuration()
directly
-
-