From 82cb5b781573bbdd314bae51694ffada3312b5da Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Fri, 7 Nov 2008 14:08:29 +0000 Subject: * Added some doxygen comments for FailoverManager * Added means for application to alter the order in which urls are tried (or indeed the list of urls to try) git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@712127 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/FailoverManager.cpp | 10 ++++-- cpp/src/qpid/client/FailoverManager.h | 59 +++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/qpid/client/FailoverManager.cpp b/cpp/src/qpid/client/FailoverManager.cpp index 73c6bfc2de..ab9dbca70f 100644 --- a/cpp/src/qpid/client/FailoverManager.cpp +++ b/cpp/src/qpid/client/FailoverManager.cpp @@ -28,7 +28,8 @@ namespace client { using qpid::sys::Monitor; -FailoverManager::FailoverManager(const ConnectionSettings& s) : settings(s), state(IDLE) {} +FailoverManager::FailoverManager(const ConnectionSettings& s, + ReconnectionStrategy* rs) : settings(s), strategy(rs), state(IDLE) {} void FailoverManager::execute(Command& c) { @@ -38,11 +39,11 @@ void FailoverManager::execute(Command& c) try { AsyncSession session = connect().newSession(); c.execute(session, retry); - session.sync();//TODO: shouldn't be required, but seems there is a bug in session + session.sync();//TODO: shouldn't be required session.close(); completed = true; } catch(const TransportFailure&) { - retry = true; + retry = true; } } } @@ -86,6 +87,7 @@ Connection& FailoverManager::getConnection() void FailoverManager::attempt(Connection& c, ConnectionSettings s, std::vector urls) { Monitor::ScopedUnlock u(lock); + if (strategy) strategy->editUrlList(urls); if (urls.empty()) { attempt(c, s); } else { @@ -105,7 +107,9 @@ void FailoverManager::attempt(Connection& c, ConnectionSettings s, std::vector& urls) = 0; + virtual ~ReconnectionStrategy() {} + }; + + /** + * Create a manager to control failover for a logical connection. + * + * @param settings the initial connection settings + * @param strategy optional stratgey callback allowing application + * to edit or reorder the list of urls to which reconnection is + * attempted + */ + FailoverManager(const ConnectionSettings& settings, ReconnectionStrategy* strategy = 0); + /** + * Return the current connection if open or attept to reconnect to + * the specified list of urls. If no list is specified the list of + * known brokers from the last connection will be used. If no list + * is specified and this is the first connect attempt, the host + * and port from the initial settings will be used. + */ Connection& connect(std::vector brokers = std::vector()); + /** + * Return the current connection whether open or not + */ Connection& getConnection(); + /** + * Close the current connection + */ void close(); + /** + * Reliably execute the specified command. This involves creating + * a session on which to carry out the work of the command, + * handling failover occuring while exeuting that command and + * re-starting the work. + */ void execute(Command&); private: enum State {IDLE, CONNECTING, CANT_CONNECT}; @@ -60,6 +114,7 @@ class FailoverManager qpid::sys::Monitor lock; Connection connection; ConnectionSettings settings; + ReconnectionStrategy* strategy; State state; void attempt(Connection&, ConnectionSettings settings, std::vector urls); -- cgit v1.2.1