Class BodyExecutionCallback
- java.lang.Object
-
- org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BodyExecutionCallback.TailCall
,GeneralNonBlockingStepExecution.TailCall
public abstract class BodyExecutionCallback extends Object implements Serializable
FutureCallback
enhanced to trackBodyExecution
.Body execution reports the callback in the order
onStart(org.jenkinsci.plugins.workflow.steps.StepContext)
, then eitheronSuccess(org.jenkinsci.plugins.workflow.steps.StepContext, java.lang.Object)
oronFailure(org.jenkinsci.plugins.workflow.steps.StepContext, java.lang.Throwable)
.- Author:
- Kohsuke Kawaguchi
- See Also:
BodyInvoker.withCallback(BodyExecutionCallback)
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BodyExecutionCallback.TailCall
A convenience subclass for the common case that the step expects to run its block just once and return the same value (or throw the same error).
-
Constructor Summary
Constructors Constructor Description BodyExecutionCallback()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
onFailure(StepContext context, Throwable t)
Notifies that the body execution has aborted abnormally.void
onStart(StepContext context)
Notifies that the body execution has started.abstract void
onSuccess(StepContext context, Object result)
Notifies that the body execution has completed successfully.static BodyExecutionCallback
wrap(com.google.common.util.concurrent.FutureCallback<Object> v)
Wraps an ordinaryFutureCallback
intoBodyExecutionCallback
.
-
-
-
Method Detail
-
onStart
public void onStart(StepContext context)
Notifies that the body execution has started.This callback has to return synchronously. It is intended for performing log output, update
FlowNode
, or some such decorative actions. For any asynchronous computation that needs to happen prior to the body execution, the best place to do that is before callingStepContext.newBodyInvoker()
.StepContext
given to this method lets you access objects that correspond to the beginning of the body, as opposed to the objects that correspond to the invocation of the step that invoked the body. Otherwise the context is identical in behaviour to that given toStep.start(StepContext)
.So for example this is a good place to record any logging that's attributed to the body execution, such as reporting that this is Nth retry of the body, or that this is the parallel branch named 'xyz'.
-
onSuccess
public abstract void onSuccess(StepContext context, Object result)
Notifies that the body execution has completed successfully.StepContext
given to this method lets you access objects that correspond to the end of the body, as opposed to the objects that correspond to the invocation of the step that invoked the body. Otherwise the context is identical in behaviour to that given toStep.start(StepContext)
.So for example this is a good place to record any logging that's attributed to the end of the body execution.
-
onFailure
public abstract void onFailure(StepContext context, Throwable t)
Notifies that the body execution has aborted abnormally.See
onSuccess(StepContext, Object)
for the discussion of how the givenStepContext
behaves.
-
wrap
public static BodyExecutionCallback wrap(com.google.common.util.concurrent.FutureCallback<Object> v)
Wraps an ordinaryFutureCallback
intoBodyExecutionCallback
. You lose some power this way (onStart(org.jenkinsci.plugins.workflow.steps.StepContext)
and per-bodyStepContext
) but may be convenient if you already have aFutureCallback
from some other source. For example, you can wrap your ownStepContext
if your step is a tail call to its body.
-
-