hudson.model
Class Executor

java.lang.Object
  extended by java.lang.Thread
      extended by hudson.model.Executor
All Implemented Interfaces:
ModelObject, Runnable
Direct Known Subclasses:
OneOffExecutor

@ExportedBean
public class Executor
extends Thread
implements ModelObject

Thread that executes builds.

Author:
Kohsuke Kawaguchi

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  Computer owner
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Executor(Computer owner, int n)
           
 
Method Summary
 Result abortResult()
           
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.
 void doStop(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Deprecated. as of 1.489 Use doStop().
 org.kohsuke.stapler.HttpResponse doYank()
          Throws away this executor and get a new one.
 Api getApi()
          Exposes the executor to the remote API.
 Throwable getCauseOfDeath()
          If this thread dies unexpectedly, obtain the cause of the failure.
 Queue.Executable getCurrentExecutable()
          Returns the current Queue.Task this executor is running.
 FilePath getCurrentWorkspace()
          If current executable is AbstractBuild, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.
 WorkUnit getCurrentWorkUnit()
          Returns the current WorkUnit (of the current executable) that this executor is running.
 String getDisplayName()
          Same as Thread.getName().
 long getElapsedTime()
           
static long getEstimatedDurationFor(Queue.Executable e)
          Deprecated. as of 1.388 Use Executables#getEstimatedDurationFor(Executable)
 String getEstimatedRemainingTime()
          Computes a human-readable text that shows the expected remaining time until the build completes.
 long getEstimatedRemainingTimeMillis()
          The same as getEstimatedRemainingTime() 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 other Executors 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.
protected  WorkUnit grabJob()
           
 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 isBusy()
          The opposite of isIdle() — the executor is doing some work.
 boolean isIdle()
          Returns true if this Executor is ready for action.
 boolean isLikelyStuck()
          Returns true if the current build is likely stuck.
 void killHard()
          For testing only.
<T> T
newImpersonatingProxy(Class<T> type, T core)
          Creates a proxy object that executes the callee in the context that impersonates this executor.
 void recordCauseOfInterruption(Run<?,?> build, TaskListener listener)
          report cause of interruption and record it to the build, if available.
 void run()
           
protected  boolean shouldRun()
          Returns true if we should keep going.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

owner

protected final Computer owner
Constructor Detail

Executor

public Executor(Computer owner,
                int n)
Method Detail

interrupt

public void interrupt()
Overrides:
interrupt in class Thread

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

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

killHard

public void killHard()
For testing only. Simulate a fatal unexpected failure.


shouldRun

protected boolean shouldRun()
Returns true if we should keep going.


grabJob

protected WorkUnit grabJob()
                    throws InterruptedException
Throws:
InterruptedException

getCurrentExecutable

@Exported
public Queue.Executable getCurrentExecutable()
Returns the current Queue.Task this executor is running.

Returns:
null if the executor is idle.

getCurrentWorkUnit

@Exported
public WorkUnit getCurrentWorkUnit()
Returns the current WorkUnit (of the current executable) that this executor is running.

Returns:
null if the executor is idle.

getCurrentWorkspace

public FilePath getCurrentWorkspace()
If current executable is AbstractBuild, return the workspace that this executor is using, or null if the build hasn't gotten to that point yet.


getDisplayName

public String getDisplayName()
Same as Thread.getName().

Specified by:
getDisplayName in interface ModelObject

getNumber

@Exported
public int getNumber()
Gets the executor number that uniquely identifies it among other Executors for the same computer.

Returns:
a sequential number starting from 0.

isIdle

@Exported
public boolean isIdle()
Returns true if this Executor is ready for action.


isBusy

public boolean isBusy()
The opposite of isIdle() — the executor is doing some work.


getCauseOfDeath

public Throwable getCauseOfDeath()
If this thread dies unexpectedly, obtain the cause of the failure.

Returns:
null if the death is expected death or the thread is still alive.
Since:
1.142

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 as getEstimatedRemainingTime() but return it as a number of milli-seconds.


doStop

public void doStop(org.kohsuke.stapler.StaplerRequest req,
                   org.kohsuke.stapler.StaplerResponse rsp)
            throws IOException,
                   javax.servlet.ServletException
Deprecated. as of 1.489 Use doStop().

Throws:
IOException
javax.servlet.ServletException

doStop

public org.kohsuke.stapler.HttpResponse doStop()
Stops the current build.

Since:
1.489

doYank

public org.kohsuke.stapler.HttpResponse doYank()
Throws away this executor and get a new one.


hasStopPermission

public boolean hasStopPermission()
Checks if the current user has a permission to stop this build.


getOwner

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

public static Executor currentExecutor()
Returns the executor of the current thread or null if current thread is not an executor.


getEstimatedDurationFor

public static long getEstimatedDurationFor(Queue.Executable e)
Deprecated. as of 1.388 Use Executables#getEstimatedDurationFor(Executable)

Returns the estimated duration for the executable. Protects against AbstractMethodErrors if the Queue.Executable implementation was compiled against Hudson < 1.383



Copyright © 2004-2013. All Rights Reserved.