Class GrpcCallContext

  • All Implemented Interfaces:
    RetryingContext, ApiCallContext

    @BetaApi("Reference ApiCallContext instead - this class is likely to experience breaking changes")
    public final class GrpcCallContext
    extends java.lang.Object
    implements ApiCallContext
    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(com.google.api.gax.rpc.TransportChannel), return copies of the object, but with one field changed. The immutability and thread safety of the arguments solely depends on the arguments themselves.

    • Method Detail

      • createDefault

        public static GrpcCallContext createDefault()
        Returns an empty instance with a null channel and default CallOptions.
      • of

        public static GrpcCallContext of​(io.grpc.Channel channel,
                                         io.grpc.CallOptions callOptions)
        Returns an instance with the given channel and CallOptions.
      • withTimeout

        public GrpcCallContext withTimeout​(@Nullable
                                           org.threeten.bp.Duration timeout)
        Description copied from interface: ApiCallContext
        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 RetrySettings, the max attempts and/or total timeout is still respected when scheduling each RPC attempt.

        Specified by:
        withTimeout in interface ApiCallContext
      • getTimeout

        @Nullable
        public org.threeten.bp.Duration getTimeout()
        Description copied from interface: ApiCallContext
        Returns the configured per-RPC timeout.
        Specified by:
        getTimeout in interface ApiCallContext
      • withChannelAffinity

        @BetaApi("The surface for channel affinity is not stable yet and may change in the future.")
        public GrpcCallContext withChannelAffinity​(@Nullable
                                                   java.lang.Integer affinity)
      • withExtraHeaders

        @BetaApi("The surface for extra headers is not stable yet and may change in the future.")
        public GrpcCallContext withExtraHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> extraHeaders)
        Description copied from interface: ApiCallContext
        Return a new ApiCallContext with the extraHeaders merged into the present instance.
        Specified by:
        withExtraHeaders in interface ApiCallContext
      • withRetryableCodes

        public GrpcCallContext withRetryableCodes​(java.util.Set<StatusCode.Code> retryableCodes)
        Description copied from interface: ApiCallContext
        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 ApiCallContext.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.

        Specified by:
        withRetryableCodes in interface ApiCallContext
      • getChannel

        public io.grpc.Channel getChannel()
        The Channel set on this context.
      • getCallOptions

        public io.grpc.CallOptions getCallOptions()
        The CallOptions set on this context.
      • getChannelAffinity

        @Nullable
        public java.lang.Integer getChannelAffinity()
        The channel affinity for this context.
      • getExtraHeaders

        @BetaApi("The surface for extra headers is not stable yet and may change in the future.")
        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getExtraHeaders()
        The extra header for this context.
        Specified by:
        getExtraHeaders in interface ApiCallContext
      • withChannel

        public GrpcCallContext withChannel​(io.grpc.Channel newChannel)
        Returns a new instance with the channel set to the given channel.
      • withCallOptions

        public GrpcCallContext withCallOptions​(io.grpc.CallOptions newCallOptions)
        Returns a new instance with the call options set to the given call options.
      • withRequestParamsDynamicHeaderOption

        public GrpcCallContext withRequestParamsDynamicHeaderOption​(java.lang.String requestParams)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object