Package hudson.model
Class Executor
java.lang.Object
java.lang.Thread
hudson.model.Executor
- All Implemented Interfaces:
ModelObject
,Runnable
,IExecutor
- Direct Known Subclasses:
OneOffExecutor
Thread that executes builds.
Since 1.536,
Executor
s start threads on-demand.
Callers should use isActive()
instead of Thread.isAlive()
.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
completedAsynchronous
(Throwable error) static Executor
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.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-opgetApi()
Exposes the executor to the remote API.If currently running in asynchronous mode, returns that handle.Deprecated.no longer usedReturns causes of interruption.Returns the current build this executor is running.Same asgetCurrentExecutable()
but checksItem.READ
.If current executable isAbstractBuild
, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.Returns the currentWorkUnit
(ofthe current executable
) that this executor is running.Human readable name of the Jenkins executor.long
Gets the elapsed time since the build has started.static long
Deprecated.callQueue.Executable.getEstimatedDuration()
directlyComputes a human-readable text that shows the expected remaining time until the build completes.long
The same asgetEstimatedRemainingTime()
but return it as a number of milli-seconds.long
Returns when this executor started or should start being idle.int
Gets the executor number that uniquely identifies it among otherIExecutor
s for the same computer.getOwner()
int
Returns the progress of the current build in the number between 0-100.long
Returns the number of milli-seconds the currently executing job spent in the queue waiting for an available executor.boolean
Checks if the current user has a permission to stop this build.void
void
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
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 thisIExecutor
is ready for action.boolean
Returns true if the current build is likely stuck.boolean
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
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface jenkins.model.IExecutor
getParentTask, getTimestampString
-
Field Details
-
owner
-
-
Constructor Details
-
Executor
-
-
Method Details
-
interrupt
public void interrupt() -
interrupt
Interrupt the execution, but instead of marking the build as aborted, mark it as specified result.- Since:
- 1.417
-
interrupt
Interrupt the execution. Mark the cause and the status accordingly. -
abortResult
-
recordCauseOfInterruption
report cause of interruption and record it to the build, if available.- Since:
- 1.425
-
run
public void run() -
completedAsynchronous
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void completedAsynchronous(@CheckForNull Throwable error) -
getCurrentExecutable
Returns the current build this executor is running.- Specified by:
getCurrentExecutable
in interfaceIExecutor
- 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
Returns causes of interruption.- Returns:
- Unmodifiable collection of causes of interruption.
- Since:
- 1.617
-
getCurrentWorkUnit
Description copied from interface:IExecutor
Returns the currentWorkUnit
(ofthe current executable
) that this executor is running.- Specified by:
getCurrentWorkUnit
in interfaceIExecutor
- Returns:
- null if the executor is idle.
-
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
Human readable name of the Jenkins executor. For the Java thread name useThread.getName()
.- Specified by:
getDisplayName
in interfaceIExecutor
- Specified by:
getDisplayName
in interfaceModelObject
- Returns:
- the current display name of the executor. Usually the name of the executable.
-
getNumber
@Exported public int getNumber()Description copied from interface:IExecutor
Gets the executor number that uniquely identifies it among otherIExecutor
s for the same computer. -
isIdle
@Exported public boolean isIdle()Description copied from interface:IExecutor
Returns true if thisIExecutor
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
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:
-
isParking
public boolean isParking()Returns true if this executor is waiting for a task to execute. -
getCauseOfDeath
Deprecated.no longer used -
getProgress
@Exported public int getProgress()Description copied from interface:IExecutor
Returns the progress of the current build in the number between 0-100.- Specified by:
getProgress
in interfaceIExecutor
- Returns:
- -1 if it's impossible to estimate the progress.
-
isLikelyStuck
@Exported public boolean isLikelyStuck()Description copied from interface:IExecutor
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.
- Specified by:
isLikelyStuck
in interfaceIExecutor
-
getElapsedTime
public long getElapsedTime()Description copied from interface:IExecutor
Gets the elapsed time since the build has started.- Specified by:
getElapsedTime
in interfaceIExecutor
- Returns:
- the number of milliseconds since the build has started.
-
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
-
getEstimatedRemainingTime
Description copied from interface:IExecutor
Computes a human-readable text that shows the expected remaining time until the build completes.- Specified by:
getEstimatedRemainingTime
in interfaceIExecutor
-
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. -
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
@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.now a no-op -
hasStopPermission
public boolean hasStopPermission()Description copied from interface:IExecutor
Checks if the current user has a permission to stop this build.- Specified by:
hasStopPermission
in interfaceIExecutor
-
getOwner
-
getIdleStartMilliseconds
public long getIdleStartMilliseconds()Returns when this executor started or should start being idle. -
getApi
Exposes the executor to the remote API. -
newImpersonatingProxy
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
Returns the executor of the current thread or null if current thread is not an executor. -
of
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.callQueue.Executable.getEstimatedDuration()
directly
-
doStop()
ordoStopBuild(String)
.