You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "lordgamez (via GitHub)" <gi...@apache.org> on 2025/01/06 13:31:30 UTC
Re: [PR] MINIFICPP-2485 fix: Support Expression Language in InvokeHTTP "Remote URL" property [nifi-minifi-cpp]
lordgamez commented on code in PR #1904:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1904#discussion_r1904155188
##########
extensions/standard-processors/processors/InvokeHTTP.h:
##########
@@ -41,9 +42,60 @@
#include "utils/Enum.h"
#include "utils/RegexUtils.h"
+namespace org::apache::nifi::minifi::test {
+class HttpClientStoreTestAccessor;
+}
+
namespace org::apache::nifi::minifi::processors {
namespace invoke_http {
+class HttpClientStore {
+ public:
+ HttpClientStore(const size_t size, std::function<gsl::not_null<std::unique_ptr<minifi::http::HTTPClient>>(const std::string&)> create_client_function)
+ : max_size_(size),
+ create_client_function_(std::move(create_client_function)) {
+ clients_.resize(size);
+ }
+ HttpClientStore(const HttpClientStore&) = delete;
+ HttpClientStore& operator=(const HttpClientStore&) = delete;
+ HttpClientStore(HttpClientStore&&) = delete;
+ HttpClientStore& operator=(HttpClientStore&&) = delete;
+ ~HttpClientStore() = default;
+
+ class HttpClientWrapper {
+ public:
+ HttpClientWrapper(HttpClientStore& client_store, minifi::http::HTTPClient& client) : client_(client), client_store_(client_store) {
+ }
+ HttpClientWrapper(HttpClientWrapper&& src) = default;
+ HttpClientWrapper(const HttpClientWrapper&) = delete;
+ ~HttpClientWrapper() {
+ client_store_.returnClient(client_);
+ }
+
+ minifi::http::HTTPClient& get() const {
+ return client_;
+ }
+
+ private:
+ minifi::http::HTTPClient& client_;
+ HttpClientStore& client_store_;
+ };
+
+ [[nodiscard]] HttpClientWrapper getClient(const std::string& url);
+
+ private:
+ friend class ::org::apache::nifi::minifi::test::HttpClientStoreTestAccessor;
+ void returnClient(minifi::http::HTTPClient& client);
+
+ std::mutex clients_mutex_;
+ std::condition_variable cv_;
+ const size_t max_size_;
+ size_t clients_created_{0};
+ std::vector<std::pair<std::unique_ptr<minifi::http::HTTPClient>, bool>> clients_;
Review Comment:
Thanks for the example I see your point now, I think it's a bit simpler and removing the need to maintain the `clients_created_ variable` is worth this change, I updated it in https://github.com/apache/nifi-minifi-cpp/pull/1904/commits/028d6b5e699dca283b7b0d706bacbc79887dcb8a
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org