Class BodyExecutionCallback
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BodyExecutionCallback.TailCall
,GeneralNonBlockingStepExecution.TailCall
FutureCallback
enhanced to track BodyExecution
.
Body execution reports the callback in the order onStart(org.jenkinsci.plugins.workflow.steps.StepContext)
, then either onSuccess(org.jenkinsci.plugins.workflow.steps.StepContext, java.lang.Object)
or onFailure(org.jenkinsci.plugins.workflow.steps.StepContext, java.lang.Throwable)
.
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
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
-
Method Summary
Modifier and TypeMethodDescriptionabstract 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
Wraps an ordinaryFutureCallback
intoBodyExecutionCallback
.
-
Constructor Details
-
BodyExecutionCallback
public BodyExecutionCallback()
-
-
Method Details
-
onStart
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
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
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.
-