Interface ApiCallContext (2.43.0) Stay organized with collections Save and categorize content based on your preferences.
- 2.72.2 (latest)
- 2.72.1
- 2.71.0
- 2.70.3
- 2.69.0
- 2.68.2
- 2.67.0
- 2.66.0
- 2.65.0
- 2.63.1
- 2.62.0
- 2.61.0
- 2.60.0
- 2.59.1
- 2.58.0
- 2.57.0
- 2.55.0
- 2.54.1
- 2.53.0
- 2.52.0
- 2.51.0
- 2.50.0
- 2.49.0
- 2.48.1
- 2.47.0
- 2.46.1
- 2.45.0
- 2.43.0
- 2.42.0
- 2.41.0
- 2.39.0
- 2.38.0
- 2.37.0
- 2.36.0
- 2.35.0
- 2.34.1
- 2.33.0
- 2.32.1
- 2.31.1
- 2.30.1
- 2.24.0
- 2.23.3
- 2.22.0
- 2.21.0
- 2.20.1
- 2.19.6
- 2.18.7
- 2.17.0
- 2.16.0
- 2.15.0
- 2.14.0
- 2.13.0
- 2.12.2
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.1
- 2.7.1
publicinterfaceApiCallContextextendsRetryingContextContext for an API call.
An API call can be composed of many RPCs (in case of retries). This class contains settings for both: API calls and RPCs.
Implementations need to be immutable because default instances are stored in callable objects.
This is transport specific and each transport has an implementation with its own options.
Implements
RetryingContextMethods
<T>getOption(ApiCallContext.Key<T> key)
publicabstractT<T>getOption(ApiCallContext.Key<T>key)Beta
The surface for call context options is not stable yet and may change in the future.
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
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)
publicabstractApiCallContext<T>withOption(ApiCallContext.Key<T>key,Tvalue)Beta
The surface for call context options is not stable yet and may change in the future.
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
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 |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
getExtraHeaders()
publicabstractMap<String,List<String>>getExtraHeaders()Beta
The surface for extra headers is not stable yet and may change in the future.
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
Return the extra headers set for this context.
| Returns | |
|---|---|
| Type | Description |
Map<String,List<String>> | |
getStreamIdleTimeout()
publicabstractDurationgetStreamIdleTimeout()The stream idle timeout set for this context.See Also:#withStreamIdleTimeout(Duration)
| Returns | |
|---|---|
| Type | Description |
org.threeten.bp.Duration | |
getStreamWaitTimeout()
publicabstractDurationgetStreamWaitTimeout()Return the stream wait timeout set for this context.See Also:#withStreamWaitTimeout(Duration)
| Returns | |
|---|---|
| Type | Description |
org.threeten.bp.Duration | |
getTimeout()
publicabstractDurationgetTimeout()Returns the configured per-RPC timeout.
| Returns | |
|---|---|
| Type | Description |
org.threeten.bp.Duration | |
getTracer()
publicabstractApiTracergetTracer()Beta
The surface for tracing is not stable yet and may change in the future
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
TheApiTracer that was previously set for this context.
TheApiTracer will be used to trace the current operation and to annotate various events like retries.
| Returns | |
|---|---|
| Type | Description |
ApiTracer | |
merge(ApiCallContext inputCallContext)
publicabstractApiCallContextmerge(ApiCallContextinputCallContext)For any values ininputCallContext that are not null, override the corresponding values in the present instance.
| Parameter | |
|---|---|
| Name | Description |
inputCallContext | ApiCallContext |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
nullToSelf(ApiCallContext inputContext)
publicabstractApiCallContextnullToSelf(ApiCallContextinputContext)If inputContext is not null, returns it; if it is null, returns the present instance.
| Parameter | |
|---|---|
| Name | Description |
inputContext | ApiCallContext |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withCredentials(Credentials credentials)
publicabstractApiCallContextwithCredentials(Credentialscredentials)Returns a new ApiCallContext with the given credentials set.
| Parameter | |
|---|---|
| Name | Description |
credentials | com.google.auth.Credentials |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withEndpointContext(EndpointContext endpointContext)
publicabstractApiCallContextwithEndpointContext(EndpointContextendpointContext)Returns a new ApiCallContext with the given Endpoint Context.
| Parameter | |
|---|---|
| Name | Description |
endpointContext | EndpointContext |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withExtraHeaders(Map<String,List<String>> extraHeaders)
publicabstractApiCallContextwithExtraHeaders(Map<String,List<String>>extraHeaders)Beta
The surface for extra headers is not stable yet and may change in the future.
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
Return a new ApiCallContext with the extraHeaders merged into the present instance.
| Parameter | |
|---|---|
| Name | Description |
extraHeaders | Map<String,List<String>> |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withRetrySettings(RetrySettings retrySettings)
publicabstractApiCallContextwithRetrySettings(RetrySettingsretrySettings)Beta
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
Returns a new ApiCallContext with the givenRetrySettings set.
This sets theRetrySettings 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 includeCode#DEADLINE_EXCEEDED as one of its retryable codes (or without calling#withRetryableCodes(Set) with a set that includes at leastCode#DEADLINE_EXCEEDED) will effectively only set a single timeout that is equal toRetrySettings#getInitialRpcTimeout(). If this timeout is exceeded, the RPC will not be retried and will fail withCode#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 withRetrySettings.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());| Parameter | |
|---|---|
| Name | Description |
retrySettings | RetrySettings |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withRetryableCodes(Set<StatusCode.Code> retryableCodes)
publicabstractApiCallContextwithRetryableCodes(Set<StatusCode.Code>retryableCodes)Beta
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
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 defaultRetrySettings for the RPC, or theRetrySettings 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> |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withStreamIdleTimeout(Duration streamIdleTimeout)
publicabstractApiCallContextwithStreamIdleTimeout(DurationstreamIdleTimeout)Returns a new ApiCallContext with the given stream idle timeout set.
This timeout only applies to aServerStreamingCallables. It limits the maximum amount of timeout that can pass between a message being received byResponseObserver#onResponse(Object) and demand being signaled viaStreamController#request(int). Please note that this timeout is best effort and the maximum resolution configured inStubSettings#getStreamWatchdogCheckInterval(). This is useful to clean up streams that were partially read but never closed. When the timeout has been reached, the stream will be closed with a nonretryableWatchdogTimeoutException and a status ofStatusCode.Code#ABORTED.
A value ofDuration#ZERO, disables the streaming idle timeout and a null value will use the default in the callable.
Please note that this timeout is best effort and the maximum resolution is configured inStubSettings#getStreamWatchdogCheckInterval().
| Parameter | |
|---|---|
| Name | Description |
streamIdleTimeout | org.threeten.bp.Duration |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withStreamWaitTimeout(Duration streamWaitTimeout)
publicabstractApiCallContextwithStreamWaitTimeout(DurationstreamWaitTimeout)Returns a new ApiCallContext with the given stream timeout set.
This timeout only applies to aServerStreamingCallables. It limits the maximum amount of time that can pass between demand being signaled viaStreamController#request(int) and actual message delivery toResponseObserver#onResponse(Object). Or, in the case of automatic flow control, since the last message was delivered toResponseObserver#onResponse(Object). This is useful to detect server or connection stalls. When the timeout has been reached, the stream will be closed with a retryableWatchdogTimeoutException and a status ofStatusCode.Code#ABORTED.
A value ofDuration#ZERO, disables the streaming wait timeout and a null value will use the default in the callable.
Please note that this timeout is best effort and the maximum resolution is configured inStubSettings#getStreamWatchdogCheckInterval().
| Parameter | |
|---|---|
| Name | Description |
streamWaitTimeout | org.threeten.bp.Duration |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withTimeout(Duration timeout)
publicabstractApiCallContextwithTimeout(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 defaultcom.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 |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withTracer(ApiTracer tracer)
publicabstractApiCallContextwithTracer(ApiTracertracer)Beta
The surface for tracing is not stable yet and may change in the future
This feature is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.
Returns a newApiCallContext with the givenApiTracer.
TheApiTracer will be used to trace the current operation and to annotate various events like retries.
| Parameter | |
|---|---|
| Name | Description |
tracer | ApiTracertheApiTracer to set. |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
withTransportChannel(TransportChannel channel)
publicabstractApiCallContextwithTransportChannel(TransportChannelchannel)Returns a new ApiCallContext with the given channel set.
| Parameter | |
|---|---|
| Name | Description |
channel | TransportChannel |
| Returns | |
|---|---|
| Type | Description |
ApiCallContext | |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.