73 const std::optional<elt::mal::Mal::Properties> mal_properties = {}) {
75 std::lock_guard lck {m_mutex};
80 LOG4CPLUS_DEBUG(m_logger,
"SetConnectionInfo will close old client");
87 m_client = elt::mal::CiiFactory::getInstance().getClient<INTERFACE_TYPE>(
88 uri, elt::mal::rr::qos::QoS::DEFAULT,
89 mal_properties ? *mal_properties : elt::mal::Mal::Properties());
91 LOG4CPLUS_DEBUG(m_logger,
"Created rr client for " << uri);
97 m_client->registerConnectionListener([
this, uri](
bool connected) {
98 m_connected.store(connected);
99 LOG4CPLUS_DEBUG(m_logger,
"Connected with " << uri <<
": " << connected);
101 }
catch (
const std::exception& ex) {
104 LOG4CPLUS_WARN(m_logger,
"Failed to create rr client for " << uri <<
": " << ex.what());
135 bool Connect(std::chrono::seconds conn_timeout) {
136 std::lock_guard lck {m_mutex};
138 LOG4CPLUS_DEBUG(m_logger,
"Requestor::Connect() failed because of missing MAL client.");
142 LOG4CPLUS_DEBUG(m_logger,
"Requestor::Connect() skipped because it is already connected.");
146 elt::mal::future<void> conn_future = {};
148 conn_future = m_client->asyncConnect();
149 }
catch (
const elt::mal::MalException & ex) {
152 LOG4CPLUS_WARN(m_logger,
"Requestor::Connect() ClientAsync::asyncConnect call failed: " << ex.what());
156 ::boost::chrono::seconds conn_timeout_cii{conn_timeout.count()};
157 LOG4CPLUS_TRACE(m_logger,
"Requestor::Connect() called asyncConnect() and will wait max " << conn_timeout_cii.count() <<
" s.");
158 bool success =
false;
160 auto future_status = conn_future.wait_for(conn_timeout_cii);
161 success = (future_status == boost::future_status::ready);
162 LOG4CPLUS_TRACE(m_logger,
"Requestor::Connect() returned from waiting for connection, success=" << success);
163 }
catch (std::exception& ex) {
164 LOG4CPLUS_INFO(m_logger,
"Failed to wait for connection: " << ex.what());
166 LOG4CPLUS_INFO(m_logger,
"Failed to wait for connection. Non-std ex.");
168 m_connected = success;