From eb1e7851a50c6a7901c73eb42d639516c0e3ba43 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 5 Apr 2016 21:50:04 +0000 Subject: QPID-7149: Fixed messaging client shutdown. Fix previous commit that did not respect the plugin boundaries for messaging::shutdown. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1737887 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/include/qpid/messaging/shutdown.h | 38 ---------------------- qpid/cpp/src/CMakeLists.txt | 1 - qpid/cpp/src/qpid/client/ConnectionImpl.h | 2 +- qpid/cpp/src/qpid/ha/StatusCheck.cpp | 4 +-- qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp | 25 ++++++++++++-- qpid/cpp/src/qpid/messaging/ProtocolRegistry.h | 5 ++- .../src/qpid/messaging/amqp/ConnectionHandle.cpp | 7 +++- qpid/cpp/src/qpid/messaging/shutdown.cpp | 32 ------------------ 8 files changed, 35 insertions(+), 79 deletions(-) delete mode 100644 qpid/cpp/include/qpid/messaging/shutdown.h delete mode 100644 qpid/cpp/src/qpid/messaging/shutdown.cpp diff --git a/qpid/cpp/include/qpid/messaging/shutdown.h b/qpid/cpp/include/qpid/messaging/shutdown.h deleted file mode 100644 index 7744630f13..0000000000 --- a/qpid/cpp/include/qpid/messaging/shutdown.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef QPID_MESSAGING_SHUTDOWN_H -#define QPID_MESSAGING_SHUTDOWN_H - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include "qpid/messaging/ImportExport.h" - -namespace qpid { -namespace messaging { - -/** Shut down the qpid::messaging library, clean up resources and stop background threads. - * Note you cannot use any of the qpid::messaging classes or functions after calling this. - * - * It is is not normally necessary to call this, the library cleans up automatically on process exit. - * You can use it to clean up resources early in unusual situations. - */ -QPID_MESSAGING_EXTERN void shutdown(); - -}} - -#endif // QPID_MESSAGING_SHUTDOWN_H diff --git a/qpid/cpp/src/CMakeLists.txt b/qpid/cpp/src/CMakeLists.txt index 36a4632e96..45f5987a6c 100644 --- a/qpid/cpp/src/CMakeLists.txt +++ b/qpid/cpp/src/CMakeLists.txt @@ -964,7 +964,6 @@ set (qpidmessaging_SOURCES qpid/messaging/ReceiverImpl.h qpid/messaging/SessionImpl.h qpid/messaging/SenderImpl.h - qpid/messaging/shutdown.cpp qpid/client/amqp0_10/AcceptTracker.h qpid/client/amqp0_10/AcceptTracker.cpp qpid/client/amqp0_10/AddressResolution.h diff --git a/qpid/cpp/src/qpid/client/ConnectionImpl.h b/qpid/cpp/src/qpid/client/ConnectionImpl.h index 1087204e35..23105bd1fd 100644 --- a/qpid/cpp/src/qpid/client/ConnectionImpl.h +++ b/qpid/cpp/src/qpid/client/ConnectionImpl.h @@ -99,7 +99,7 @@ class ConnectionImpl : public Bounds, }; // Shut down the poller early. Internal use only. -void shutdown(); +QPID_CLIENT_EXTERN void shutdown(); }} diff --git a/qpid/cpp/src/qpid/ha/StatusCheck.cpp b/qpid/cpp/src/qpid/ha/StatusCheck.cpp index b6bce0fd7b..e1c8df5e56 100644 --- a/qpid/cpp/src/qpid/ha/StatusCheck.cpp +++ b/qpid/cpp/src/qpid/ha/StatusCheck.cpp @@ -23,13 +23,13 @@ #include "HaBroker.h" #include "qpid/broker/Broker.h" #include "qpid/log/Statement.h" -#include "qpid/messaging/shutdown.h" #include "qpid/messaging/Address.h" #include "qpid/messaging/Connection.h" #include "qpid/messaging/Message.h" #include "qpid/messaging/Receiver.h" #include "qpid/messaging/Sender.h" #include "qpid/messaging/Session.h" +#include "qpid/messaging/ProtocolRegistry.h" #include "qpid/types/Variant.h" namespace qpid { @@ -136,7 +136,7 @@ void StatusCheck::endThread() { // Shut down the client poller ASAP to avoid conflict with the broker's poller. // See https://issues.apache.org/jira/browse/QPID-7149 if (--threadCount == 0) { - messaging::shutdown(); + messaging::ProtocolRegistry::shutdown(); } } diff --git a/qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp b/qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp index dbb0d6dfc2..ba55149048 100644 --- a/qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp +++ b/qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp @@ -20,9 +20,11 @@ */ #include "ProtocolRegistry.h" #include "qpid/messaging/exceptions.h" +#include "qpid/client/ConnectionImpl.h" #include "qpid/client/amqp0_10/ConnectionImpl.h" #include "qpid/client/LoadPlugins.h" #include "qpid/log/Statement.h" +#include "qpid/sys/Mutex.h" #include "qpid/Options.h" #include "qpid/StringUtils.h" #include "config.h" @@ -59,6 +61,7 @@ std::string join(const std::vector& in, const std::string& base=EMP } typedef std::map Factories; +typedef std::vector Shutdowns; ConnectionImpl* create_0_10(const std::string& url, const qpid::types::Variant::Map& options) { @@ -71,6 +74,7 @@ class Registry Registry() { factories["amqp0-10"] = &create_0_10; + shutdowns.push_back(&qpid::client::shutdown); CommonOptions common("", "", QPIDC_CONF_FILE); ProtocolOptions options; try { @@ -96,9 +100,10 @@ class Registry return i->second; } } - void add(const std::string& name, ProtocolRegistry::Factory* factory) + void add(const std::string& name, ProtocolRegistry::Factory* factory, ProtocolRegistry::Shutdown* shutdown) { factories[name] = factory; + shutdowns.push_back(shutdown); } std::string getNames() const { @@ -128,8 +133,17 @@ class Registry } } } + void shutdown() { + sys::Mutex::ScopedLock l(shutdownLock); + while (!shutdowns.empty()) { + shutdowns.back()(); + shutdowns.pop_back(); + } + } private: Factories factories; + Shutdowns shutdowns; + sys::Mutex shutdownLock; std::vector versions; }; @@ -192,9 +206,14 @@ ConnectionImpl* ProtocolRegistry::next(ConnectionImpl* last) throw MessagingException("No suitable protocol version supported by peer"); } -void ProtocolRegistry::add(const std::string& name, Factory* factory) +void ProtocolRegistry::add(const std::string& name, Factory* factory, Shutdown* shutdown) { - theRegistry().add(name, factory); + theRegistry().add(name, factory, shutdown); } +void ProtocolRegistry::shutdown() { + theRegistry().shutdown(); +} + + }} // namespace qpid::messaging diff --git a/qpid/cpp/src/qpid/messaging/ProtocolRegistry.h b/qpid/cpp/src/qpid/messaging/ProtocolRegistry.h index 6a6f5962c3..e5d8e918f7 100644 --- a/qpid/cpp/src/qpid/messaging/ProtocolRegistry.h +++ b/qpid/cpp/src/qpid/messaging/ProtocolRegistry.h @@ -36,9 +36,12 @@ class ProtocolRegistry { public: typedef ConnectionImpl* Factory(const std::string& url, const qpid::types::Variant::Map& options); + typedef void Shutdown(); + static ConnectionImpl* create(const std::string& url, const qpid::types::Variant::Map& options); static ConnectionImpl* next(ConnectionImpl*); - QPID_MESSAGING_EXTERN static void add(const std::string& name, Factory* factory); + QPID_MESSAGING_EXTERN static void add(const std::string& name, Factory*, Shutdown*); + QPID_MESSAGING_EXTERN static void shutdown(); private: static ConnectionImpl* createInternal(const std::vector& versions, const std::string& url, const qpid::types::Variant::Map& options, const std::string& error); }; diff --git a/qpid/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp b/qpid/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp index 90227fa29b..e34e0a5874 100644 --- a/qpid/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp +++ b/qpid/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp @@ -21,6 +21,7 @@ #include "ConnectionHandle.h" #include "ConnectionContext.h" #include "SessionHandle.h" +#include "DriverImpl.h" #include "qpid/messaging/Session.h" #include "qpid/messaging/ProtocolRegistry.h" @@ -40,11 +41,15 @@ ConnectionImpl* create(const std::string& u, const qpid::types::Variant::Map& o) } } +void shutdown() { + DriverImpl::getDefault()->stop(); +} + struct StaticInit { StaticInit() { - ProtocolRegistry::add("amqp1.0", &create); + ProtocolRegistry::add("amqp1.0", &create, &shutdown); }; } init; } diff --git a/qpid/cpp/src/qpid/messaging/shutdown.cpp b/qpid/cpp/src/qpid/messaging/shutdown.cpp deleted file mode 100644 index 01c7f56ac0..0000000000 --- a/qpid/cpp/src/qpid/messaging/shutdown.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#include -#include "../client/ConnectionImpl.h" -#include "amqp/DriverImpl.h" - -namespace qpid { -namespace messaging { - -void shutdown() { - amqp::DriverImpl::getDefault()->stop(); - qpid::client::shutdown(); -} - -}} -- cgit v1.2.1