AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
RetryStrategy.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/utils/threading/ReaderWriterLock.h>
10#include <memory>
11
12namespace Aws
13{
14 namespace Http
15 {
16 class HttpResponse;
17 }
18
19 namespace Utils
20 {
21 template<typename R, typename E>
22 class Outcome;
23 }
24
25 namespace Client
26 {
27 static const int NO_RETRY_INCREMENT = 1;
28
29 enum class CoreErrors;
30 template<typename ERROR_TYPE>
31 class AWSError;
32
34
38 class AWS_CORE_API RetryStrategy
39 {
40 public:
41 virtual ~RetryStrategy() = default;
45 virtual bool ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const = 0;
46
50 virtual long CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const = 0;
51
56 virtual long GetMaxAttempts() const { return 0; }
57
61 virtual void GetSendToken() {}
62
66 virtual bool HasSendToken()
67 {
68 GetSendToken(); // first call old method for backward compatibility
69 return true;
70 }
71
75 virtual void RequestBookkeeping(const HttpResponseOutcome& /* httpResponseOutcome */) {}
76 virtual void RequestBookkeeping(const HttpResponseOutcome& /* httpResponseOutcome */, const AWSError<CoreErrors>& /* lastError */) {}
77
81 virtual const char* GetStrategyName() const
82 {
83 // SDK provided strategies will provide actual name
84 return "custom";
85 }
86 };
87
94 class AWS_CORE_API RetryQuotaContainer
95 {
96 public:
97 virtual ~RetryQuotaContainer() = default;
98 virtual bool AcquireRetryQuota(int capacityAmount) = 0;
99 virtual bool AcquireRetryQuota(const AWSError<CoreErrors>& error) = 0;
100 virtual void ReleaseRetryQuota(int capacityAmount) = 0;
101 virtual void ReleaseRetryQuota(const AWSError<CoreErrors>& lastError) = 0;
102 virtual int GetRetryQuota() const = 0;
103 };
104
106 {
107 public:
109 virtual ~DefaultRetryQuotaContainer() = default;
110 virtual bool AcquireRetryQuota(int capacityAmount) override;
111 virtual bool AcquireRetryQuota(const AWSError<CoreErrors>& error) override;
112 virtual void ReleaseRetryQuota(int capacityAmount) override;
113 virtual void ReleaseRetryQuota(const AWSError<CoreErrors>& lastError) override;
114 virtual int GetRetryQuota() const override { return m_retryQuota; }
115
116 protected:
119 };
120
121 class AWS_CORE_API StandardRetryStrategy : public RetryStrategy
122 {
123 public:
124 StandardRetryStrategy(long maxAttempts = 3);
125 StandardRetryStrategy(std::shared_ptr<RetryQuotaContainer> retryQuotaContainer, long maxAttempts = 3);
126
127 virtual void RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome) override;
128 virtual void RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome, const AWSError<CoreErrors>& lastError) override;
129
130 virtual bool ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const override;
131
132 virtual long CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const override;
133
134 virtual long GetMaxAttempts() const override { return m_maxAttempts; }
135
136 const char* GetStrategyName() const override { return "standard";}
137
138 protected:
139 std::shared_ptr<RetryQuotaContainer> m_retryQuotaContainer;
141 };
142 } // namespace Client
143} // namespace Aws
virtual bool AcquireRetryQuota(const AWSError< CoreErrors > &error) override
virtual void ReleaseRetryQuota(int capacityAmount) override
Aws::Utils::Threading::ReaderWriterLock m_retryQuotaLock
virtual bool AcquireRetryQuota(int capacityAmount) override
virtual void ReleaseRetryQuota(const AWSError< CoreErrors > &lastError) override
virtual int GetRetryQuota() const override
virtual void ReleaseRetryQuota(int capacityAmount)=0
virtual bool AcquireRetryQuota(const AWSError< CoreErrors > &error)=0
virtual bool AcquireRetryQuota(int capacityAmount)=0
virtual int GetRetryQuota() const =0
virtual ~RetryQuotaContainer()=default
virtual void ReleaseRetryQuota(const AWSError< CoreErrors > &lastError)=0
virtual ~RetryStrategy()=default
virtual void RequestBookkeeping(const HttpResponseOutcome &, const AWSError< CoreErrors > &)
virtual bool ShouldRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const =0
virtual long CalculateDelayBeforeNextRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const =0
virtual long GetMaxAttempts() const
virtual const char * GetStrategyName() const
virtual void RequestBookkeeping(const HttpResponseOutcome &)
std::shared_ptr< RetryQuotaContainer > m_retryQuotaContainer
virtual void RequestBookkeeping(const HttpResponseOutcome &httpResponseOutcome) override
virtual void RequestBookkeeping(const HttpResponseOutcome &httpResponseOutcome, const AWSError< CoreErrors > &lastError) override
virtual bool ShouldRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const override
virtual long CalculateDelayBeforeNextRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const override
const char * GetStrategyName() const override
StandardRetryStrategy(std::shared_ptr< RetryQuotaContainer > retryQuotaContainer, long maxAttempts=3)
StandardRetryStrategy(long maxAttempts=3)
virtual long GetMaxAttempts() const override
static const int NO_RETRY_INCREMENT
Utils::Outcome< std::shared_ptr< Aws::Http::HttpResponse >, AWSError< CoreErrors > > HttpResponseOutcome
Definition AWSClient.h:71