Class RpcRetryOptions.Builder

  • Enclosing class:
    RpcRetryOptions

    public static final class RpcRetryOptions.Builder
    extends java.lang.Object
    • Method Detail

      • setInitialInterval

        public RpcRetryOptions.Builder setInitialInterval​(java.time.Duration initialInterval)
        Interval of the first retry. If coefficient is 1.0 then it is used for all retries. Required.
      • setExpiration

        public RpcRetryOptions.Builder setExpiration​(java.time.Duration expiration)
        Maximum time to retry. When exceeded the retries stop even if maximum retries is not reached yet.

        At least one of the expiration or setMaximumAttempts(int) is required to be set.

      • setBackoffCoefficient

        public RpcRetryOptions.Builder setBackoffCoefficient​(double backoffCoefficient)
        Coefficient used to calculate the next retry interval. The next retry interval is previous interval multiplied by this coefficient. Must be 1 or larger. Default is 2.0.
      • setMaximumAttempts

        public RpcRetryOptions.Builder setMaximumAttempts​(int maximumAttempts)
        When exceeded the amount of attempts, stop. Even if expiration time is not reached.
        Default is unlimited.

        At least one of the maximum attempts or setExpiration(Duration) is required to be set.

        Parameters:
        maximumAttempts - Maximum number of attempts. Default will be used if set to 0.
      • setMaximumInterval

        public RpcRetryOptions.Builder setMaximumInterval​(java.time.Duration maximumInterval)
        Maximum interval between retries. Exponential backoff leads to interval increase. This value is the cap of the increase.
        Default is 100x of initial interval. Can't be less than setInitialInterval(Duration)
        Parameters:
        maximumInterval - the maximum interval value. Default will be used if set to null.
      • addDoNotRetry

        public RpcRetryOptions.Builder addDoNotRetry​(io.grpc.Status.Code code,
                                                     @Nullable
                                                     java.lang.Class<? extends com.google.protobuf.GeneratedMessageV3> detailsClass)
        Makes request that receives a server response with gRPC code and failure of detailsClass type non-retryable.

        The following gRPC codes are never retried:

        • Status.Code.CANCELLED
        • Status.Code.INVALID_ARGUMENT
        • Status.Code.NOT_FOUND
        • Status.Code.ALREADY_EXISTS
        • Status.Code.FAILED_PRECONDITION
        • Status.Code.PERMISSION_DENIED
        • Status.Code.UNAUTHENTICATED
        • Status.Code.UNIMPLEMENTED
        Parameters:
        code - gRPC code to don't retry
        detailsClass - failure type to don't retry. null means to wildcard, all failures with the code code are non retryable.
      • addDoNotRetry

        public RpcRetryOptions.Builder addDoNotRetry​(RpcRetryOptions.DoNotRetryItem doNotRetryItem)
        Makes request that receives a server response with gRPC doNotRetryItem.code and failure of doNotRetryItem.detailsClass type non-retryable.

        The following gRPC codes are never retried:

        • Status.Code.CANCELLED
        • Status.Code.INVALID_ARGUMENT
        • Status.Code.NOT_FOUND
        • Status.Code.ALREADY_EXISTS
        • Status.Code.FAILED_PRECONDITION
        • Status.Code.PERMISSION_DENIED
        • Status.Code.UNAUTHENTICATED
        • Status.Code.UNIMPLEMENTED
        Parameters:
        doNotRetryItem - specifies gRPC code and failure type that shouldn't be retried. If doNotRetryItem.detailsClass==null, all failures with the doNotRetryItem.code code are non retryable.
      • build

        public RpcRetryOptions build()
        Build RetryOptions without performing validation as validation should be done after merging with MethodRetry.
      • validateBuildWithDefaults

        public RpcRetryOptions validateBuildWithDefaults()
        Validates property values and builds RetryOptions with default values.