Package io.grpc
Class Context.Key<T>
- java.lang.Object
-
- io.grpc.Context.Key<T>
-
- Enclosing class:
- Context
public static final class Context.Key<T> extends java.lang.ObjectKey for indexing values stored in a context. Keys use reference equality and Context does not provide a mechanism to loop over Keys. This means there is no way to access a Key's value from a Context without having access to the Key instance itself. This allows strong control over what code can get/set a key in the Context. For example, you might manage access to Key similar to a ThreadLocal using Java visibility (private/protected). Generally Keys are stored in static fields.
-
-
Field Summary
Fields Modifier and Type Field Description private TdefaultValueprivate java.lang.Stringname
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Get the value from theContext.current()context for this key.Tget(Context context)Get the value from the specified context for this key.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private final java.lang.String name
-
defaultValue
private final T defaultValue
-
-
Constructor Detail
-
Key
Key(java.lang.String name)
-
Key
Key(java.lang.String name, T defaultValue)
-
-
Method Detail
-
get
public T get()
Get the value from theContext.current()context for this key.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-