Class Controller
java.lang.Object
org.jenkinsci.plugins.durabletask.Controller
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
FileMonitoringTask.FileMonitoringController
Defines how to control the execution of a task after it has started.
Expected to be XStream and Java serializable.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
Cleans up after a task is done.exitStatus
(FilePath workspace) Deprecated.exitStatus
(FilePath workspace, Launcher launcher) Deprecated.useexitStatus(FilePath, Launcher, TaskListener)
insteadexitStatus
(FilePath workspace, Launcher launcher, TaskListener logger) Checks whether the task has finished.getDiagnostics
(FilePath workspace, Launcher launcher) Should be overridden to provide specific information about the status of an external process, for diagnostic purposes.byte[]
Obtain the process output.void
Deprecated.usestop(FilePath, Launcher)
insteadvoid
Tries to stop any running task.void
watch
(FilePath workspace, Handler handler, TaskListener listener) Begins watching the process asynchronously, so that the master may receive notification when output is available or the process has exited.abstract boolean
writeLog
(FilePath workspace, OutputStream sink) Obtains any new task log output.
-
Constructor Details
-
Controller
public Controller()
-
-
Method Details
-
watch
public void watch(@NonNull FilePath workspace, @NonNull Handler handler, @NonNull TaskListener listener) throws IOException, InterruptedException, UnsupportedOperationException Begins watching the process asynchronously, so that the master may receive notification when output is available or the process has exited. This should be called as soon as the process is launched, and thereafter whenever reconnecting to the agent. You should not callwriteLog(hudson.FilePath, java.io.OutputStream)
orcleanup(hudson.FilePath)
in this case; you do not need to callexitStatus(FilePath, Launcher)
frequently, though it is advisable to still call it occasionally to verify that the process is still running.- Parameters:
workspace
- the workspace in usehandler
- a remotable callbacklistener
- a remotable destination for messages- Throws:
IOException
- if initiating the watch fails, for example with aChannelClosedException
UnsupportedOperationException
- when this mode is not available, so you must fall back to pollingwriteLog(hudson.FilePath, java.io.OutputStream)
andexitStatus(FilePath, Launcher)
InterruptedException
-
writeLog
public abstract boolean writeLog(FilePath workspace, OutputStream sink) throws IOException, InterruptedException Obtains any new task log output. Could use a serializable field to keep track of how much output has been previously written.- Parameters:
workspace
- the workspace in usesink
- where to send new log output- Returns:
- true if something was written and the controller should be resaved, false if everything is idle
- Throws:
IOException
InterruptedException
- See Also:
-
exitStatus
@CheckForNull public Integer exitStatus(FilePath workspace, Launcher launcher, TaskListener logger) throws IOException, InterruptedException Checks whether the task has finished.- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes (currently unused)logger
- a way to report special messages- Returns:
- an exit code (zero is successful), or null if the task appears to still be running
- Throws:
IOException
InterruptedException
-
exitStatus
@Deprecated @CheckForNull public Integer exitStatus(FilePath workspace, Launcher launcher) throws IOException, InterruptedException Deprecated.useexitStatus(FilePath, Launcher, TaskListener)
instead- Throws:
IOException
InterruptedException
-
exitStatus
@Deprecated @CheckForNull public Integer exitStatus(FilePath workspace) throws IOException, InterruptedException Deprecated.useexitStatus(FilePath, Launcher, TaskListener)
instead- Throws:
IOException
InterruptedException
-
getOutput
@NonNull public byte[] getOutput(@NonNull FilePath workspace, @NonNull Launcher launcher) throws IOException, InterruptedException Obtain the process output. Intended for use afterexitStatus(FilePath, Launcher)
has returned a non-null status. The result is undefined ifDurableTask.captureOutput()
was not called before launch; generally anIOException
will result.- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes (currently unused)- Returns:
- the output of the process as raw bytes (may be empty but not null)
- Throws:
IOException
InterruptedException
- See Also:
-
stop
Tries to stop any running task.- Parameters:
workspace
- the workspace in uselauncher
- a way to start processes- Throws:
IOException
InterruptedException
-
stop
Deprecated.usestop(FilePath, Launcher)
instead- Throws:
IOException
InterruptedException
-
cleanup
Cleans up after a task is done. Should delete any temporary files created byDurableTask.launch(hudson.EnvVars, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener)
.- Parameters:
workspace
- the workspace in use- Throws:
IOException
InterruptedException
-
getDiagnostics
public String getDiagnostics(FilePath workspace, Launcher launcher) throws IOException, InterruptedException Should be overridden to provide specific information about the status of an external process, for diagnostic purposes.- Returns:
Object.toString()
by default- Throws:
IOException
InterruptedException
-
exitStatus(FilePath, Launcher, TaskListener)
instead