Class RetriableStream.Throttle

  • Enclosing class:
    RetriableStream<ReqT>

    static final class RetriableStream.Throttle
    extends java.lang.Object
    Used for retry throttling.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int maxTokens
      1000 times the maxTokens field of the retryThrottling policy in service config.
      private static int THREE_DECIMAL_PLACES_SCALE_UP  
      (package private) int threshold
      Half of maxTokens.
      (package private) java.util.concurrent.atomic.AtomicInteger tokenCount  
      (package private) int tokenRatio
      1000 times the tokenRatio field of the retryThrottling policy in service config.
    • Constructor Summary

      Constructors 
      Constructor Description
      Throttle​(float maxTokens, float tokenRatio)  
    • Field Detail

      • THREE_DECIMAL_PLACES_SCALE_UP

        private static final int THREE_DECIMAL_PLACES_SCALE_UP
        See Also:
        Constant Field Values
      • maxTokens

        final int maxTokens
        1000 times the maxTokens field of the retryThrottling policy in service config. The number of tokens starts at maxTokens. The token_count will always be between 0 and maxTokens.
      • threshold

        final int threshold
        Half of maxTokens.
      • tokenRatio

        final int tokenRatio
        1000 times the tokenRatio field of the retryThrottling policy in service config.
      • tokenCount

        final java.util.concurrent.atomic.AtomicInteger tokenCount
    • Constructor Detail

      • Throttle

        Throttle​(float maxTokens,
                 float tokenRatio)
    • Method Detail

      • isAboveThreshold

        boolean isAboveThreshold()
      • onQualifiedFailureThenCheckIsAboveThreshold

        boolean onQualifiedFailureThenCheckIsAboveThreshold()
        Counts down the token on qualified failure and checks if it is above the threshold atomically. Qualified failure is a failure with a retryable or non-fatal status code or with a not-to-retry pushback.
      • onSuccess

        void onSuccess()
      • equals

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

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