userver: userver/ugrpc/client/client_factory.hpp Source File
Loading...
Searching...
No Matches
client_factory.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <optional>
7#include <string>
8#include <utility>
9
12
13#include <userver/concurrent/impl/striped_read_indicator.hpp>
17#include <userver/ugrpc/client/impl/client_internals.hpp>
18#include <userver/ugrpc/client/impl/client_qos_errors_reporter.hpp>
20#include <userver/ugrpc/impl/static_service_metadata.hpp>
21
22USERVER_NAMESPACE_BEGIN
23
24namespace ugrpc::impl {
25class StatisticsStorage;
26class CompletionQueuePoolBase;
27} // namespace ugrpc::impl
28
29namespace ugrpc::client {
30
42class ClientFactory final {
43public:
45 template <typename Client>
46 Client MakeClient(ClientSettings&& client_settings);
47
52 template <typename Client>
53 Client MakeClient(const std::string& client_name, const std::string& endpoint);
54
56 // For internal use only.
58 ClientFactorySettings&& client_factory_settings,
59 engine::TaskProcessor& channel_task_processor,
60 impl::MiddlewarePipelineCreator& middleware_pipeline_creator,
61 ugrpc::impl::CompletionQueuePoolBase& completion_queues,
62 ugrpc::impl::StatisticsStorage& statistics_storage,
63 utils::statistics::MetricsStorage& metrics_storage,
64 testsuite::GrpcControl& testsuite_grpc,
65 dynamic_config::Source config_source
66 );
68
70
71private:
72 impl::ClientInternals MakeClientInternals(
73 ClientSettings&& client_settings,
74 std::optional<ugrpc::impl::StaticServiceMetadata> meta
75 );
76
77 // Ensures that all clients created by this factory are destroyed before
78 // the factory itself. If any client outlives the factory, the program
79 // will abort with a stacktrace in the factory's destructor.
80 concurrent::impl::StripedReadIndicator alive_clients_indicator_;
81
82 ClientFactorySettings client_factory_settings_;
83 engine::TaskProcessor& channel_task_processor_;
84 impl::MiddlewarePipelineCreator& middleware_pipeline_creator_;
85 ugrpc::impl::CompletionQueuePoolBase& completion_queues_;
86 ugrpc::impl::StatisticsStorage& client_statistics_storage_;
87 impl::ClientQosErrorsReporter client_qos_errors_reporter_;
88 const dynamic_config::Source config_source_;
89 testsuite::GrpcControl& testsuite_grpc_;
90};
91
92template <typename Client>
93Client ClientFactory::MakeClient(ClientSettings&& client_settings) {
94 return Client(MakeClientInternals(std::move(client_settings), Client::GetMetadata(utils::impl::InternalTag{})));
95}
96
97template <typename Client>
98Client ClientFactory::MakeClient(const std::string& client_name, const std::string& endpoint) {
99 ClientSettings client_settings;
100 client_settings.client_name = client_name;
101 client_settings.endpoint = endpoint;
102 return MakeClient<Client>(std::move(client_settings));
103}
104
105} // namespace ugrpc::client
106
107USERVER_NAMESPACE_END