diff options
author | Ted Ross <tross@apache.org> | 2008-11-06 17:06:21 +0000 |
---|---|---|
committer | Ted Ross <tross@apache.org> | 2008-11-06 17:06:21 +0000 |
commit | d8cda3197b53140ce4c8d0a0141e3962eb37a391 (patch) | |
tree | 90883e7a59dd327a96eaccc896bd14eb45bc22e8 /qpid/cpp | |
parent | 67b8d04434e1f2893130ac3532316c9b84530593 (diff) | |
download | qpid-python-d8cda3197b53140ce4c8d0a0141e3962eb37a391.tar.gz |
QPID-1437 - Fixed qmf agent shutdown
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@711913 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r-- | qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp | 45 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/agent/ManagementAgentImpl.h | 11 |
2 files changed, 49 insertions, 7 deletions
diff --git a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp index 1c737155a7..257d6f6999 100644 --- a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp +++ b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp @@ -87,6 +87,17 @@ ManagementAgentImpl::ManagementAgentImpl() : // TODO: Establish system ID } +ManagementAgentImpl::~ManagementAgentImpl() +{ + connThreadBody.close(); + + // If the thread is doing work on the connection, we must wait for it to + // complete before shutting down. + if (!connThreadBody.isSleeping()) { + connThread.join(); + } +} + void ManagementAgentImpl::init(string brokerHost, uint16_t brokerPort, uint16_t intervalSeconds, @@ -725,21 +736,31 @@ void ManagementAgentImpl::ConnectionThread::run() delete subscriptions; subscriptions = 0; session.close(); + connection.close(); } } catch (std::exception &e) { if (delay < delayMax) delay *= delayFactor; } - ::sleep(delay); + { + Mutex::ScopedLock _lock(connLock); + if (shutdown) + return; + sleeping = true; + { + Mutex::ScopedUnlock _unlock(connLock); + ::sleep(delay); + } + sleeping = false; + if (shutdown) + return; + } } } ManagementAgentImpl::ConnectionThread::~ConnectionThread() { - if (subscriptions != 0) { - delete subscriptions; - } } void ManagementAgentImpl::ConnectionThread::sendBuffer(Buffer& buf, @@ -773,6 +794,22 @@ void ManagementAgentImpl::ConnectionThread::bindToBank(uint32_t brokerBank, uint arg::bindingKey=key.str()); } +void ManagementAgentImpl::ConnectionThread::close() +{ + { + Mutex::ScopedLock _lock(connLock); + shutdown = true; + } + if (subscriptions) + subscriptions->stop(); +} + +bool ManagementAgentImpl::ConnectionThread::isSleeping() const +{ + Mutex::ScopedLock _lock(connLock); + return sleeping; +} + void ManagementAgentImpl::PublishThread::run() { diff --git a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h index d8ede8a80d..28fbb72f6f 100644 --- a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h +++ b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h @@ -43,7 +43,7 @@ class ManagementAgentImpl : public ManagementAgent, public client::MessageListen public: ManagementAgentImpl(); - virtual ~ManagementAgentImpl() {}; + virtual ~ManagementAgentImpl(); // // Methods from ManagementAgent @@ -156,17 +156,22 @@ class ManagementAgentImpl : public ManagementAgent, public client::MessageListen client::Session session; client::SubscriptionManager* subscriptions; std::stringstream queueName; - sys::Mutex connLock; + mutable sys::Mutex connLock; + bool shutdown; + bool sleeping; void run(); public: ConnectionThread(ManagementAgentImpl& _agent) : - operational(false), agent(_agent), subscriptions(0) {} + operational(false), agent(_agent), subscriptions(0), + shutdown(false), sleeping(false) {} ~ConnectionThread(); void sendBuffer(qpid::framing::Buffer& buf, uint32_t length, const std::string& exchange, const std::string& routingKey); void bindToBank(uint32_t brokerBank, uint32_t agentBank); + void close(); + bool isSleeping() const; }; class PublishThread : public sys::Runnable |