cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
|
Class to establish connections for clients. More...
#include <msgpack_rpc/clients/impl/client_connector.h>
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::IConnection > | connection () |
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::IConnection > | connection_ {} |
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::Logger > | logger_ |
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::URI > | server_uris_ |
URIs of servers. |
Class to establish connections for clients.
Definition at line 45 of file client_connector.h.
using msgpack_rpc::clients::impl::ClientConnector::ConnectionCallback = std::function<void()> |
Type of callback functions called when a connection is established.
Definition at line 48 of file client_connector.h.
using msgpack_rpc::clients::impl::ClientConnector::ConnectionClosedCallback = std::function<void()> |
Type of callback functions called when a connection is closed.
Definition at line 58 of file client_connector.h.
Type of callback functions called when a message is received.
Parameters:
Definition at line 51 of file client_connector.h.
using msgpack_rpc::clients::impl::ClientConnector::MessageSentCallback = transport::IConnection::MessageSentCallback |
Type of callback functions called when a message is successfully sent.
Definition at line 55 of file client_connector.h.
|
inline |
Constructor.
[in] | executor | Executor. |
[in] | backends | Backends. |
[in] | server_uris | URIs of servers. |
[in] | reconnection_config | Configuration of reconnection. |
[in] | logger | Logger. |
Definition at line 69 of file client_connector.h.
|
inlineprivate |
Asynchronously connect to a server.
Definition at line 131 of file client_connector.h.
|
inlinenodiscard |
Get the connection.
Definition at line 122 of file client_connector.h.
|
inlineprivate |
Handle connection established.
[in] | connection | Connection. |
Definition at line 148 of file client_connector.h.
|
inlineprivate |
Handle connection closed.
Definition at line 182 of file client_connector.h.
|
inlineprivate |
Handle failure to connect.
Definition at line 171 of file client_connector.h.
|
inline |
Start processing.
[in] | on_connection | Callback function called when a connection is established. |
[in] | on_received | Callback function called when a message is received. |
[in] | on_sent | Callback function called when a message is sent. |
[in] | on_closed | Callback function called when a connection is closed. |
Definition at line 90 of file client_connector.h.
|
inline |
Stop processing.
Definition at line 103 of file client_connector.h.
|
private |
Backends.
Definition at line 195 of file client_connector.h.
|
private |
Connection.
Definition at line 201 of file client_connector.h.
|
private |
Mutex of connection_ and is_connecting_.
Definition at line 204 of file client_connector.h.
|
private |
Whether this connector is stopped.
Definition at line 207 of file client_connector.h.
|
private |
Logger.
Definition at line 225 of file client_connector.h.
|
private |
Callback function called when a connection is closed.
Definition at line 222 of file client_connector.h.
|
private |
Callback function called when a connection is established.
Definition at line 213 of file client_connector.h.
|
private |
Callback function called when a message is received.
Definition at line 216 of file client_connector.h.
|
private |
Callback function called when a message is sent.
Definition at line 219 of file client_connector.h.
|
private |
Timer to sleep until next retry.
Definition at line 210 of file client_connector.h.
|
private |
URIs of servers.
Definition at line 198 of file client_connector.h.