17 #include <boost/assign.hpp>
18 #include <boost/lexical_cast.hpp>
20 #include <thrift/Thrift.h>
21 #include <gutil/strings/substitute.h>
27 using namespace apache::thrift::transport;
28 using namespace apache::thrift;
29 using namespace strings;
36 if (!socket_create_status_.ok())
return socket_create_status_;
38 if (!transport_->isOpen()) {
41 }
catch (
const TException& e) {
42 return Status(Substitute(
"Couldn't open transport for $0 ($1)",
43 lexical_cast<string>(address_), e.what()));
48 Status ThriftClientImpl::OpenWithRetry(uint32_t num_tries,
uint64_t wait_ms) {
49 uint32_t try_count = 0L;
53 if (status.
ok())
return status;
55 LOG(INFO) <<
"Unable to connect to " << address_;
57 LOG(INFO) <<
"(Attempt " << try_count <<
", will retry indefinitely)";
61 LOG(INFO) <<
"(Attempt " << try_count <<
" of " << num_tries <<
")";
63 if (try_count == num_tries)
return status;
69 void ThriftClientImpl::Close() {
71 if (transport_.get() != NULL && transport_->isOpen()) transport_->close();
72 }
catch (
const TException& e) {
73 LOG(INFO) <<
"Error closing connection to: " << address_ <<
", ignoring (" << e.what()
78 if (socket_.get() != NULL) socket_->close();
79 }
catch (
const TException& e) {
80 LOG(INFO) <<
"Error closing socket to: " << address_ <<
", ignoring (" << e.what()
86 Status ThriftClientImpl::CreateSocket() {
88 socket_.reset(
new TSocket(address_.hostname, address_.port));
91 TSSLSocketFactory factory;
95 factory.loadTrustedCertificates(FLAGS_ssl_client_ca_certificate.c_str());
96 socket_ = factory.createSocket(address_.hostname, address_.port);
97 }
catch (
const TException& e) {
98 return Status(Substitute(
"Failed to create socket: $0", e.what()));
void SleepForMs(const int64_t duration_ms)
Sleeps the current thread for at least duration_ms milliseconds.
DECLARE_string(ssl_client_ca_certificate)