71 std::vector<addresses::URI> server_uris,
73 const std::shared_ptr<logging::Logger>& logger)
104 if (
is_stopped_.exchange(
true, std::memory_order_acquire)) {
122 [[nodiscard]] std::shared_ptr<transport::IConnection>
connection() {
133 [self = this->shared_from_this()](
const Status& status,
134 const std::shared_ptr<transport::IConnection>&
connection) {
135 if (status.
code() == StatusCode::SUCCESS) {
138 self->on_connection_failure();
149 const std::shared_ptr<transport::IConnection>&
connection) {
156 [weak_self = weak_from_this()](
const Status& ) {
157 const auto self = weak_self.lock();
159 self->on_connection_closed();
176 [self = this->shared_from_this()] { self->async_connect(); });
Definition of async_connect function.
Definition of BackendList class.
ClientConnector(const std::shared_ptr< executors::IExecutor > &executor, transport::BackendList backends, std::vector< addresses::URI > server_uris, const config::ReconnectionConfig &reconnection_config, const std::shared_ptr< logging::Logger > &logger)
Constructor.
void on_connection(const std::shared_ptr< transport::IConnection > &connection)
Handle connection established.
std::function< void()> ConnectionCallback
Type of callback functions called when a connection is established.
transport::IConnection::MessageSentCallback MessageSentCallback
Type of callback functions called when a message is successfully sent.
std::mutex connection_mutex_
Mutex of connection_ and is_connecting_.
ConnectionCallback on_connection_
Callback function called when a connection is established.
void on_connection_closed()
Handle connection closed.
std::shared_ptr< transport::IConnection > connection_
Connection.
void on_connection_failure()
Handle failure to connect.
std::atomic< bool > is_stopped_
Whether this connector is stopped.
transport::BackendList backends_
Backends.
void async_connect()
Asynchronously connect to a server.
std::function< void()> ConnectionClosedCallback
Type of callback functions called when a connection is closed.
transport::IConnection::MessageReceivedCallback MessageReceivedCallback
Type of callback functions called when a message is received.
ConnectionClosedCallback on_closed_
Callback function called when a connection is closed.
MessageReceivedCallback on_received_
Callback function called when a message is received.
MessageSentCallback on_sent_
Callback function called when a message is sent.
void stop()
Stop processing.
std::shared_ptr< logging::Logger > logger_
Logger.
void start(ConnectionCallback on_connection, MessageReceivedCallback on_received, MessageSentCallback on_sent, ConnectionClosedCallback on_closed)
Start processing.
std::vector< addresses::URI > server_uris_
URIs of servers.
std::shared_ptr< transport::IConnection > connection()
Get the connection.
ReconnectionTimer retry_timer_
Timer to sleep until next retry.
Class of timer to sleep before reconnecting.
StatusCode code() const noexcept
Get the status code.
Class of configurations of reconnection.
Class of lists of backends of protocols.
std::function< void(messages::ParsedMessage)> MessageReceivedCallback
Type of callback functions called when a message is received.
std::function< void()> MessageSentCallback
Type of callback functions called when a message is successfully sent.
Definition of IConnection class.
Definition of IExecutor class.
Definition of Logger class.
#define MSGPACK_RPC_TRACE(LOGGER_PTR,...)
Write a trace log.
Namespace of internal implementations.
void async_connect(const BackendList &backends, const std::vector< addresses::URI > &uris, std::function< void(const Status &, std::shared_ptr< IConnection >)> on_connection)
Asynchronously connect to an endpoint.
Definition of ReconnectionConfig class.
Class of ReconnectionTimer class.
Definition of Status class.
Definition of StatusCode enumeration.