Class HttpJsonCallContext (2.48.1)

public final class HttpJsonCallContext implements ApiCallContext

HttpJsonCallContext encapsulates context data used to make an http-json call.

HttpJsonCallContext is immutable in the sense that none of its methods modifies the HttpJsonCallContext itself or the underlying data. Methods of the form withX 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 > HttpJsonCallContext

Implements

ApiCallContext

Static Methods

createDefault()

public static HttpJsonCallContext createDefault()

Returns an empty instance.

Returns
Type Description
HttpJsonCallContext

of(HttpJsonChannel channel, HttpJsonCallOptions options)

public static HttpJsonCallContext of(HttpJsonChannel channel, HttpJsonCallOptions options)
Parameters
Name Description
channel HttpJsonChannel
options HttpJsonCallOptions
Returns
Type Description
HttpJsonCallContext

Methods

<T>getOption(ApiCallContext.Key<T> key)

public T <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)

public ApiCallContext <T>withOption(ApiCallContext.Key<T> key, T value)

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

equals(Object o)

public boolean equals(Object o)
Parameter
Name Description
o Object
Returns
Type Description
boolean
Overrides

getCallOptions()

public HttpJsonCallOptions getCallOptions()
Returns
Type Description
HttpJsonCallOptions

getChannel()

public HttpJsonChannel getChannel()
Returns
Type Description
HttpJsonChannel

getCredentials() (deprecated)

public Credentials getCredentials()
Returns
Type Description
com.google.auth.Credentials

getDeadline() (deprecated)

public Instant getDeadline()
Returns
Type Description
org.threeten.bp.Instant

getExtraHeaders()

public Map<String,List<String>> getExtraHeaders()

Return the extra headers set for this context.

Returns
Type Description
Map<String,List<String>>

getRetrySettings()

public RetrySettings getRetrySettings()

Returns the RetrySettings to use with this context, or null if the default RetrySettings should be used.

Returns
Type Description
RetrySettings

getRetryableCodes()

public Set<StatusCode.Code> getRetryableCodes()

Returns the retryable codes to use with this context, or null if the default retryable codes should be used.

Returns
Type Description
Set<Code>

getStreamIdleTimeout()

public Duration getStreamIdleTimeout()

The stream idle timeout set for this context. See Also: ApiCallContext#withStreamIdleTimeout(Duration)

Returns
Type Description
org.threeten.bp.Duration

getStreamWaitTimeout()

public Duration getStreamWaitTimeout()

The stream wait timeout set for this context. See Also: ApiCallContext#withStreamWaitTimeout(Duration)

Returns
Type Description
org.threeten.bp.Duration

getTimeout()

public Duration getTimeout()

Returns the configured per-RPC timeout.

Returns
Type Description
org.threeten.bp.Duration

getTracer()

public ApiTracer getTracer()

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.

Returns
Type Description
ApiTracer

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

merge(ApiCallContext inputCallContext)

public HttpJsonCallContext merge(ApiCallContext inputCallContext)

For any values in inputCallContext that are not null, override the corresponding values in the present instance.

Parameter
Name Description
inputCallContext ApiCallContext
Returns
Type Description
HttpJsonCallContext

nullToSelf(ApiCallContext inputContext)

public HttpJsonCallContext nullToSelf(ApiCallContext inputContext)

Returns inputContext cast to HttpJsonCallContext, or an empty HttpJsonCallContext if inputContext is null.

Parameter
Name Description
inputContext ApiCallContext

the ApiCallContext to cast if it is not null

Returns
Type Description
HttpJsonCallContext

validateUniverseDomain()

public void validateUniverseDomain()

Validate the Universe Domain to ensure that the user configured Universe Domain and the Credentials' Universe Domain match. An exception will be raised if there are any issues when trying to validate (i.e. unable to access the universe domain).

withCallOptions(HttpJsonCallOptions newCallOptions)

public HttpJsonCallContext withCallOptions(HttpJsonCallOptions newCallOptions)
Parameter
Name Description
newCallOptions HttpJsonCallOptions
Returns
Type Description
HttpJsonCallContext

