| 109 | } |
| 110 | |
| 111 | Status ClientCacheHelper::CreateClient(const TNetworkAddress& address, |
| 112 | const ClientFactory& factory_method, ClientKey* client_key) { |
| 113 | shared_ptr<ThriftClientImpl> client_impl(factory_method(address, client_key)); |
| 114 | VLOG(2) << "CreateClient(): creating new client for " << |
| 115 | TNetworkAddressToString(client_impl->address()); |
| 116 | |
| 117 | if (!client_impl->init_status().ok()) { |
| 118 | *client_key = nullptr; |
| 119 | return client_impl->init_status(); |
| 120 | } |
| 121 | |
| 122 | // Set the TSocket's send, receive and connect timeouts. |
| 123 | client_impl->setRecvTimeout(recv_timeout_ms_); |
| 124 | client_impl->setSendTimeout(send_timeout_ms_); |
| 125 | client_impl->setConnTimeout(conn_timeout_ms_); |
| 126 | |
| 127 | Status status = client_impl->OpenWithRetry(num_tries_, wait_ms_); |
| 128 | if (!status.ok()) { |
| 129 | *client_key = nullptr; |
| 130 | return status; |
| 131 | } |
| 132 | |
| 133 | // Because the client starts life 'checked out', we don't add it to its host cache. |
| 134 | { |
| 135 | lock_guard<mutex> lock(client_map_lock_); |
| 136 | client_map_[*client_key] = client_impl; |
| 137 | } |
| 138 | |
| 139 | if (metrics_enabled_) total_clients_metric_->Increment(1); |
| 140 | return Status::OK(); |
| 141 | } |
| 142 | |
| 143 | void ClientCacheHelper::ReleaseClient(ClientKey* client_key) { |
| 144 | DCHECK(*client_key != NULL) << "Trying to release NULL client"; |
nothing calls this directly
no test coverage detected