public interface ProcessorInterceptor
SOURCE. 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).
Interceptable components are those that are defined by a configuration element and have a ComponentLocation.
Each component for which a ProcessorInterceptor is applicable will have its own instance of that
ProcessorInterceptor. For instance, assuming there is a class MyInterceptor that implements
ProcessorInterceptor and 2 different components for which MyInterceptor is applicable, there will be 2
different instances of MyInterceptor, one intercepting each of the component. Since different executions on the same
processor 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 component 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 component itself and finally the after
methods.
| Modifier and Type | Method and Description |
|---|---|
default void |
after(ComponentLocation location,
InterceptionEvent event,
Optional<Throwable> thrown)
This method is called after the intercepted component has run.
|
default CompletableFuture<InterceptionEvent> |
around(ComponentLocation location,
Map<String,ProcessorParameterValue> parameters,
InterceptionEvent event,
InterceptionAction action)
|
default void |
before(ComponentLocation location,
Map<String,ProcessorParameterValue> parameters,
InterceptionEvent event)
This method is called before the intercepted component has run.
|
default void before(ComponentLocation location, Map<String,ProcessorParameterValue> parameters, InterceptionEvent event)
event.location - the location and identification properties of the intercepted component in the mule app configuration.parameters - the parameters of the component as defined in the configuration.event - an object that contains the state of the event to be sent to the component. It may be modified by calling its
mutator methods.default CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String,ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action)
before and
after.
If implemented, only by calling action proceed() will the interception chain
continue and eventually call the intercepted component. 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:
location - the location and identification properties of the intercepted component in the mule app configuration.parameters - the parameters of the component as defined in the configuration.event - an object that contains the state of the event to be sent to the component. 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(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown)
event.
This method will be called after the around
method has been called.
If the intercepted component throws an Exception, the after methods will still be called, with the passed InterceptionEvent returning the appropriate Error on
Event.getError().
If before throws an Exception, the interception will be
called there, but the afters of the already called handlers
will still be called.
location - the location and identification properties of the intercepted component in the mule app configuration.event - the result of the component.thrown - the exception thrown by the intercepted component, if any.Copyright © 2017 MuleSoft, Inc.. All rights reserved.