21 , index_{_other.index_}
23 _other.pool_ =
nullptr;
24 _other.conn_ =
nullptr;
25 _other.index_ = uninitialized_index;
32 index_ = _other.index_;
34 _other.pool_ =
nullptr;
35 _other.conn_ =
nullptr;
36 _other.index_ = uninitialized_index;
41 connection_pool::connection_proxy::operator bool() const noexcept
43 return nullptr != conn_;
46 connection_pool::connection_proxy::operator
rcComm_t&()
const
49 throw std::runtime_error{
"Invalid connection object"};
55 connection_pool::connection_proxy::operator
rcComm_t*()
const noexcept
62 pool_->release_connection(index_);
78 const std::string& _host,
80 const std::string& _username,
81 const std::string& _zone,
82 const int _refresh_time)
85 , username_{_username}
87 , refresh_time_(_refresh_time)
91 throw std::runtime_error{
"invalid connection pool size"};
98 [] {
throw std::runtime_error{
"connect error"}; },
99 [] {
throw std::runtime_error{
"client login error"}; });
108 irods::thread_pool thread_pool{std::min<int>(_size, std::thread::hardware_concurrency())};
110 std::atomic<bool> connect_error{};
111 std::atomic<bool> login_error{};
113 for (
int i = 1; i < _size; ++i) {
115 if (connect_error.load() || login_error.load()) {
120 [&connect_error] { connect_error.store(
true); },
121 [&login_error] { login_error.store(
true); });
127 if (connect_error.load()) {
128 throw std::runtime_error{
"connect error"};
131 if (login_error.load()) {
132 throw std::runtime_error{
"client login error"};
137 std::function<
void()> _on_connect_error,
138 std::function<
void()> _on_login_error)
141 ctx.creation_time = std::time(
nullptr);
168 query<rcComm_t>{ctx.conn.get(),
"select ZONE_NAME where ZONE_TYPE = 'local'"};
169 if (std::time(
nullptr) - ctx.creation_time >
refresh_time_) {
173 catch (
const std::exception&) {
192 [] {
throw std::runtime_error{
"connect error"}; },
193 [] {
throw std::runtime_error{
"client login error"}; });
196 return ctx.conn.get();
201 for (
int i = 0;; i = ++i %
conn_ctxs_.size()) {
202 std::unique_lock<std::mutex>
lock{
conn_ctxs_[i].mutex, std::defer_lock};
204 if (
lock.try_lock()) {
227 return std::make_shared<irods::connection_pool>(
233 env.irodsConnectionPoolRefreshTime);