cronet: add getter for retrieving grpc cronet annotations in calloptions. (#6086)

This commit is contained in:
Chengyuan Zhang 2019-08-21 09:55:48 -07:00 committed by GitHub
parent 63661c7b70
commit be226aa99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,8 @@ package io.grpc.cronet;
import io.grpc.CallOptions;
import io.grpc.Internal;
import java.util.Collection;
import java.util.Collections;
/**
* Internal accessor class for call options using with the Cronet transport. This is intended for
@ -33,4 +35,17 @@ public final class InternalCronetCallOptions {
public static CallOptions withAnnotation(CallOptions callOptions, Object annotation) {
return CronetClientStream.withAnnotation(callOptions, annotation);
}
/**
* Returns Cronet annotations for gRPC included in the given {@code callOptions}. Annotations
* are attached via {@link #withAnnotation(CallOptions, Object)}.
*/
public static Collection<Object> getAnnotations(CallOptions callOptions) {
Collection<Object> annotations =
callOptions.getOption(CronetClientStream.CRONET_ANNOTATIONS_KEY);
if (annotations == null) {
annotations = Collections.emptyList();
}
return annotations;
}
}