28 #ifndef AsyncComm_ConnectionManager_h
29 #define AsyncComm_ConnectionManager_h
40 #include <condition_variable>
45 #include <unordered_map>
90 std::condition_variable
cond;
103 const ConnectionStatePtr &cs2)
const {
135 std::priority_queue<ConnectionStatePtr, std::vector<ConnectionStatePtr>,
154 m_impl = std::make_shared<SharedImpl>();
156 m_impl->quiet_mode =
false;
183 const char *service_name);
239 const char *service_name,
261 uint32_t timeout_ms,
const char *service_name);
284 uint32_t timeout_ms,
const char *service_name,
365 uint32_t timeout_ms,
const char *service_name,
403 void schedule_retry(ConnectionStatePtr &conn_state,
const std::string &message);
415 #endif // AsyncComm_ConnectionManager_h
static Comm * instance()
Creates/returns singleton instance of the Comm class.
void add(const CommAddress &addr, uint32_t timeout_ms, const char *service_name)
Adds a connection.
SharedImplPtr m_impl
Smart pointer to connection manager state.
uint32_t timeout_ms
Retry connection attempt after this many milliseconds.
std::mutex mutex
Mutex to serialize concurrent access.
std::unordered_map< String, ConnectionStatePtr > conn_map_proxy
Proxy-to-ConnectionState map.
void add_internal(const CommAddress &addr, const CommAddress &local_addr, uint32_t timeout_ms, const char *service_name, DispatchHandlerPtr &handler, ConnectionInitializerPtr &initializer)
Called by the add methods to add a connection.
void add_with_initializer(const CommAddress &addr, uint32_t timeout_ms, const char *service_name, DispatchHandlerPtr &handler, ConnectionInitializerPtr &initializer)
Adds a connection with a dispatch handler and connection initializer.
StringWeakOrdering for connection retry heap.
std::shared_ptr< ConnectionState > ConnectionStatePtr
Smart pointer to ConnectionState.
void schedule_retry(ConnectionStatePtr &conn_state, const std::string &message)
Schedules a connection retry attempt.
ConnectionManager(Comm *comm=0)
Constructor.
Establishes and maintains a set of TCP connections.
std::condition_variable retry_cond
Condition variable to signal if anything is on the retry heap.
Abstract base class for application dispatch handlers registered with AsyncComm.
CommAddress local_addr
Local address to bind to.
Declarations for CommAddress.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Declarations for ConnectionInitializer.
void connect_retry_loop()
Connect retry loop.
std::thread thread
Pointer to connection manager thread object.
bool shutdown
Set to true to signal shutdown in progress.
bool quiet_mode
Set to true to prevent connect failure log message.
std::mutex mutex
Mutex to serialize concurrent access.
virtual void handle(EventPtr &event)
Primary dispatch handler method.
Declarations for DispatchHandler.
std::condition_variable cond
Condition variable used to signal connection state change.
Comm * comm
Pointer to Comm layer.
std::chrono::steady_clock::time_point next_retry
Absolute time of next connect attempt.
Encapsulate an internet address.
A timer class to keep timeout states across AsyncComm related calls.
ConnectionInitializerPtr initializer
Connection initializer.
State state
Connection state.
std::shared_ptr< SharedImpl > SharedImplPtr
Smart pointer to SharedImpl object.
Connection manager state shared between Connection manager objects.
std::string service_name
Service name of connection for log messages.
SockAddrMap< ConnectionStatePtr > conn_map
InetAddr-to-ConnectionState map.
Declarations for SockAddrMap.
CommAddress addr
Connection address supplied to the add methods.
bool wait_for_connection(const CommAddress &addr, uint32_t max_wait_ms)
Blocks until the connection to the given address is established.
bool operator()(const ConnectionStatePtr &cs1, const ConnectionStatePtr &cs2) const
Entry point to AsyncComm service.
InetAddr inet_addr
Address initialized from Event object.
DispatchHandlerPtr handler
Registered connection handler.
A timer class to keep timeout states across AsyncComm related calls.
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
void send_initialization_request(ConnectionStatePtr &conn_state)
Sends an initialization request.
void set_quiet_mode(bool mode)
Sets the SharedImpl::quiet_mode flag which will disable the generation of log messages upon failed co...
void send_connect_request(ConnectionStatePtr &conn_state)
Calls Comm::connect to establish a connection.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
std::shared_ptr< ConnectionInitializer > ConnectionInitializerPtr
Smart pointer to ConnectionInitializer.
Comm * get_comm()
Returns the Comm object associated with this connection manager.
std::priority_queue< ConnectionStatePtr, std::vector< ConnectionStatePtr >, LtConnectionState > retry_queue
Connect retry heap.
bool operator>(const directory< _Key, _Tp, _Compare, _Allocator > &__x, const directory< _Key, _Tp, _Compare, _Allocator > &__y)
Address abstraction to hold either proxy name or IPv4:port address.
virtual ~ConnectionManager()
Destructor.