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 Details

    • 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(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(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(PrivilegedExceptionAction<R> action) throws 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:
      PrivilegedActionException - if the action fails with an exception
    • runCallable

      default <V> V runCallable(Callable<V> callable) throws 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:
      Exception
    • runBiConsumer

      default <T, U> void runBiConsumer(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 Exception> void runExBiConsumer(ExceptionBiConsumer<T,U,E> consumer, T param1, U param2) throws E
      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
    • runConsumer

      default <T> void runConsumer(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 Exception> void runExConsumer(ExceptionConsumer<T,E> consumer, T param) throws E
      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
    • runBiFunction

      default <T, U, R> R runBiFunction(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 Exception> R runExBiFunction(ExceptionBiFunction<T,U,R,E> function, T param1, U param2) throws E
      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
    • runFunction

      default <T, R> R runFunction(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 Exception> R runExFunction(ExceptionFunction<T,R,E> function, T param) throws E
      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
    • runBiPredicate

      default <T, U> boolean runBiPredicate(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 Exception> boolean runExBiPredicate(ExceptionBiPredicate<T,U,E> predicate, T param1, U param2) throws E
      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
    • runPredicate

      default <T> boolean runPredicate(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 Exception> boolean runExPredicate(ExceptionPredicate<T,E> predicate, T param) throws E
      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
    • runIntFunction

      default <T> T runIntFunction(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 Exception> T runExIntFunction(ExceptionIntFunction<T,E> function, int value) throws E
      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
    • runLongFunction

      default <T> T runLongFunction(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 Exception> T runExLongFunction(ExceptionLongFunction<T,E> function, long value) throws E
      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