From b6eb88609aea82e676f33ae8ff68918b68b81d33 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 26 Oct 2009 20:11:08 +0000 Subject: Separate FailoverListener from client::Connection. client::ConnectionImpl used to contain a FailoverListener to subscribe for updates on the amq.failover exchange. This caused some lifecycle issues including memory leaks. Now FailoverListener is a public API class that the user must create associated with a session to get known-broker updates. Removed the weak_ptr logic in client::SessionImpl which was only required because of FailoverListener. Made SessionImpl::close() idempotent. Gets rid of spurious warning messages in some tests. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@829931 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp | 5 ++++- cpp/src/qpid/client/amqp0_10/ConnectionImpl.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'cpp/src/qpid/client/amqp0_10') diff --git a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp index 3a735b5698..1698f96caf 100644 --- a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp @@ -136,7 +136,9 @@ void ConnectionImpl::connect(const AbsTime& started) bool ConnectionImpl::tryConnect() { - if (tryConnect(url) || tryConnect(connection.getKnownBrokers())) { + if (tryConnect(url) || + (failoverListener.get() && tryConnect(failoverListener->getKnownBrokers()))) + { return resetSessions(); } else { return false; @@ -148,6 +150,7 @@ bool ConnectionImpl::tryConnect(const Url& u) try { QPID_LOG(info, "Trying to connect to " << url << "..."); connection.open(u, settings); + failoverListener.reset(new FailoverListener(connection)); return true; } catch (const Exception& e) { //TODO: need to fix timeout on open so that it throws TransportFailure diff --git a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h index 565f2ec7ec..f4bc09594d 100644 --- a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h +++ b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h @@ -25,6 +25,7 @@ #include "qpid/messaging/Variant.h" #include "qpid/Url.h" #include "qpid/client/Connection.h" +#include "qpid/client/FailoverListener.h" #include "qpid/client/ConnectionSettings.h" #include "qpid/sys/Mutex.h" #include "qpid/sys/Semaphore.h" @@ -50,6 +51,7 @@ class ConnectionImpl : public qpid::messaging::ConnectionImpl qpid::sys::Mutex lock;//used to protect data structures qpid::sys::Semaphore semaphore;//used to coordinate reconnection qpid::client::Connection connection; + std::auto_ptr failoverListener; qpid::Url url; qpid::client::ConnectionSettings settings; Sessions sessions; -- cgit v1.2.1