Class Context<T>


  • public abstract class Context<T>
    extends java.lang.Object
    Context SPI for automatic context propagation.
    • Constructor Summary

      Constructors 
      Constructor Description
      Context()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T cast​(java.lang.Object context)
      Cast an untyped object to the context type.
      abstract T get()
      Get the current context object for propagation.
      T join​(T firstContext, T secondContext)
      Join two propagated context objects (such as for Futures).
      abstract void set​(T context)
      Set the propagated context object into the current scope.
      • Methods inherited from class java.lang.Object

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

      • Context

        public Context()
    • Method Detail

      • get

        public abstract T get()
        Get the current context object for propagation.

        Note: implementations can return null to propagate empty context.

        Returns:
        current context object
      • set

        public abstract void set​(T context)
        Set the propagated context object into the current scope.

        Note: implementations should handle null as empty context.

        Parameters:
        context - propagated context object, from associated get()
      • join

        public T join​(T firstContext,
                      T secondContext)
        Join two propagated context objects (such as for Futures).

        Default implementation prefers the second context (for Futures, the completing context). Override this method to actually join the contexts. Note: implementations should handle null as empty context.

        Parameters:
        firstContext - first propagated context object, from associated get()
        secondContext - second propagated context object, from associated get()
        Returns:
        joined or selected context (secondContext preferred by default)
      • cast

        public T cast​(java.lang.Object context)
        Cast an untyped object to the context type.
        Parameters:
        context - context object
        Returns:
        context object as context type