@@ -15,15 +15,18 @@ namespace Aws
1515{
1616 namespace Client
1717 {
18- static const int THROTTLE_BASED_RETRY_COST = 14 ;
19- static const int THROTTLE_BASED_THROTTLING_COST = 5 ;
20- static const int THROTTLE_BASED_INITIAL_TOKENS = 500 ;
18+ struct QuotaConfig
19+ {
20+ int retryCost = 14 ;
21+ int throttlingCost = 5 ;
22+ int initialTokens = 500 ;
23+ };
2124
2225 class AWS_CORE_LOCAL ThrottleBasedRetryQuotaContainer : public RetryQuotaContainer
2326 {
2427 public:
25- ThrottleBasedRetryQuotaContainer (int retryCost = THROTTLE_BASED_RETRY_COST , int throttlingRetryCost = THROTTLE_BASED_THROTTLING_COST )
26- : m_retryQuota( THROTTLE_BASED_INITIAL_TOKENS ), m_retryCost(retryCost), m_throttlingRetryCost(throttlingRetryCost ) {}
28+ ThrottleBasedRetryQuotaContainer (const QuotaConfig& config = QuotaConfig{} )
29+ : m_config(config ), m_retryQuota(config.initialTokens ) {}
2730
2831 virtual ~ThrottleBasedRetryQuotaContainer () = default ;
2932
@@ -43,29 +46,28 @@ namespace Aws
4346
4447 bool AcquireRetryQuota (const AWSError<CoreErrors>& error) override
4548 {
46- int capacityAmount = error.ShouldThrottle () ? m_throttlingRetryCost : m_retryCost ;
49+ int capacityAmount = error.ShouldThrottle () ? m_config. throttlingCost : m_config. retryCost ;
4750 return AcquireRetryQuota (capacityAmount);
4851 }
4952
5053 void ReleaseRetryQuota (int capacityAmount) override
5154 {
5255 Aws::Utils::Threading::WriterLockGuard guard (m_retryQuotaLock);
53- m_retryQuota = (std::min)(m_retryQuota + capacityAmount, THROTTLE_BASED_INITIAL_TOKENS );
56+ m_retryQuota = (std::min)(m_retryQuota + capacityAmount, m_config. initialTokens );
5457 }
5558
5659 void ReleaseRetryQuota (const AWSError<CoreErrors>& error) override
5760 {
58- int capacityAmount = error.ShouldThrottle () ? m_throttlingRetryCost : m_retryCost ;
61+ int capacityAmount = error.ShouldThrottle () ? m_config. throttlingCost : m_config. retryCost ;
5962 ReleaseRetryQuota (capacityAmount);
6063 }
6164
6265 int GetRetryQuota () const override { return m_retryQuota; }
6366
6467 private:
68+ QuotaConfig m_config;
6569 mutable Aws::Utils::Threading::ReaderWriterLock m_retryQuotaLock;
6670 int m_retryQuota;
67- int m_retryCost;
68- int m_throttlingRetryCost;
6971 };
7072 } // namespace Client
7173} // namespace Aws
0 commit comments