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,Executors 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 Computerowner-
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 ResultabortResult()voidcompletedAsynchronous(Throwable error)static ExecutorcurrentExecutor()Returns the executor of the current thread or null if current thread is not an executor.org.kohsuke.stapler.HttpResponsedoStop()Stops the current build.
You can usedoStopBuild(String)instead to ensure what will be interrupted is actually what you want to interrupt.voiddoStop(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)Deprecated.as of 1.489 UsedoStop()ordoStopBuild(String).org.kohsuke.stapler.HttpResponsedoStopBuild(String runExtId)Stops the current build, if matching the specified external id (or no id is specified, or the currentQueue.Executableis not aRun).org.kohsuke.stapler.HttpResponsedoYank()Deprecated.now a no-opApigetApi()Exposes the executor to the remote API.AsynchronousExecutiongetAsynchronousExecution()If currently running in asynchronous mode, returns that handle.ThrowablegetCauseOfDeath()Deprecated.no longer usedCollection<CauseOfInterruption>getCausesOfInterruption()Returns causes of interruption.Queue.ExecutablegetCurrentExecutable()Returns the current build this executor is running.Queue.ExecutablegetCurrentExecutableForApi()Same asgetCurrentExecutable()but checksItem.READ.FilePathgetCurrentWorkspace()If current executable isAbstractBuild, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.WorkUnitgetCurrentWorkUnit()Returns the currentWorkUnit(ofthe current executable) that this executor is running.StringgetDisplayName()Human readable name of the Jenkins executor.longgetElapsedTime()static longgetEstimatedDurationFor(Queue.Executable e)Deprecated.callQueue.Executable.getEstimatedDuration()directlyStringgetEstimatedRemainingTime()Computes a human-readable text that shows the expected remaining time until the build completes.longgetEstimatedRemainingTimeMillis()The same asgetEstimatedRemainingTime()but return it as a number of milli-seconds.longgetIdleStartMilliseconds()Returns when this executor started or should start being idle.intgetNumber()Gets the executor number that uniquely identifies it among otherExecutors for the same computer.ComputergetOwner()intgetProgress()Returns the progress of the current build in the number between 0-100.longgetTimeSpentInQueue()Returns the number of milli-seconds the currently executing job spent in the queue waiting for an available executor.StringgetTimestampString()Gets the string that says how long since this build has started.booleanhasStopPermission()Checks if the current user has a permission to stop this build.voidinterrupt()voidinterrupt(Result result)Interrupt the execution, but instead of marking the build as aborted, mark it as specified result.voidinterrupt(Result result, CauseOfInterruption... causes)Interrupt the execution.booleanisActive()Check if executor is ready to accept tasks.booleanisBusy()The opposite ofisIdle()— the executor is doing some work.booleanisDisplayCell()If this executor is running anAsynchronousExecutionand 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 returnfalseto indicate toexecutors.jellythat the executor cell should be hidden.booleanisIdle()Returns true if thisExecutoris ready for action.booleanisLikelyStuck()Returns true if the current build is likely stuck.booleanisParking()Returns true if this executor is waiting for a task to execute.<T> TnewImpersonatingProxy(Class<T> type, T core)Creates a proxy object that executes the callee in the context that impersonates this executor.static Executorof(Queue.Executable executable)Finds the executor currently running a given process.voidrecordCauseOfInterruption(Run<?,?> build, TaskListener listener)report cause of interruption and record it to the build, if available.voidrun()voidstart()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:
getDisplayNamein interfaceModelObject
-
getNumber
@Exported public int getNumber()
Gets the executor number that uniquely identifies it among otherExecutors for the same computer.- Returns:
- a sequential number starting from 0.
-
isIdle
@Exported public boolean isIdle()
Returns true if thisExecutoris 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 anAsynchronousExecutionand 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 returnfalseto indicate toexecutors.jellythat the executor cell should be hidden.- Returns:
trueiff theexecutorCell.jellyfor thisExecutorshould 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:
startin 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:
IOExceptionjavax.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.Executableis 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
-
-