SON conn. pool
This commit is contained in:
parent
94092093f8
commit
6bc8a10c67
2 changed files with 31 additions and 1 deletions
|
|
@ -289,6 +289,17 @@ rpc_client::rpc_client(const std::vector<std::string> &_urls, const std::vector<
|
||||||
for (size_t i=0; i < _urls.size(); i++)
|
for (size_t i=0; i < _urls.size(); i++)
|
||||||
connections.push_back(new rpc_connection(_urls[i], _users[i], _passwords[i], _debug_rpc_calls));
|
connections.push_back(new rpc_connection(_urls[i], _users[i], _passwords[i], _debug_rpc_calls));
|
||||||
n_active_conn = 0;
|
n_active_conn = 0;
|
||||||
|
schedule_connection_selection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void rpc_client::schedule_connection_selection()
|
||||||
|
{
|
||||||
|
fc::time_point now = fc::time_point::now();
|
||||||
|
static const int64_t time_to_next_conn_selection = 2000000;
|
||||||
|
fc::time_point next_wakeup = now + fc::microseconds(time_to_next_conn_selection);
|
||||||
|
connection_selection_task = fc::schedule([this] {
|
||||||
|
reselect_connection();
|
||||||
|
}, next_wakeup, "SON RPC connection selection");
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_client::reselect_connection()
|
void rpc_client::reselect_connection()
|
||||||
|
|
@ -337,6 +348,8 @@ void rpc_client::reselect_connection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
schedule_connection_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
rpc_connection &rpc_client::get_active_connection() const
|
rpc_connection &rpc_client::get_active_connection() const
|
||||||
|
|
@ -349,4 +362,16 @@ std::string rpc_client::send_post_request(std::string method, std::string params
|
||||||
return get_active_connection().send_post_request(method, params, show_log);
|
return get_active_connection().send_post_request(method, params, show_log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpc_client::~rpc_client()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (connection_selection_task.valid())
|
||||||
|
connection_selection_task.cancel_and_wait(__FUNCTION__);
|
||||||
|
} catch (fc::canceled_exception &) {
|
||||||
|
//Expected exception. Move along.
|
||||||
|
} catch (fc::exception &e) {
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace graphene::peerplays_sidechain
|
}} // namespace graphene::peerplays_sidechain
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,20 @@ class rpc_connection;
|
||||||
class rpc_client {
|
class rpc_client {
|
||||||
public:
|
public:
|
||||||
rpc_client(const std::vector<std::string> &_urls, const std::vector<std::string> &_users, const std::vector<std::string> &_passwords, bool _debug_rpc_calls);
|
rpc_client(const std::vector<std::string> &_urls, const std::vector<std::string> &_users, const std::vector<std::string> &_passwords, bool _debug_rpc_calls);
|
||||||
|
~rpc_client();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string send_post_request(std::string method, std::string params, bool show_log);
|
std::string send_post_request(std::string method, std::string params, bool show_log);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<rpc_connection*> connections;
|
std::vector<rpc_connection*> connections;
|
||||||
int n_active_conn;
|
int n_active_conn;
|
||||||
|
fc::future<void> connection_selection_task;
|
||||||
|
|
||||||
rpc_connection &get_active_connection() const;
|
rpc_connection &get_active_connection() const;
|
||||||
|
|
||||||
|
void select_connection();
|
||||||
|
void schedule_connection_selection();
|
||||||
virtual uint64_t ping(rpc_connection &conn) const = 0;
|
virtual uint64_t ping(rpc_connection &conn) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue