@NotThreadSafe public abstract class Metadata extends Object
This class is not thread safe, implementations should ensure that header reads and writes do not occur in multiple threads concurrently.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Metadata.AsciiMarshaller<T>
Marshaller for metadata values that are serialized into ASCII strings that contain only
printable characters and space.
|
static interface |
Metadata.BinaryMarshaller<T>
Marshaller for metadata values that are serialized into raw binary.
|
static class |
Metadata.Headers
Concrete instance for metadata attached to the start of a call.
|
static class |
Metadata.Key<T>
Key for metadata entries.
|
static class |
Metadata.Trailers
Concrete instance for metadata attached to the end of the call.
|
| Modifier and Type | Field and Description |
|---|---|
static Metadata.AsciiMarshaller<String> |
ASCII_STRING_MARSHALLER
Simple metadata marshaller that encodes strings as is.
|
static String |
BINARY_HEADER_SUFFIX
All binary headers should have this suffix in their names.
|
static Metadata.AsciiMarshaller<Integer> |
INTEGER_MARSHALLER
Simple metadata marshaller that encodes an integer as a signed decimal string.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(Metadata.Key<?> key)
Returns true if a value is defined for the given key.
|
<T> T |
get(Metadata.Key<T> key)
Returns the last metadata entry added with the name 'name' parsed as T.
|
<T> Iterable<T> |
getAll(Metadata.Key<T> key)
Returns all the metadata entries named 'name', in the order they were received,
parsed as T or null if there are none.
|
boolean |
isSerializable()
Can this metadata be serialized.
|
void |
merge(Metadata other)
Perform a simple merge of two sets of metadata.
|
void |
merge(Metadata other,
Set<Metadata.Key<?>> keys)
Merge values for the given set of keys into this set of metadata.
|
<T> void |
put(Metadata.Key<T> key,
T value) |
<T> boolean |
remove(Metadata.Key<T> key,
T value)
Remove a specific value.
|
<T> List<T> |
removeAll(Metadata.Key<T> key)
Remove all values for the given key.
|
byte[][] |
serialize()
Serialize all the metadata entries.
|
public static final String BINARY_HEADER_SUFFIX
public static final Metadata.AsciiMarshaller<String> ASCII_STRING_MARSHALLER
This should be used with ASCII strings that only contain printable characters and space. Otherwise the output may be considered invalid and discarded by the transport.
public static final Metadata.AsciiMarshaller<Integer> INTEGER_MARSHALLER
public boolean containsKey(Metadata.Key<?> key)
public <T> T get(Metadata.Key<T> key)
public <T> Iterable<T> getAll(Metadata.Key<T> key)
public <T> void put(Metadata.Key<T> key, T value)
public <T> boolean remove(Metadata.Key<T> key, T value)
public <T> List<T> removeAll(Metadata.Key<T> key)
public boolean isSerializable()
merge(Metadata, java.util.Set)public byte[][] serialize()
It produces serialized names and values interleaved. result[i*2] are names, while result[i*2+1] are values.
Names are ASCII string bytes. If the name ends with "-bin", the value can be raw binary. Otherwise, the value must be printable ASCII characters or space.
public void merge(Metadata other)
Note that we can't merge non-serializable metadata into serializable.
public void merge(Metadata other, Set<Metadata.Key<?>> keys)