cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
msgpack_rpc::clients::impl::ClientConnector Class Reference

Class to establish connections for clients. More...

#include <msgpack_rpc/clients/impl/client_connector.h>

Inheritance diagram for msgpack_rpc::clients::impl::ClientConnector:
Collaboration diagram for msgpack_rpc::clients::impl::ClientConnector:

Public Types

using ConnectionCallback = std::function<void()>
 Type of callback functions called when a connection is established.
using ConnectionClosedCallback = std::function<void()>
 Type of callback functions called when a connection is closed.
using MessageReceivedCallback
 Type of callback functions called when a message is received.
using MessageSentCallback = transport::IConnection::MessageSentCallback
 Type of callback functions called when a message is successfully sent.

Public Member Functions

 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.
std::shared_ptr< transport::IConnectionconnection ()
 Get the connection.
void start (ConnectionCallback on_connection, MessageReceivedCallback on_received, MessageSentCallback on_sent, ConnectionClosedCallback on_closed)
 Start processing.
void stop ()
 Stop processing.

Private Member Functions

void async_connect ()
 Asynchronously connect to a server.
void on_connection (const std::shared_ptr< transport::IConnection > &connection)
 Handle connection established.
void on_connection_closed ()
 Handle connection closed.
void on_connection_failure ()
 Handle failure to connect.

Private Attributes

transport::BackendList backends_
 Backends.
std::shared_ptr< transport::IConnectionconnection_ {}
 Connection.
std::mutex connection_mutex_ {}
 Mutex of connection_ and is_connecting_.
std::atomic< bool > is_stopped_ {false}
 Whether this connector is stopped.
std::shared_ptr< logging::Loggerlogger_
 Logger.
ConnectionClosedCallback on_closed_ {}
 Callback function called when a connection is closed.
ConnectionCallback on_connection_ {}
 Callback function called when a connection is established.
MessageReceivedCallback on_received_ {}
 Callback function called when a message is received.
MessageSentCallback on_sent_ {}
 Callback function called when a message is sent.
ReconnectionTimer retry_timer_
 Timer to sleep until next retry.
std::vector< addresses::URIserver_uris_
 URIs of servers.

Detailed Description

Class to establish connections for clients.

Definition at line 45 of file client_connector.h.

Member Typedef Documentation

◆ ConnectionCallback

Type of callback functions called when a connection is established.

Definition at line 48 of file client_connector.h.

◆ ConnectionClosedCallback

Type of callback functions called when a connection is closed.

Definition at line 58 of file client_connector.h.

◆ MessageReceivedCallback

Initial value:
std::function< void(messages::ParsedMessage)> MessageReceivedCallback
Type of callback functions called when a message is received.

Type of callback functions called when a message is received.

Parameters:

  1. Received message.

Definition at line 51 of file client_connector.h.

◆ MessageSentCallback

Type of callback functions called when a message is successfully sent.

Definition at line 55 of file client_connector.h.

Constructor & Destructor Documentation

◆ ClientConnector()

msgpack_rpc::clients::impl::ClientConnector::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 )
inline

Constructor.

Parameters
[in]executorExecutor.
[in]backendsBackends.
[in]server_urisURIs of servers.
[in]reconnection_configConfiguration of reconnection.
[in]loggerLogger.

Definition at line 69 of file client_connector.h.

Member Function Documentation

◆ async_connect()

void msgpack_rpc::clients::impl::ClientConnector::async_connect ( )
inlineprivate

Asynchronously connect to a server.

Definition at line 131 of file client_connector.h.

◆ connection()

std::shared_ptr< transport::IConnection > msgpack_rpc::clients::impl::ClientConnector::connection ( )
inlinenodiscard

Get the connection.

Returns
Connection. (Null if not connected.)

Definition at line 122 of file client_connector.h.

◆ on_connection()

void msgpack_rpc::clients::impl::ClientConnector::on_connection ( const std::shared_ptr< transport::IConnection > & connection)
inlineprivate

Handle connection established.

Parameters
[in]connectionConnection.

Definition at line 148 of file client_connector.h.

◆ on_connection_closed()

void msgpack_rpc::clients::impl::ClientConnector::on_connection_closed ( )
inlineprivate

Handle connection closed.

Definition at line 182 of file client_connector.h.

◆ on_connection_failure()

void msgpack_rpc::clients::impl::ClientConnector::on_connection_failure ( )
inlineprivate

Handle failure to connect.

Definition at line 171 of file client_connector.h.

◆ start()

void msgpack_rpc::clients::impl::ClientConnector::start ( ConnectionCallback on_connection,
MessageReceivedCallback on_received,
MessageSentCallback on_sent,
ConnectionClosedCallback on_closed )
inline

Start processing.

Parameters
[in]on_connectionCallback function called when a connection is established.
[in]on_receivedCallback function called when a message is received.
[in]on_sentCallback function called when a message is sent.
[in]on_closedCallback function called when a connection is closed.

Definition at line 90 of file client_connector.h.

◆ stop()

void msgpack_rpc::clients::impl::ClientConnector::stop ( )
inline

Stop processing.

Definition at line 103 of file client_connector.h.

Member Data Documentation

◆ backends_

transport::BackendList msgpack_rpc::clients::impl::ClientConnector::backends_
private

Backends.

Definition at line 195 of file client_connector.h.

◆ connection_

std::shared_ptr<transport::IConnection> msgpack_rpc::clients::impl::ClientConnector::connection_ {}
private

Connection.

Definition at line 201 of file client_connector.h.

◆ connection_mutex_

std::mutex msgpack_rpc::clients::impl::ClientConnector::connection_mutex_ {}
private

Mutex of connection_ and is_connecting_.

Definition at line 204 of file client_connector.h.

◆ is_stopped_

std::atomic<bool> msgpack_rpc::clients::impl::ClientConnector::is_stopped_ {false}
private

Whether this connector is stopped.

Definition at line 207 of file client_connector.h.

◆ logger_

std::shared_ptr<logging::Logger> msgpack_rpc::clients::impl::ClientConnector::logger_
private

Logger.

Definition at line 225 of file client_connector.h.

◆ on_closed_

ConnectionClosedCallback msgpack_rpc::clients::impl::ClientConnector::on_closed_ {}
private

Callback function called when a connection is closed.

Definition at line 222 of file client_connector.h.

◆ on_connection_

ConnectionCallback msgpack_rpc::clients::impl::ClientConnector::on_connection_ {}
private

Callback function called when a connection is established.

Definition at line 213 of file client_connector.h.

◆ on_received_

MessageReceivedCallback msgpack_rpc::clients::impl::ClientConnector::on_received_ {}
private

Callback function called when a message is received.

Definition at line 216 of file client_connector.h.

◆ on_sent_

MessageSentCallback msgpack_rpc::clients::impl::ClientConnector::on_sent_ {}
private

Callback function called when a message is sent.

Definition at line 219 of file client_connector.h.

◆ retry_timer_

ReconnectionTimer msgpack_rpc::clients::impl::ClientConnector::retry_timer_
private

Timer to sleep until next retry.

Definition at line 210 of file client_connector.h.

◆ server_uris_

std::vector<addresses::URI> msgpack_rpc::clients::impl::ClientConnector::server_uris_
private

URIs of servers.

Definition at line 198 of file client_connector.h.


The documentation for this class was generated from the following file: