Skip to content

Commit 99d6646

Browse files
SergeyRyabininSergey Ryabinin
authored andcommitted
AWS Client call operation API
1 parent 6be8c1d commit 99d6646

File tree

8 files changed

+627
-90
lines changed

8 files changed

+627
-90
lines changed

src/aws-cpp-sdk-core/include/aws/core/client/AWSClient.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace Aws
6868
class AWSAuthSigner;
6969
struct ClientConfiguration;
7070
class RetryStrategy;
71+
class AwsClientAsyncRequestCtx;
7172

7273
typedef Utils::Outcome<std::shared_ptr<Aws::Http::HttpResponse>, AWSError<CoreErrors>> HttpResponseOutcome;
7374
typedef Utils::Outcome<AmazonWebServiceResult<Utils::Stream::ResponseStream>, AWSError<CoreErrors>> StreamOutcome;
@@ -242,6 +243,20 @@ namespace Aws
242243
const char* signerRegionOverride = nullptr,
243244
const char* signerServiceNameOverride = nullptr) const;
244245

246+
/* Block of Async API*/
247+
void StartAsyncAttempt(const Aws::Endpoint::AWSEndpoint& endpoint,
248+
Aws::AmazonWebServiceRequest const * const request,
249+
const char* requestName,
250+
Aws::Http::HttpMethod method,
251+
std::function<void(HttpResponseOutcome)> responseHandler,
252+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor) const;
253+
254+
void AttemptOneRequestAsync(std::shared_ptr<Aws::Client::AwsClientAsyncRequestCtx> pRequestCtx) const;
255+
256+
void HandleExhaustiveAsyncReply(std::shared_ptr<Aws::Client::AwsClientAsyncRequestCtx> pRequestCtx,
257+
std::shared_ptr<Aws::Http::HttpResponse> httpResponse) const;
258+
/* eof Block of Async API */
259+
245260
/**
246261
* This is used for structureless response payloads (file streams, binary data etc...). It calls AttemptExhaustively, but upon
247262
* return transfers ownership of the underlying stream for the http response to the caller.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <aws/core/Core_EXPORTS.h>
7+
8+
#include <aws/core/endpoint/AWSEndpoint.h>
9+
#include <aws/core/http/HttpRequest.h>
10+
#include <aws/core/AmazonWebServiceRequest.h>
11+
12+
#include <aws/core/utils/DateTime.h>
13+
14+
15+
namespace Aws
16+
{
17+
namespace Client
18+
{
19+
class AwsClientAsyncRequestCtx
20+
{
21+
public:
22+
struct RequestInfo
23+
{
24+
Aws::Utils::DateTime ttl;
25+
long attempt;
26+
long maxAttempts;
27+
28+
operator String()
29+
{
30+
Aws::StringStream ss;
31+
if (ttl.WasParseSuccessful() && ttl != Aws::Utils::DateTime())
32+
{
33+
assert(attempt > 1);
34+
ss << "ttl=" << ttl.ToGmtString(Aws::Utils::DateFormat::ISO_8601_BASIC) << "; ";
35+
}
36+
ss << "attempt=" << attempt;
37+
if (maxAttempts > 0)
38+
{
39+
ss << "; max=" << maxAttempts;
40+
}
41+
return ss.str();
42+
}
43+
};
44+
45+
Aws::String m_invocationId;
46+
Http::HttpMethod m_method;
47+
const Aws::AmazonWebServiceRequest* m_pRequest; // optional
48+
49+
RequestInfo m_requestInfo;
50+
Aws::String m_requestName;
51+
std::shared_ptr<Aws::Http::HttpRequest> m_httpRequest;
52+
Aws::Endpoint::AWSEndpoint m_endpoint;
53+
54+
Aws::Crt::Optional<AWSError<CoreErrors>> m_lastError;
55+
56+
size_t m_retryCount;
57+
Aws::Vector<void*> m_monitoringContexts;
58+
59+
std::function<void(HttpResponseOutcome)> m_responseHandler;
60+
std::shared_ptr<Aws::Utils::Threading::Executor> m_pExecutor;
61+
62+
};
63+
} // namespace Client
64+
} // namespace Aws

src/aws-cpp-sdk-core/include/aws/core/client/AWSXmlClient.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ namespace Aws
127127
const char* requestName = "",
128128
const char* signerRegionOverride = nullptr,
129129
const char* signerServiceNameOverride = nullptr) const;
130+
131+
132+
void MakeAsyncRequest(Aws::AmazonWebServiceRequest const * const request,
133+
const char* requestName,
134+
Aws::Endpoint::AWSEndpoint endpoint,
135+
std::function<void(XmlOutcome)> responseHandler,
136+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
137+
Http::HttpMethod method /* = Http::HttpMethod::HTTP_POST */) const;
138+
139+
XmlOutcome HandleHttpResponse(const char* requestName, HttpResponseOutcome httpOutcome) const;
130140
};
131141

