public interface FlowInterceptor
flow. Implementations may implement the before method, the
around method and the
after method (by default,
before and
after do nothing and
around just calls
proceed on the action).
Each flow for which a FlowInterceptor is applicable will have its own instance of that FlowInterceptor. For
instance, assuming there is a class MyInterceptor that implements FlowInterceptor and 2 flows for which
MyInterceptor is applicable, there will be 2 different instances of MyInterceptor, one intercepting each of the
flows. Since different executions on the same flow will use the same interceptor, it is advisable for implementations to be
stateless. State can be simulated by keeping method local variables in the
around method if required.
A flow may have more than one interceptor applied. In that case, all will be applied in a predetermined order, calling the
before methods of each,
around methods which may proceed to the next
interceptor or the flow itself and finally the after methods.
| Modifier and Type | Method and Description |
|---|---|
default void |
after(String flowName,
InterceptionEvent event,
Optional<Throwable> thrown)
This method is called after the main branch of the flow has run.
|
default CompletableFuture<InterceptionEvent> |
around(String flowName,
InterceptionEvent event,
InterceptionAction action)
|
default void |
before(String flowName,
InterceptionEvent event)
This method is called before an event is dispached to the intercepted flow.
|
default void before(String flowName, InterceptionEvent event)
event.flowName - the name of the flow being intercepted.event - an object that contains the state of the event to be dispatched to the flow. It may be modified by calling
its mutator methods.default CompletableFuture<InterceptionEvent> around(String flowName, InterceptionEvent event, InterceptionAction action)
before and
after.
If implemented, only by calling action#proceed() will the interception chain
continue and eventually dispatch the event to the intercepted flow. Otherwise, by calling skip() the interception chain execution will be interrupted and after
method called immediately. (skip() may not be called at all, but it is convenient that it
already returns a CompletableFuture to return in this method.)
Calling an implementation with this method will be less efficient than calling just
before and
after. So,
around should only be implemented for cases
that cannot be done just with before and/or
after. Some scenarios where implementing this method is needed
are:
flowName - the name of the flow being intercepted.event - an object that contains the state of the event to be dispatched to the flow. It may be modified by calling
its mutator methods.action - when something other than continuing the interception is desired, the corresponding method on this object
must be called. The methods on this object return a CompletableFuture that may be used to return from
this method.CompletableFuture for modifying the intercepted event after this method
returns.default void after(String flowName, InterceptionEvent event, Optional<Throwable> thrown)
event.
This method will be called after the around
method has been called.
If the flow finishes in error, the after methods will still be
called, with the thrown exception provided in the thrown parameter.
If before throws an Exception, the interception will be called there, but
the afters of the already called handlers will still be called.
flowName - the name of the flow being intercepted.event - the result of the component.thrown - the exception thrown by the intercepted component, if any.Copyright © 2024 MuleSoft, Inc.. All rights reserved.