Class ArrayBasedContext

java.lang.Object
io.opentelemetry.context.ArrayBasedContext
All Implemented Interfaces:
Context

final class ArrayBasedContext extends Object implements Context
  • Field Details

    • ROOT

      private static final Context ROOT
    • entries

      private final Object[] entries
  • Constructor Details

    • ArrayBasedContext

      private ArrayBasedContext(Object[] entries)
  • Method Details

    • root

      static Context root()
    • get

      @Nullable public <V> V get(ContextKey<V> key)
      Description copied from interface: Context
      Returns the value stored in this Context for the given ContextKey, or null if there is no value for the key in this context.
      Specified by:
      get in interface Context
    • with

      public <V> Context with(ContextKey<V> key, V value)
      Description copied from interface: Context
      Returns a new context with the given key value set.
      
       Context withCredential = Context.current().with(CRED_KEY, cred);
       withCredential.wrap(new Runnable() {
         public void run() {
            readUserRecords(userId, CRED_KEY.get());
         }
       }).run();
       

      Note that multiple calls to Context.with(ContextKey, Object) can be chained together.

      
       context.with(K1, V1).with(K2, V2);
       

      Nonetheless, Context should not be treated like a general purpose map with a large number of keys and values — combine multiple related items together into a single key instead of separating them. But if the items are unrelated, have separate keys for them.

      Specified by:
      with in interface Context
    • toString

      public String toString()
      Overrides:
      toString in class Object