Interface Interceptor<T extends org.mule.runtime.api.meta.model.ComponentModel>


public interface Interceptor<T extends org.mule.runtime.api.meta.model.ComponentModel>
Taps into different phases of the execution of an extension's operation allowing to take different actions depending on the phase.

One instance of each implementation will be created per ConfigurationInstance. Those instances can have lifecycle, can be stateful and can use JSR-330 annotations for dependency injection. However, they MUST be thread-safe and reusable.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    after(ExecutionContext<T> executionContext, Object result)
    Executes after the execution of an operation is finished, regardless of it being successful or not.
    default void
    before(ExecutionContext<T> executionContext)
    Executes before the operation is executed.
    default Throwable
    onError(ExecutionContext<T> executionContext, Throwable exception)
    Executes when the execution of an operation threw exception.
    default void
    onSuccess(ExecutionContext<T> executionContext, Object result)
    Executes when an operation was successfully executed.
  • Method Details

    • before

      default void before(ExecutionContext<T> executionContext) throws Exception
      Executes before the operation is executed.

      If this method fails, the exception will be bubbled up right away. No other method in this interceptor will be executed (not even the after(ExecutionContext, Object), nor any other of the interceptors in line will be executed either. Because of this, no implementation should rely on the execution of any other method in this or other interceptor

      Parameters:
      executionContext - the ExecutionContext for the operation to be executed
      Throws:
      Exception - in case of error
    • onSuccess

      default void onSuccess(ExecutionContext<T> executionContext, Object result)
      Executes when an operation was successfully executed.

      Implementations of this method should not fail. If they do throw any exception, it will be logged and ignored.

      The after(ExecutionContext, Object) method is guaranteed to be executed regardless of this method's outcome in this or other involved instances

      Parameters:
      executionContext - the ExecutionContext that was used to execute the operation
      result - the result of the operation. Can be null if the operation itself returned that.
    • onError

      default Throwable onError(ExecutionContext<T> executionContext, Throwable exception)
      Executes when the execution of an operation threw exception.

      This method returns Exception to allow implementations to decorate, enrich or even replace the exception that will be bubbled up. Implementations however are not obligated to do such thing in which case they should return the same exception supplied. Notice however that:

      • The next interceptor in line will receive the exception returned by this method, which might not be the same one supplied in this invokation.
        There's no guarantee that the exception returned by this method will be the one bubbled up, since the next interceptor in line might also change it.

    Implementations of this method should not fail. If they do throw any exception, it will be logged and ignored.

    The after(ExecutionContext, Object) method is guaranteed to be executed regardless of this method's outcome in this or other involved instances