Interface Contextual<C extends Contextual<C>>

  • Type Parameters:
    C - the public type of the contextual object

    public interface Contextual<C extends Contextual<C>>
    A base class for contexts which are activated in a thread-local context.
    Author:
    David M. Lloyd
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      ContextManager<C> getInstanceContextManager()
      Get the context manager for this object.
      default void run​(java.lang.Runnable runnable)
      Run the given task with this contextual object selected.
      default <R> R runAction​(java.security.PrivilegedAction<R> action)
      Run the given task with this contextual object selected.
      default <T,​U>
      void
      runBiConsumer​(java.util.function.BiConsumer<T,​U> consumer, T param1, U param2)
      Run the given task with this contextual object selected.
      default <T,​U,​R>
      R
      runBiFunction​(java.util.function.BiFunction<T,​U,​R> function, T param1, U param2)
      Run the given task with this contextual object selected.
      default <T,​U>
      boolean
      runBiPredicate​(java.util.function.BiPredicate<T,​U> predicate, T param1, U param2)
      Run the given task with this contextual object selected.
      default <V> V runCallable​(java.util.concurrent.Callable<V> callable)
      Run the given task with this contextual object selected.
      default <T> void runConsumer​(java.util.function.Consumer<T> consumer, T param)
      Run the given task with this contextual object selected.
      default <T,​U,​E extends java.lang.Exception>
      void
      runExBiConsumer​(ExceptionBiConsumer<T,​U,​E> consumer, T param1, U param2)
      Run the given task with this contextual object selected.
      default <T,​U,​R,​E extends java.lang.Exception>
      R
      runExBiFunction​(ExceptionBiFunction<T,​U,​R,​E> function, T param1, U param2)
      Run the given task with this contextual object selected.
      default <T,​U,​E extends java.lang.Exception>
      boolean
      runExBiPredicate​(ExceptionBiPredicate<T,​U,​E> predicate, T param1, U param2)
      Run the given task with this contextual object selected.
      default <R> R runExceptionAction​(java.security.PrivilegedExceptionAction<R> action)
      Run the given task with this contextual object selected.
      default <T,​E extends java.lang.Exception>
      void
      runExConsumer​(ExceptionConsumer<T,​E> consumer, T param)
      Run the given task with this contextual object selected.
      default <T,​R,​E extends java.lang.Exception>
      R
      runExFunction​(ExceptionFunction<T,​R,​E> function, T param)
      Run the given task with this contextual object selected.
      default <T,​E extends java.lang.Exception>
      T
      runExIntFunction​(ExceptionIntFunction<T,​E> function, int value)
      Run the given task with this contextual object selected.
      default <T,​E extends java.lang.Exception>
      T
      runExLongFunction​(ExceptionLongFunction<T,​E> function, long value)
      Run the given task with this contextual object selected.
      default <T,​E extends java.lang.Exception>
      boolean
      runExPredicate​(ExceptionPredicate<T,​E> predicate, T param)
      Run the given task with this contextual object selected.
      default <T,​R>
      R
      runFunction​(java.util.function.Function<T,​R> function, T param)
      Run the given task with this contextual object selected.
      default <T> T runIntFunction​(java.util.function.IntFunction<T> function, int value)
      Run the given task with this contextual object selected.
      default <T> T runLongFunction​(java.util.function.LongFunction<T> function, long value)
      Run the given task with this contextual object selected.
      default <T> boolean runPredicate​(java.util.function.Predicate<T> predicate, T param)
      Run the given task with this contextual object selected.
    • Method Detail

      • getInstanceContextManager

        @NotNull
        ContextManager<C> getInstanceContextManager()
        Get the context manager for this object. The implementation of this method normally should return a constant instance.
        Returns:
        the context manager (must not be null)
      • run

        default void run​(java.lang.Runnable runnable)
        Run the given task with this contextual object selected.
        Parameters:
        runnable - the task to run (must not be null)
      • runAction

        default <R> R runAction​(java.security.PrivilegedAction<R> action)
        Run the given task with this contextual object selected.
        Type Parameters:
        R - the return value type
        Parameters:
        action - the task to run (must not be null)
        Returns:
        the action return value
      • runExceptionAction

        default <R> R runExceptionAction​(java.security.PrivilegedExceptionAction<R> action)
                                  throws java.security.PrivilegedActionException
        Run the given task with this contextual object selected.
        Type Parameters:
        R - the return value type
        Parameters:
        action - the task to run (must not be null)
        Returns:
        the action return value
        Throws:
        java.security.PrivilegedActionException - if the action fails with an exception
      • runCallable

        default <V> V runCallable​(java.util.concurrent.Callable<V> callable)
                           throws java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        V - the return value type
        Parameters:
        callable - the task to run (must not be null)
        Returns:
        the action return value
        Throws:
        java.lang.Exception
      • runBiConsumer

        default <T,​U> void runBiConsumer​(java.util.function.BiConsumer<T,​U> consumer,
                                               T param1,
                                               U param2)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        Parameters:
        consumer - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
      • runExBiConsumer

        default <T,​U,​E extends java.lang.Exception> void runExBiConsumer​(ExceptionBiConsumer<T,​U,​E> consumer,
                                                                                     T param1,
                                                                                     U param2)
                                                                              throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        E - the exception type
        Parameters:
        consumer - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runConsumer

        default <T> void runConsumer​(java.util.function.Consumer<T> consumer,
                                     T param)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the parameter type
        Parameters:
        consumer - the task to run (must not be null)
        param - the parameter to pass to the task
      • runExConsumer

        default <T,​E extends java.lang.Exception> void runExConsumer​(ExceptionConsumer<T,​E> consumer,
                                                                           T param)
                                                                    throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the parameter type
        E - the exception type
        Parameters:
        consumer - the task to run (must not be null)
        param - the parameter to pass to the task
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runBiFunction

        default <T,​U,​R> R runBiFunction​(java.util.function.BiFunction<T,​U,​R> function,
                                                    T param1,
                                                    U param2)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        R - the return value type
        Parameters:
        function - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
        Returns:
        the action return value
      • runExBiFunction

        default <T,​U,​R,​E extends java.lang.Exception> R runExBiFunction​(ExceptionBiFunction<T,​U,​R,​E> function,
                                                                                          T param1,
                                                                                          U param2)
                                                                                   throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        R - the return value type
        E - the exception type
        Parameters:
        function - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runFunction

        default <T,​R> R runFunction​(java.util.function.Function<T,​R> function,
                                          T param)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the parameter type
        R - the return value type
        Parameters:
        function - the task to run (must not be null)
        param - the parameter to pass to the task
        Returns:
        the action return value
      • runExFunction

        default <T,​R,​E extends java.lang.Exception> R runExFunction​(ExceptionFunction<T,​R,​E> function,
                                                                                T param)
                                                                         throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the parameter type
        R - the return value type
        E - the exception type
        Parameters:
        function - the task to run (must not be null)
        param - the parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runBiPredicate

        default <T,​U> boolean runBiPredicate​(java.util.function.BiPredicate<T,​U> predicate,
                                                   T param1,
                                                   U param2)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        Parameters:
        predicate - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
        Returns:
        the action return value
      • runExBiPredicate

        default <T,​U,​E extends java.lang.Exception> boolean runExBiPredicate​(ExceptionBiPredicate<T,​U,​E> predicate,
                                                                                         T param1,
                                                                                         U param2)
                                                                                  throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        U - the second parameter type
        E - the exception type
        Parameters:
        predicate - the task to run (must not be null)
        param1 - the first parameter to pass to the task
        param2 - the second parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runPredicate

        default <T> boolean runPredicate​(java.util.function.Predicate<T> predicate,
                                         T param)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        Parameters:
        predicate - the task to run (must not be null)
        param - the parameter to pass to the task
        Returns:
        the action return value
      • runExPredicate

        default <T,​E extends java.lang.Exception> boolean runExPredicate​(ExceptionPredicate<T,​E> predicate,
                                                                               T param)
                                                                        throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the first parameter type
        E - the exception type
        Parameters:
        predicate - the task to run (must not be null)
        param - the parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runIntFunction

        default <T> T runIntFunction​(java.util.function.IntFunction<T> function,
                                     int value)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the return value type
        Parameters:
        function - the task to run (must not be null)
        value - the parameter to pass to the task
        Returns:
        the action return value
      • runExIntFunction

        default <T,​E extends java.lang.Exception> T runExIntFunction​(ExceptionIntFunction<T,​E> function,
                                                                           int value)
                                                                    throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the return value type
        E - the exception type
        Parameters:
        function - the task to run (must not be null)
        value - the parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception
      • runLongFunction

        default <T> T runLongFunction​(java.util.function.LongFunction<T> function,
                                      long value)
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the return value type
        Parameters:
        function - the task to run (must not be null)
        value - the parameter to pass to the task
        Returns:
        the action return value
      • runExLongFunction

        default <T,​E extends java.lang.Exception> T runExLongFunction​(ExceptionLongFunction<T,​E> function,
                                                                            long value)
                                                                     throws E extends java.lang.Exception
        Run the given task with this contextual object selected.
        Type Parameters:
        T - the return value type
        E - the exception type
        Parameters:
        function - the task to run (must not be null)
        value - the parameter to pass to the task
        Returns:
        the action return value
        Throws:
        E - if an exception occurs in the task
        E extends java.lang.Exception