JavaScript is disabled on your browser.
Skip navigation links

AWS SDK for Java 1.x API Reference - 1.12.795

We announced the upcoming end-of-support for AWS SDK for Java (v1). We recommend that you migrate to AWS SDK for Java v2. For dates, additional details, and information on how to migrate, please refer to the linked announcement.
com.amazonaws.internal

Class TokenBucket



  • public class TokenBucket
    extends Object 
    • Nested Class Summary

      Nested Classes
      Modifier and Type Class and Description
      static interface TokenBucket.Clock
    • Constructor Summary

      Constructors
      Constructor and Description
      TokenBucket ()
    • Method Summary

      All Methods
      Modifier and Type Method and Description
      boolean acquire (double amount)
      Acquire tokens from the bucket.
      boolean acquire (double amount, boolean fastFail)
      Acquire tokens from the bucket.
      void updateClientSendingRate (boolean throttlingResponse)
      _UpdateClientSendingRate(response) _UpdateMeasuredRate() if IsThrottlingError(response) if not enabled rate_to_use = measured_tx_rate else rate_to_use = min(measured_tx_rate, fill_rate) # The fill_rate is from the token bucket.
    • Constructor Detail

      • TokenBucket

        public TokenBucket()
    • Method Detail

      • acquire

        public boolean acquire(double amount)
        Acquire tokens from the bucket. If the bucket contains enough capacity to satisfy the request, this method will return immediately, otherwise the method will block the calling thread until enough tokens are refilled.

         _TokenBucketAcquire(amount)
         # Client side throttling is not enabled until we see a throttling error.
         if not enabled
         return
         _TokenBucketRefill()
         # Next see if we have enough capacity for the requested amount.
         if amount <= current_capacity current_capacity = current_capacity - amount else sleep((amount - current_capacity) / fill_rate) current_capacity = current_capacity - amount return 

        This is equivalent to acquire(amount, false).

        Parameters:
        amount - The amount of tokens to acquire.
        Returns:
        Whether the amount was successfully acquired.
      • acquire

        public boolean acquire(double amount,
         boolean fastFail)
        Acquire tokens from the bucket. If the bucket contains enough capacity to satisfy the request, this method will return immediately. Otherwise, the behavior depends on the value of fastFail. If it is true, then it will return false immediately, signaling that enough capacity could not be acquired. Otherwise if fastFail is false, then it will wait the required amount of time to fill the bucket with enough tokens to satisfy amount.
         _TokenBucketAcquire(amount)
         # Client side throttling is not enabled until we see a throttling error.
         if not enabled
         return
         _TokenBucketRefill()
         # Next see if we have enough capacity for the requested amount.
         if amount <= current_capacity current_capacity = current_capacity - amount else sleep((amount - current_capacity) / fill_rate) current_capacity = current_capacity - amount return 
        Parameters:
        amount - The amount of tokens to acquire.
        fastFail - Whether this method should return immediately instead of waiting if amount exceeds the current capacity.
        Returns:
        Whether the amount was successfully acquired.
      • updateClientSendingRate

        public void updateClientSendingRate(boolean throttlingResponse)
         _UpdateClientSendingRate(response)
         _UpdateMeasuredRate()
         if IsThrottlingError(response)
         if not enabled
         rate_to_use = measured_tx_rate
         else
         rate_to_use = min(measured_tx_rate, fill_rate)
         # The fill_rate is from the token bucket.
         last_max_rate = rate_to_use
         _CalculateTimeWindow()
         last_throttle_time = time()
         calculated_rate = _CUBICThrottle(rate_to_use)
         TokenBucketEnable()
         else
         _CalculateTimeWindow()
         calculated_rate = _CUBICSuccess(time())
         new_rate = min(calculated_rate, 2 * measured_tx_rate)
         _TokenBucketUpdateRate(new_rate)
         
Skip navigation links

AltStyle によって変換されたページ (->オリジナル) /