public abstract class BodyExecutionCallback extends Object implements Serializable
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)
.
BodyInvoker.withCallback(BodyExecutionCallback)
,
Serialized FormModifier and Type | Class and 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 and Description |
---|
BodyExecutionCallback() |
Modifier and Type | Method and 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 ordinary
FutureCallback into BodyExecutionCallback . |
public void onStart(StepContext context)
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 calling StepContext.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 to Step.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'.
public abstract void onSuccess(StepContext context, Object result)
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 to Step.start(StepContext)
.
So for example this is a good place to record any logging that's attributed to the end of the body execution.
public abstract void onFailure(StepContext context, Throwable t)
See onSuccess(StepContext, Object)
for the discussion of how
the given StepContext
behaves.
public static BodyExecutionCallback wrap(com.google.common.util.concurrent.FutureCallback<Object> v)
FutureCallback
into BodyExecutionCallback
.
You lose some power this way (onStart(org.jenkinsci.plugins.workflow.steps.StepContext)
and per-body StepContext
)
but may be convenient if you already have a FutureCallback
from some other source.
For example, you can wrap your own StepContext
if your step is a tail call to its body.Copyright © 2016–2017. All rights reserved.