Class ServerRequestContext


  • public final class ServerRequestContext
    extends java.lang.Object
    The holder for the current HttpRequest that is bound to instrumented threads. Allowing lookup of the current request if it is present.
    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String KEY  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Optional<HttpRequest<T>> currentRequest()
      Retrieve the current server request context.
      static java.lang.Runnable instrument​(HttpRequest request, java.lang.Runnable runnable)
      Return a new runnable by instrumenting the given runnable with request context handling.
      static void set​(HttpRequest request)
      static void with​(HttpRequest request, java.lang.Runnable runnable)
      Wrap the execution of the given runnable in request context processing.
      static <T> T with​(HttpRequest request, java.util.concurrent.Callable<T> callable)
      Wrap the execution of the given callable in request context processing.
      static <T> T with​(HttpRequest request, java.util.function.Supplier<T> callable)
      Wrap the execution of the given callable in request context processing.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • with

        public static void with​(@Nullable
                                HttpRequest request,
                                @NonNull
                                java.lang.Runnable runnable)
        Wrap the execution of the given runnable in request context processing.
        Parameters:
        request - The request
        runnable - The runnable
      • instrument

        public static java.lang.Runnable instrument​(@Nullable
                                                    HttpRequest request,
                                                    @NonNull
                                                    java.lang.Runnable runnable)
        Return a new runnable by instrumenting the given runnable with request context handling.
        Parameters:
        request - The request
        runnable - The runnable
        Returns:
        The newly instrumented runnable
      • with

        public static <T> T with​(@Nullable
                                 HttpRequest request,
                                 @NonNull
                                 java.util.function.Supplier<T> callable)
        Wrap the execution of the given callable in request context processing.
        Type Parameters:
        T - The return type of the callable
        Parameters:
        request - The request
        callable - The callable
        Returns:
        The return value of the callable
      • with

        public static <T> T with​(@Nullable
                                 HttpRequest request,
                                 @NonNull
                                 java.util.concurrent.Callable<T> callable)
                          throws java.lang.Exception
        Wrap the execution of the given callable in request context processing.
        Type Parameters:
        T - The return type of the callable
        Parameters:
        request - The request
        callable - The callable
        Returns:
        The return value of the callable
        Throws:
        java.lang.Exception - If the callable throws an exception
      • currentRequest

        public static <T> java.util.Optional<HttpRequest<T>> currentRequest()
        Retrieve the current server request context.
        Type Parameters:
        T - The body type
        Returns:
        The request context if it is present