From 907ad76c2db1ae834ea8d09a0aca86da008c261f Mon Sep 17 00:00:00 2001 From: David Reiss Date: Sun, 2 Mar 2008 00:25:58 +0000 Subject: [PATCH] Adding a few integration points to the C++ TSocketPool. - Adding ability to use a vector of TSocketPoolServers to construct a TSocketPool - Ability to get back the list of TSocketPoolServers This is especially useful in multithreaded client code that will just keep around the list of servers, and create the pool on every request. Since TSocketPool updates the failure stuff, we need a way to get back the updated TSocketPoolServers Reviewed By: aditya Test Plan: just compiling the code git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665537 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/transport/TSocketPool.cpp | 16 +++++++++++++++- lib/cpp/src/transport/TSocketPool.h | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/cpp/src/transport/TSocketPool.cpp b/lib/cpp/src/transport/TSocketPool.cpp index 63980526..d1d5bcdc 100644 --- a/lib/cpp/src/transport/TSocketPool.cpp +++ b/lib/cpp/src/transport/TSocketPool.cpp @@ -57,7 +57,7 @@ TSocketPool::TSocketPool(const vector &hosts, } } -TSocketPool::TSocketPool(const vector > servers) : TSocket(), +TSocketPool::TSocketPool(const std::vector >& servers) : TSocket(), numRetries_(1), retryInterval_(60), maxConsecutiveFailures_(1), @@ -69,6 +69,16 @@ TSocketPool::TSocketPool(const vector > servers) : TSocket(), } } +TSocketPool::TSocketPool(const std::vector& servers) : TSocket(), + servers_(servers), + numRetries_(1), + retryInterval_(60), + maxConsecutiveFailures_(1), + randomize_(true), + alwaysTryLast_(true) +{ +} + TSocketPool::TSocketPool(const string& host, int port) : TSocket(), numRetries_(1), retryInterval_(60), @@ -87,6 +97,10 @@ void TSocketPool::addServer(const string& host, int port) { servers_.push_back(TSocketPoolServer(host, port)); } +std::vector TSocketPool::getServers() { + return servers_; +} + void TSocketPool::setNumRetries(int numRetries) { numRetries_ = numRetries; } diff --git a/lib/cpp/src/transport/TSocketPool.h b/lib/cpp/src/transport/TSocketPool.h index bed4cca0..2d0496bb 100644 --- a/lib/cpp/src/transport/TSocketPool.h +++ b/lib/cpp/src/transport/TSocketPool.h @@ -65,7 +65,14 @@ class TSocketPool : public TSocket { * * @param servers list of pairs of host name and port */ - TSocketPool(const std::vector > servers); + TSocketPool(const std::vector >& servers); + + /** + * Socket pool constructor + * + * @param servers list of TSocketPoolServers + */ + TSocketPool(const std::vector& servers); /** * Socket pool constructor @@ -85,6 +92,12 @@ class TSocketPool : public TSocket { */ void addServer(const std::string& host, int port); + + /** + * Get list of servers in this pool + */ + std::vector getServers(); + /** * Sets how many times to keep retrying a host in the connect function. */ -- 2.17.1