Top Fields Constructors Methods
io.opentelemetry.context

pack-priv final Class ArrayBasedContext

extends Object
implements Context
Class Inheritance
All Implemented Interfaces
io.opentelemetry.context.Context
Imports
java.util.Arrays, javax.annotation.Nullable

Field Summary

Modifier and TypeField and Description
private final Object[]
private static final Context

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public <V> V
get(ContextKey<V> key)

Implements io.opentelemetry.context.Context.get.

Returns the value stored in this Context for the given ContextKey, or null if there is no value for the key in this context.

pack-priv static Context
root()

Hides io.opentelemetry.context.Context.root.

Returns the root Context which all other Context are derived from.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public <V> Context
with(ContextKey<V> key, V value)

Implements io.opentelemetry.context.Context.with.

Returns a new context with the given key value set.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

entriesback to summary
private final Object[] entries
ROOTback to summary
private static final Context ROOT

Constructor Detail

ArrayBasedContextback to summary
private ArrayBasedContext(Object[] entries)

Method Detail

getback to summary
public <V> V get(ContextKey<V> key)

Implements io.opentelemetry.context.Context.get.

Doc from io.opentelemetry.context.Context.get.

Returns the value stored in this Context for the given ContextKey, or null if there is no value for the key in this context.

Annotations
@Override
@Nullable
rootback to summary
pack-priv static Context root()

Hides io.opentelemetry.context.Context.root.

Doc from io.opentelemetry.context.Context.root.

Returns the root Context which all other Context are derived from.

It should generally not be required to use the root Context directly - instead, use Context#current() to operate on the current Context. Only use this method if you are absolutely sure you need to disregard the current Context - this almost always is only a workaround hiding an underlying context propagation issue.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
withback to summary
public <V> Context with(ContextKey<V> key, V value)

Implements io.opentelemetry.context.Context.with.

Doc from io.opentelemetry.context.Context.with.

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 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.

Annotations
@Override