cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
client_builder_impl.h
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <memory>
23
#include <utility>
24
25
#include "
msgpack_rpc/addresses/uri.h
"
26
#include "
msgpack_rpc/clients/impl/call_list.h
"
27
#include "
msgpack_rpc/clients/impl/client_connector.h
"
28
#include "
msgpack_rpc/clients/impl/client_impl.h
"
29
#include "
msgpack_rpc/clients/impl/i_client_builder_impl.h
"
30
#include "
msgpack_rpc/clients/impl/i_client_impl.h
"
31
#include "
msgpack_rpc/config/client_config.h
"
32
#include "
msgpack_rpc/executors/i_async_executor.h
"
33
#include "
msgpack_rpc/logging/logger.h
"
34
#include "
msgpack_rpc/transport/backend_list.h
"
35
#include "
msgpack_rpc/transport/i_backend.h
"
36
37
namespace
msgpack_rpc::clients::impl
{
38
42
class
ClientBuilderImpl
final :
public
IClientBuilderImpl {
43
public
:
52
ClientBuilderImpl
(std::shared_ptr<executors::IAsyncExecutor> executor,
53
std::shared_ptr<logging::Logger> logger,
config::ClientConfig
config
,
54
transport::BackendList
backends)
55
:
executor_
(
std
::move(executor)),
56
logger_
(
std
::move(logger)),
57
config_
(
std
::move(
config
)),
58
backends_
(
std
::move(backends)) {}
59
61
void
register_protocol
(
62
std::shared_ptr<transport::IBackend> backend)
override
{
63
backends_
.
append
(backend);
64
}
65
67
void
connect_to
(
addresses::URI
uri)
override
{
68
config_
.
add_uri
(std::move(uri));
69
}
70
72
[[nodiscard]] std::shared_ptr<clients::impl::IClientImpl>
build
()
override
{
73
const
auto
connector = std::make_shared<ClientConnector>(
executor_
,
74
backends_
,
config_
.
uris
(),
config_
.
reconnection
(),
logger_
);
75
76
const
auto
call_list = std::make_shared<CallList>(
77
config_
.
call_timeout
(),
executor_
,
logger_
);
78
79
auto
client = std::make_shared<ClientImpl>(
80
connector, call_list,
executor_
,
logger_
);
81
client->start();
82
83
return
client;
84
}
85
86
private
:
88
std::shared_ptr<executors::IAsyncExecutor>
executor_
;
89
91
std::shared_ptr<logging::Logger>
logger_
;
92
94
config::ClientConfig
config_
;
95
97
transport::BackendList
backends_
;
98
};
99
100
}
// namespace msgpack_rpc::clients::impl
backend_list.h
Definition of BackendList class.
call_list.h
Definition of CallList class.
msgpack_rpc::addresses::URI
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition
uri.h:38
msgpack_rpc::clients::impl::ClientBuilderImpl::ClientBuilderImpl
ClientBuilderImpl(std::shared_ptr< executors::IAsyncExecutor > executor, std::shared_ptr< logging::Logger > logger, config::ClientConfig config, transport::BackendList backends)
Constructor.
Definition
client_builder_impl.h:52
msgpack_rpc::clients::impl::ClientBuilderImpl::logger_
std::shared_ptr< logging::Logger > logger_
Logger.
Definition
client_builder_impl.h:91
msgpack_rpc::clients::impl::ClientBuilderImpl::backends_
transport::BackendList backends_
Backends.
Definition
client_builder_impl.h:97
msgpack_rpc::clients::impl::ClientBuilderImpl::connect_to
void connect_to(addresses::URI uri) override
Add a URI to connect to.
Definition
client_builder_impl.h:67
msgpack_rpc::clients::impl::ClientBuilderImpl::executor_
std::shared_ptr< executors::IAsyncExecutor > executor_
Executor.
Definition
client_builder_impl.h:88
msgpack_rpc::clients::impl::ClientBuilderImpl::config_
config::ClientConfig config_
Configuration.
Definition
client_builder_impl.h:94
msgpack_rpc::clients::impl::ClientBuilderImpl::register_protocol
void register_protocol(std::shared_ptr< transport::IBackend > backend) override
Register a protocol.
Definition
client_builder_impl.h:61
msgpack_rpc::clients::impl::ClientBuilderImpl::build
std::shared_ptr< clients::impl::IClientImpl > build() override
Build a client.
Definition
client_builder_impl.h:72
msgpack_rpc::config::ClientConfig
Class of configuration of clients.
Definition
client_config.h:38
msgpack_rpc::config::ClientConfig::reconnection
ReconnectionConfig & reconnection() noexcept
Get the configuration of reconnection.
Definition
client_config.cpp:81
msgpack_rpc::config::ClientConfig::call_timeout
ClientConfig & call_timeout(std::chrono::nanoseconds value)
Set the duration of timeout of RPCs.
Definition
client_config.cpp:54
msgpack_rpc::config::ClientConfig::uris
const std::vector< addresses::URI > & uris() const noexcept
Get the URIs of the server.
Definition
client_config.cpp:50
msgpack_rpc::config::ClientConfig::add_uri
ClientConfig & add_uri(addresses::URI uri)
Add a URI of the server.
Definition
client_config.cpp:41
msgpack_rpc::transport::BackendList
Class of lists of backends of protocols.
Definition
backend_list.h:39
msgpack_rpc::transport::BackendList::append
void append(std::shared_ptr< transport::IBackend > backend)
Add a backend of the protocol.
Definition
backend_list.h:51
client_config.h
Definition of ClientConfig class.
client_connector.h
Definition of ClientConnector class.
client_impl.h
Definition of ClientImpl class.
i_async_executor.h
Definition of IAsyncExecutor class.
i_backend.h
Definition of IBackend class.
i_client_builder_impl.h
Definition of IClientBuilderImpl class.
i_client_impl.h
Definition of IClientImpl class.
logger.h
Definition of Logger class.
msgpack_rpc::clients::impl
Namespace of internal implementations.
Definition
i_call_future_impl.h:26
msgpack_rpc::config
Namespace of configurations.
Definition
client_config.h:32
std
STL namespace.
uri.h
Definition of URI class.
src
msgpack_rpc
clients
impl
client_builder_impl.h
Generated on
for cpp-msgpack-rpc by
1.18.0