Interface InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE extends Interceptor>

Type Parameters:
OPERATION - the type of operation to intercept, aka. the argument to the interceptor
RESULT - the result of the operation
INTERCEPTOR_TYPE - The type of interceptor
All Known Implementing Classes:
DefaultInterceptorChain

public interface InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE extends Interceptor>
Generic interceptor chain concept that supports intercepting concrete Interceptor operations to modify the behaviour or add to the default behaviour
  • Method Summary

    Modifier and Type
    Method
    Description
    static <OPERATION, RESULT, INTERCEPTOR_TYPE extends Interceptor>
    InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE>
    newInterceptorChainForOperation(OPERATION operation, List<INTERCEPTOR_TYPE> interceptors, BiFunction<INTERCEPTOR_TYPE,InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE>,RESULT> interceptorMethodInvoker, Supplier<RESULT> defaultBehaviour)
    Create a new InterceptorChain instance for the provided operation instance
    InterceptorChain instances are not reusable across different operation instances.
    Example:
    The operation details
    To continue the processing a Interceptor will call this method, which in turn will call other Interceptor's (if more interceptors are configured) and finally the default implementation will be called.
    If the Interceptor can provide a result without calling the default behaviour then it can just return its (e.g. cached) result and not call proceed()
  • Method Details

    • proceed

      RESULT proceed()
      To continue the processing a Interceptor will call this method, which in turn will call other Interceptor's (if more interceptors are configured) and finally the default implementation will be called.
      If the Interceptor can provide a result without calling the default behaviour then it can just return its (e.g. cached) result and not call proceed()
      Returns:
      the result of the operation
    • operation

      OPERATION operation()
      The operation details
      Returns:
      the operation details
    • newInterceptorChainForOperation

      static <OPERATION, RESULT, INTERCEPTOR_TYPE extends Interceptor> InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE> newInterceptorChainForOperation(OPERATION operation, List<INTERCEPTOR_TYPE> interceptors, BiFunction<INTERCEPTOR_TYPE,InterceptorChain<OPERATION,RESULT,INTERCEPTOR_TYPE>,RESULT> interceptorMethodInvoker, Supplier<RESULT> defaultBehaviour)
      Create a new InterceptorChain instance for the provided operation instance
      InterceptorChain instances are not reusable across different operation instances.
      Example:
      
       var result = newInterceptorChainForOperation(operation,
                                                    allInterceptorsConfigured,
                                                    (interceptor, interceptorChain) -> interceptorChain.intercept(operation, interceptorChain),
                                                    () -> performDefaultBehaviorForOperation(operation)
                                                    ).proceed();
       
      Type Parameters:
      OPERATION - the type of operation to intercept, aka. the argument to the interceptor
      RESULT - the result of the operation
      Parameters:
      operation - the operation to intercept, aka. the argument to the interceptor
      interceptors - the Interceptor's (can be an empty List if no interceptors have been configured)
      interceptorMethodInvoker - the function that's responsible for invoking the matching Interceptor method
      defaultBehaviour - the default behaviour for the given operation in case none of the interceptors provided a different result and stopped the interceptor chain
      Returns:
      a new InterceptorChain instance for the provided operation