publicfinalclass GrpcCallContextimplementsApiCallContext
GrpcCallContext encapsulates context data used to make a grpc call.
GrpcCallContext is immutable in the sense that none of its methods modifies the
GrpcCallContext itself or the underlying data. Methods of the form withX, such as #withTransportChannel, return copies of the object, but with one field changed. The immutability
and thread safety of the arguments solely depends on the arguments themselves.
Inheritance
Object >
GrpcCallContext
Static Methods
createDefault()
publicstaticGrpcCallContextcreateDefault()
Returns an empty instance with a null channel and default CallOptions.
of(Channel channel, CallOptions callOptions)
publicstaticGrpcCallContextof(Channelchannel,CallOptionscallOptions)
Returns an instance with the given channel and CallOptions.
| Parameters |
| Name |
Description |
channel |
io.grpc.Channel
|
callOptions |
io.grpc.CallOptions
|
Methods
<T>getOption(ApiCallContext.Key<T> key)
publicT<T>getOption(ApiCallContext.Key<T>key)
Return the api call context option set for this context.
| Parameter |
| Name |
Description |
key |
Key<T>
|
| Returns |
| Type |
Description |
T |
<T>withOption(ApiCallContext.Key<T> key, T value)
publicGrpcCallContext<T>withOption(ApiCallContext.Key<T>key,Tvalue)
Return a new ApiCallContext with additional option merged into the present instance. Any
existing value of the key is overwritten.
| Parameters |
| Name |
Description |
key |
Key<T>
|
value |
T
|
equals(Object o)
publicbooleanequals(Objecto)
| Parameter |
| Name |
Description |
o |
Object
|
Overrides
getCallOptions()
publicCallOptionsgetCallOptions()
The CallOptions set on this context.
| Returns |
| Type |
Description |
io.grpc.CallOptions |
getChannel()
publicChannelgetChannel()
The Channel set on this context.
| Returns |
| Type |
Description |
io.grpc.Channel |
getChannelAffinity()
publicIntegergetChannelAffinity()
The channel affinity for this context.
publicMap<String,List<String>>getExtraHeaders()
The extra header for this context.
getRetrySettings()
publicRetrySettingsgetRetrySettings()
getRetryableCodes()
publicSet<StatusCode.Code>getRetryableCodes()
Returns the retryable codes to use with this context, or null if the default
retryable codes should be used.
getStreamIdleTimeout()
publicDurationgetStreamIdleTimeout()
| Returns |
| Type |
Description |
org.threeten.bp.Duration |
getStreamWaitTimeout()
publicDurationgetStreamWaitTimeout()
| Returns |
| Type |
Description |
org.threeten.bp.Duration |
getTimeout()
publicDurationgetTimeout()
Returns the configured per-RPC timeout.
| Returns |
| Type |
Description |
org.threeten.bp.Duration |
getTracer()
publicApiTracergetTracer()
The ApiTracer that was previously set for this context.
The ApiTracer will be used to trace the current operation and to annotate various
events like retries.
hashCode()
| Returns |
| Type |
Description |
int |
Overrides
merge(ApiCallContext inputCallContext)
publicApiCallContextmerge(ApiCallContextinputCallContext)
For any values in inputCallContext that are not null, override the corresponding values
in the present instance.
nullToSelf(ApiCallContext inputContext)
publicGrpcCallContextnullToSelf(ApiCallContextinputContext)
withCallOptions(CallOptions newCallOptions)
publicGrpcCallContextwithCallOptions(CallOptionsnewCallOptions)
Returns a new instance with the call options set to the given call options.
| Parameter |
| Name |
Description |
newCallOptions |
io.grpc.CallOptions
|
withChannel(Channel newChannel)
publicGrpcCallContextwithChannel(ChannelnewChannel)
Returns a new instance with the channel set to the given channel.
| Parameter |
| Name |
Description |
newChannel |
io.grpc.Channel
|
withChannelAffinity(Integer affinity)
publicGrpcCallContextwithChannelAffinity(Integeraffinity)
| Parameter |
| Name |
Description |
affinity |
Integer
|
withCredentials(Credentials newCredentials)
publicGrpcCallContextwithCredentials(CredentialsnewCredentials)
Returns a new ApiCallContext with the given credentials set.
| Parameter |
| Name |
Description |
newCredentials |
com.google.auth.Credentials
|
publicGrpcCallContextwithExtraHeaders(Map<String,List<String>>extraHeaders)
Return a new ApiCallContext with the extraHeaders merged into the present instance.
publicGrpcCallContextwithRequestParamsDynamicHeaderOption(StringrequestParams)
| Parameter |
| Name |
Description |
requestParams |
String
|
withRetrySettings(RetrySettings retrySettings)
publicGrpcCallContextwithRetrySettings(RetrySettingsretrySettings)
Returns a new ApiCallContext with the given RetrySettings set.
This sets the RetrySettings to use for the RPC. These settings will work in
combination with either the default retryable codes for the RPC, or the retryable codes
supplied through #withRetryableCodes(Set). Calling #withRetrySettings(RetrySettings) on an RPC that does not include Code#DEADLINE_EXCEEDED as one of its retryable codes (or without calling #withRetryableCodes(Set) with a set that includes at least Code#DEADLINE_EXCEEDED)
will effectively only set a single timeout that is equal to RetrySettings#getInitialRpcTimeout(). If this timeout is exceeded, the RPC will not be retried
and will fail with Code#DEADLINE_EXCEEDED.
Example usage:
ApiCallContextcontext=GrpcCallContext.createDefault()
.withRetrySettings(RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(10L))
.setInitialRpcTimeout(Duration.ofMillis(100L))
.setMaxAttempts(10)
.setMaxRetryDelay(Duration.ofSeconds(10L))
.setMaxRpcTimeout(Duration.ofSeconds(30L))
.setRetryDelayMultiplier(1.4)
.setRpcTimeoutMultiplier(1.5)
.setTotalTimeout(Duration.ofMinutes(10L))
.build())
.withRetryableCodes(Sets.newSet(
StatusCode.Code.UNAVAILABLE,
StatusCode.Code.DEADLINE_EXCEEDED));
Setting a logical call timeout for the context can be done similarly with RetrySettings.Builder#setLogicalTimeout(Duration timeout).
Example usage:
ApiCallContextcontext=GrpcCallContext.createDefault()
.withRetrySettings(RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(10L))
.setMaxRetryDelay(Duration.ofSeconds(10L))
.setRetryDelayMultiplier(1.4)
.setMaxAttempts(10)
.setLogicalTimeout(Duration.ofSeconds(30L))
.build());
withRetryableCodes(Set<StatusCode.Code> retryableCodes)
publicGrpcCallContextwithRetryableCodes(Set<StatusCode.Code>retryableCodes)
Returns a new ApiCallContext with the given retryable codes set.
This sets the retryable codes to use for the RPC. These settings will work in combination
with either the default RetrySettings for the RPC, or the RetrySettings
supplied through #withRetrySettings(RetrySettings).
Setting a non-empty set of retryable codes for an RPC that is not already retryable by
default, will not have any effect and the RPC will NOT be retried. This option can only be used
to change which codes are considered retryable for an RPC that already has at least one
retryable code in its default settings.
| Parameter |
| Name |
Description |
retryableCodes |
Set<Code>
|
withStreamIdleTimeout(Duration streamIdleTimeout)
publicGrpcCallContextwithStreamIdleTimeout(DurationstreamIdleTimeout)
| Parameter |
| Name |
Description |
streamIdleTimeout |
org.threeten.bp.Duration
|
withStreamWaitTimeout(Duration streamWaitTimeout)
publicGrpcCallContextwithStreamWaitTimeout(DurationstreamWaitTimeout)
| Parameter |
| Name |
Description |
streamWaitTimeout |
org.threeten.bp.Duration
|
withTimeout(Duration timeout)
publicGrpcCallContextwithTimeout(Durationtimeout)
Returns a new ApiCallContext with the given timeout set.
This sets the maximum amount of time a single unary RPC attempt can take. If retries are
enabled, then this can take much longer, as each RPC attempt will have the same constant
timeout. Unlike a deadline, timeouts are relative durations that are measure from the beginning
of each RPC attempt. Please note that this limits the duration of a server streaming RPC as
well.
If a method has default com.google.api.gax.retrying.RetrySettings, the max attempts
and/or total timeout is still respected when scheduling each RPC attempt.
| Parameter |
| Name |
Description |
timeout |
org.threeten.bp.Duration
|
withTracer(ApiTracer tracer)
publicGrpcCallContextwithTracer(ApiTracertracer)
withTransportChannel(TransportChannel inputChannel)
publicGrpcCallContextwithTransportChannel(TransportChannelinputChannel)
Returns a new ApiCallContext with the given channel set.