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.
Static Methods
createDefault()
public static HttpJsonCallContext createDefault ()
Returns an empty instance.
of(HttpJsonChannel channel, HttpJsonCallOptions options)
public static HttpJsonCallContext of ( HttpJsonChannel channel , HttpJsonCallOptions options )
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
equals(@Nullable Object o)
public boolean equals ( @Nullable Object o )
Parameter
Name
Description
o
@org.jspecify.annotations.Nullable java.lang.Object
Overrides
getCallOptions()
public HttpJsonCallOptions getCallOptions ()
getChannel()
public @Nullable HttpJsonChannel getChannel ()
Returns
Type
Description
@org.jspecify.annotations.Nullable com.google.api.gax.httpjson.HttpJsonChannel
getCredentials() (deprecated)
public @Nullable Credentials getCredentials ()
Returns
Type
Description
@org.jspecify.annotations.Nullable com.google.auth.Credentials
getDeadline() (deprecated)
public @Nullable Instant getDeadline ()
Returns
Type
Description
@org.jspecify.annotations.Nullable org.threeten.bp.Instant
public Map<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 the Pre-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.
getRetrySettings()
public RetrySettings getRetrySettings ()
Returns the RetrySettings to use with this context, or null if the default
RetrySettings should be used.
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.
getStreamIdleTimeout()
public @Nullable Duration getStreamIdleTimeout ()
Obsolete
Use getStreamIdleTimeoutDuration() instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #getStreamIdleTimeoutDuration() instead.
Returns
Type
Description
@org.jspecify.annotations.Nullable org.threeten.bp.Duration
getStreamIdleTimeoutDuration()
public @Nullable Duration getStreamIdleTimeoutDuration ()
Returns
Type
Description
@org.jspecify.annotations.Nullable java.time.Duration
getStreamWaitTimeout()
public @Nullable Duration getStreamWaitTimeout ()
Obsolete
Use getStreamWaitTimeoutDuration() instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #getStreamWaitTimeoutDuration() instead.
Returns
Type
Description
@org.jspecify.annotations.Nullable org.threeten.bp.Duration
getStreamWaitTimeoutDuration()
public @Nullable Duration getStreamWaitTimeoutDuration ()
Returns
Type
Description
@org.jspecify.annotations.Nullable java.time.Duration
getTimeout()
public @Nullable Duration getTimeout ()
Obsolete
Use getTimeoutDuration instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #getTimeoutDuration() instead.
Returns
Type
Description
@org.jspecify.annotations.Nullable org.threeten.bp.Duration
getTimeoutDuration()
public @Nullable Duration getTimeoutDuration ()
Returns the configured per-RPC timeout.
Returns
Type
Description
@org.jspecify.annotations.Nullable java.time.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.
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.
nullToSelf(ApiCallContext inputContext)
public HttpJsonCallContext nullToSelf ( ApiCallContext inputContext )
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 )
withChannel(@Nullable HttpJsonChannel newChannel)
public HttpJsonCallContext withChannel ( @Nullable HttpJsonChannel newChannel )
Parameter
Name
Description
newChannel
@org.jspecify.annotations.Nullable com.google.api.gax.httpjson.HttpJsonChannel
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
withDeadline(Instant newDeadline) (deprecated)
public HttpJsonCallContext withDeadline ( Instant newDeadline )
Parameter
Name
Description
newDeadline
org.threeten.bp.Instant
withEndpointContext(EndpointContext endpointContext)
public HttpJsonCallContext withEndpointContext ( EndpointContext endpointContext )
Returns a new ApiCallContext with the given Endpoint Context.
public ApiCallContext withExtraHeaders ( 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 the Pre-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.
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(java.time.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 ());
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 >
withStreamIdleTimeout(@Nullable Duration streamIdleTimeout)
public HttpJsonCallContext withStreamIdleTimeout ( @Nullable Duration streamIdleTimeout )
Obsolete
Use withStreamIdleTimeoutDuration(java.time.Duration) instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #withStreamIdleTimeoutDuration(java.time.Duration)
instead.
Parameter
Name
Description
streamIdleTimeout
@org.jspecify.annotations.Nullable org.threeten.bp.Duration
withStreamIdleTimeoutDuration(@Nullable Duration streamIdleTimeout)
public HttpJsonCallContext withStreamIdleTimeoutDuration ( @Nullable Duration streamIdleTimeout )
Parameter
Name
Description
streamIdleTimeout
@org.jspecify.annotations.Nullable java.time.Duration
withStreamWaitTimeout(@Nullable Duration streamWaitTimeout)
public HttpJsonCallContext withStreamWaitTimeout ( @Nullable Duration streamWaitTimeout )
Obsolete
Use withStreamWaitTimeoutDuration(java.time.Duration) instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #withStreamWaitTimeoutDuration(java.time.Duration)
instead.
Parameter
Name
Description
streamWaitTimeout
@org.jspecify.annotations.Nullable org.threeten.bp.Duration
withStreamWaitTimeoutDuration(@Nullable Duration streamWaitTimeout)
public HttpJsonCallContext withStreamWaitTimeoutDuration ( @Nullable Duration streamWaitTimeout )
Parameter
Name
Description
streamWaitTimeout
@org.jspecify.annotations.Nullable java.time.Duration
withTimeout(Duration timeout)
public HttpJsonCallContext withTimeout ( Duration timeout )
Obsolete
Use withTimeoutDuration(java.time.Duration) instead
This feature is stable for usage in this major version, but may be deprecated in a future release.
This method is obsolete. Use #withTimeoutDuration(java.time.Duration) instead.
Parameter
Name
Description
timeout
org.threeten.bp.Duration
withTimeoutDuration(Duration timeout)
public HttpJsonCallContext withTimeoutDuration ( Duration timeout )
Parameter
Name
Description
timeout
Duration
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
withTransportChannel(TransportChannel inputChannel)
public HttpJsonCallContext withTransportChannel ( TransportChannel inputChannel )
Returns a new ApiCallContext with the given channel set.