Interface Aspects.InterceptBuilder<T>

  • Type Parameters:
    T - the delegate type
    Enclosing class:
    Aspects

    public static interface Aspects.InterceptBuilder<T>
    A builder to create a proxy that delegates to another object but can intercept calls, put something before, after and around calls.
    • Method Detail

      • intercept

        Aspects.InterceptBuilder<T> intercept​(FunctionWithException<Aspects.Invocation,​java.lang.Object> intercept,
                                              java.lang.String name,
                                              java.lang.Class<?>... types)
        Intercept a method call with a lambda. This is the generic form. For 0, 1, and 2 argument forms there are more convenient shortcuts. The number of types and the given arguments to the lambda must match
        Parameters:
        intercept - the lambda to intercept
        name - the method name
        types - the types
      • intercept

        <R> Aspects.InterceptBuilder<T> intercept​(SupplierWithException<R> intercept,
                                                  java.lang.String name)
        Intercept a no method call
        Parameters:
        intercept - the no method lambda
        name - the name of the method without arguments
      • intercept

        <R> Aspects.InterceptBuilder<T> intercept​(RunnableWithException intercept,
                                                  java.lang.String name)
        Intercept a no method call
        Parameters:
        intercept - the no method lambda
        name - the name of the method without arguments
      • intercept

        <A,​R> Aspects.InterceptBuilder<T> intercept​(FunctionWithException<A,​R> intercept,
                                                          java.lang.String name,
                                                          java.lang.Class<A> type)
        Intercept a one argument method call
        Parameters:
        intercept - the one argument method lambda
        name - the name of the method with one argument
      • intercept

        <A,​B,​R> Aspects.InterceptBuilder<T> intercept​(BiFunctionWithException<A,​B,​R> intercept,
                                                                  java.lang.String name,
                                                                  java.lang.Class<A> aType,
                                                                  java.lang.Class<B> bType)
        Intercept a two argument method call
        Parameters:
        intercept - the two argument method lambda
        name - the name of the method with two arguments
      • around

        Aspects.InterceptBuilder<T> around​(BiFunctionWithException<Aspects.Invocation,​java.util.concurrent.Callable<java.lang.Object>,​java.lang.Object> around)
        Provide a function that is called with the method calling function. The around can setup some function around the call, which is passed as a callable. The around should setup whatever it wants to setup, call the callable, tear down what was setup and then return the result of the callable. Exceptions can be passed upwards.
        Parameters:
        around - the around advice (the argument is a callable that should be calle
      • before

        Aspects.InterceptBuilder<T> before​(ConsumerWithException<Aspects.Invocation> before)
        Provide a function that is called before the method is called. The argument to the Consumer is the array of arguments (which is never null). The consumer may change these arguments but should of course be extremely careful to not change the types in a way that would make the method call impossible.
        Parameters:
        before - advice
      • after

        Aspects.InterceptBuilder<T> after​(BiFunctionWithException<Aspects.Invocation,​java.lang.Object,​java.lang.Object> after)
        Provide a function that is called after the method is called. The given parameter to the function are the arguments and the result of the previous methods. The function should return the result, modified if so needed.
        Parameters:
        after - advice
      • build

        T build()
        Build the proxy