withChannel(HttpJsonChannel newChannel)

public HttpJsonCallContext withChannel(HttpJsonChannel newChannel)
Parameter
Name Description
newChannel HttpJsonChannel
Returns
Type Description
HttpJsonCallContext

withCredentials(Credentials newCredentials)

public HttpJsonCallContext withCredentials(Credentials newCredentials)

Returns a new ApiCallContext with the given credentials set.

Parameter
Name Description
newCredentials com.google.auth.Credentials
Returns
Type Description
HttpJsonCallContext

withDeadline(Instant newDeadline) (deprecated)

public HttpJsonCallContext withDeadline(Instant newDeadline)
Parameter
Name Description
newDeadline org.threeten.bp.Instant
Returns
Type Description
HttpJsonCallContext

withEndpointContext(EndpointContext endpointContext)

public HttpJsonCallContext withEndpointContext(EndpointContext endpointContext)

Returns a new ApiCallContext with the given Endpoint Context.

Parameter
Name Description
endpointContext EndpointContext
Returns
Type Description
HttpJsonCallContext

withExtraHeaders(Map<String,List<String>> extraHeaders)

public ApiCallContext withExtraHeaders(Map<String,List<String>> extraHeaders)

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)

public HttpJsonCallContext withRetrySettings(RetrySettings retrySettings)

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:


 ApiCallContext context = 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:


 ApiCallContext context = 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
HttpJsonCallContext

withRetryableCodes(Set<StatusCode.Code> retryableCodes)

public HttpJsonCallContext withRetryableCodes(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>
Returns
Type Description
HttpJsonCallContext

withStreamIdleTimeout(Duration streamIdleTimeout)

public HttpJsonCallContext withStreamIdleTimeout(Duration streamIdleTimeout)

Returns a new ApiCallContext with the given stream idle timeout set.

This timeout only applies to a ServerStreamingCallables. It limits the maximum amount of timeout that can pass between a message being received by ResponseObserver#onResponse(Object) and demand being signaled via StreamController#request(int). Please note that this timeout is best effort and the maximum resolution configured in StubSettings#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 nonretryable WatchdogTimeoutException and a status of StatusCode.Code#ABORTED.

A value of Duration#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 in StubSettings#getStreamWatchdogCheckInterval().

Parameter
Name Description
streamIdleTimeout org.threeten.bp.Duration
Returns
Type Description
HttpJsonCallContext

withStreamWaitTimeout(Duration streamWaitTimeout)

public HttpJsonCallContext withStreamWaitTimeout(Duration streamWaitTimeout)

Returns a new ApiCallContext with the given stream timeout set.

This timeout only applies to a ServerStreamingCallables. It limits the maximum amount of time that can pass between demand being signaled via StreamController#request(int) and actual message delivery to ResponseObserver#onResponse(Object). Or, in the case of automatic flow control, since the last message was delivered to ResponseObserver#onResponse(Object). This is useful to detect server or connection stalls. When the timeout has been reached, the stream will be closed with a retryable WatchdogTimeoutException and a status of StatusCode.Code#ABORTED.

A value of Duration#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 in StubSettings#getStreamWatchdogCheckInterval().

Parameter
Name Description
streamWaitTimeout org.threeten.bp.Duration
Returns
Type Description
HttpJsonCallContext

withTimeout(Duration timeout)

public HttpJsonCallContext withTimeout(Duration timeout)

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
Returns
Type Description
HttpJsonCallContext

withTracer(ApiTracer newTracer)

public HttpJsonCallContext withTracer(ApiTracer newTracer)

Returns a new ApiCallContext with the given ApiTracer.

The ApiTracer will be used to trace the current operation and to annotate various events like retries.

Parameter
Name Description
newTracer ApiTracer
Returns
Type Description
HttpJsonCallContext

withTransportChannel(TransportChannel inputChannel)

public HttpJsonCallContext withTransportChannel(TransportChannel inputChannel)

Returns a new ApiCallContext with the given channel set.

Parameter
Name Description
inputChannel TransportChannel
Returns
Type Description
HttpJsonCallContext