132142
} // namespace Client

src/aws-cpp-sdk-core/include/aws/core/http/HttpClient.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
#include <memory>
1111
#include <atomic>
12+
#include <functional>
1213
#include <mutex>
1314
#include <condition_variable>
1415

16+
#include <aws/core/utils/UnreferencedParam.h>
17+
1518
namespace Aws
1619
{
1720
namespace Utils
@@ -20,6 +23,10 @@ namespace Aws
2023
{
2124
class RateLimiterInterface;
2225
} // namespace RateLimits
26+
namespace Threading
27+
{
28+
class Executor;
29+
}
2330
} // namespace Utils
2431

2532
namespace Http
@@ -43,6 +50,34 @@ namespace Aws
4350
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
4451
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const = 0;
4552

53+
/**
54+
* Takes an http request, makes it, and returns the newly allocated HttpResponse.
55+
*/
56+
virtual std::shared_ptr<HttpResponse> MakeSyncRequest(const std::shared_ptr<HttpRequest>& request,
57+
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
58+
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const
59+
{
60+
return MakeRequest(request, readLimiter, writeLimiter);
61+
}
62+
63+
64+
using HttpAsyncOnDoneHandler = std::function<void(std::shared_ptr<HttpResponse>)>;
65+
//typedef std::function<void(std::shared_ptr<HttpResponse>)> HttpAsyncOnDoneHandler;
66+
67+
virtual void MakeAsyncRequest(const std::shared_ptr<HttpRequest>& request,
68+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
69+
HttpAsyncOnDoneHandler onDoneHandler,
70+
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
71+
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const
72+
{
73+
// TODO: fixme, provide backward compatibility
74+
AWS_UNREFERENCED_PARAM(request);
75+
AWS_UNREFERENCED_PARAM(pExecutor);
76+
AWS_UNREFERENCED_PARAM(onDoneHandler);
77+
AWS_UNREFERENCED_PARAM(readLimiter);
78+
AWS_UNREFERENCED_PARAM(writeLimiter);
79+
}
80+
4681
/**
4782
* If yes, the http client supports transfer-encoding:chunked.
4883
*/

src/aws-cpp-sdk-core/include/aws/core/http/curl-multi/CurlMultiHttpClient.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,23 @@ class AWS_CORE_API CurlMultiHttpClient: public HttpClient
7474
//Makes request and receives response synchronously
7575
std::shared_ptr<HttpResponse> MakeRequest(const std::shared_ptr<HttpRequest>& request,
7676
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
77-
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;
77+
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override
78+
{
79+
// TODO: put back the original curl_easy_perform wrapper (and then remove later)
80+
return MakeSyncRequest(request, readLimiter, writeLimiter);
81+
}
82+
83+
//Makes request and receives response synchronously using the curl_multi api
84+
std::shared_ptr<HttpResponse> MakeSyncRequest(const std::shared_ptr<HttpRequest>& request,
85+
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
86+
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;
87+
88+
/* Makes request and process reply async using the curl_multi api and Executor API */
89+
virtual void MakeAsyncRequest(const std::shared_ptr<HttpRequest>& request,
90+
std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor,
91+
HttpClient::HttpAsyncOnDoneHandler onDoneHandler,
92+
Aws::Utils::RateLimits::RateLimiterInterface* readLimiter = nullptr,
93+
Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter = nullptr) const override;
7894

7995
static void InitGlobalState();
8096
static void CleanupGlobalState();

0 commit comments

Comments
 (0)