Class ContextUtils


  • public final class ContextUtils
    extends java.lang.Object
    Utility methods for accessing the TagContext contained in the Context.

    Most code should interact with the current context via the public APIs in TagContext and avoid accessing TAG_CONTEXT_KEY directly.

    Since:
    0.8
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ContextUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static TagContext getValue​(io.grpc.Context context)
      Returns the value from the specified Context.
      static io.grpc.Context withValue​(io.grpc.Context context, TagContext tagContext)
      Creates a new Context with the given value set.
      • Methods inherited from class java.lang.Object

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

      • EMPTY_TAG_CONTEXT

        private static final TagContext EMPTY_TAG_CONTEXT
      • TAG_CONTEXT_KEY

        private static final io.grpc.Context.Key<TagContext> TAG_CONTEXT_KEY
        The Context.Key used to interact with the TagContext contained in the Context.
    • Constructor Detail

      • ContextUtils

        private ContextUtils()
    • Method Detail

      • withValue

        public static io.grpc.Context withValue​(io.grpc.Context context,
                                                @Nullable
                                                TagContext tagContext)
        Creates a new Context with the given value set.
        Parameters:
        context - the parent Context.
        tagContext - the value to be set.
        Returns:
        a new context with the given value set.
        Since:
        0.21
      • getValue

        public static TagContext getValue​(io.grpc.Context context)
        Returns the value from the specified Context.
        Parameters:
        context - the specified Context.
        Returns:
        the value from the specified Context.
        Since:
        0.21