summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2016-04-05 21:50:04 +0000
committerAlan Conway <aconway@apache.org>2016-04-05 21:50:04 +0000
commiteb1e7851a50c6a7901c73eb42d639516c0e3ba43 (patch)
tree509c001a09e2b9fecaba5597fa41869f5fe7a4b1
parentc9f1b7641fa089eca017a543991485be5de35775 (diff)
downloadqpid-python-eb1e7851a50c6a7901c73eb42d639516c0e3ba43.tar.gz
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
-rw-r--r--qpid/cpp/include/qpid/messaging/shutdown.h38
-rw-r--r--qpid/cpp/src/CMakeLists.txt1
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionImpl.h2
-rw-r--r--qpid/cpp/src/qpid/ha/StatusCheck.cpp4
-rw-r--r--qpid/cpp/src/qpid/messaging/ProtocolRegistry.cpp25
-rw-r--r--qpid/cpp/src/qpid/messaging/ProtocolRegistry.h5
-rw-r--r--qpid/cpp/src/qpid/messaging/amqp/ConnectionHandle.cpp7
-rw-r--r--qpid/cpp/src/qpid/messaging/shutdown.cpp32
8 files changed, 35 insertions, 79 deletions
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<std::string>& in, const std::string& base=EMP
}
typedef std::map<std::string, ProtocolRegistry::Factory*> Factories;
+typedef std::vector<ProtocolRegistry::Shutdown*> 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<std::string> 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<std::string>& 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 <qpid/messaging/shutdown.h>
-#include "../client/ConnectionImpl.h"
-#include "amqp/DriverImpl.h"
-
-namespace qpid {
-namespace messaging {
-
-void shutdown() {
- amqp::DriverImpl::getDefault()->stop();
- qpid::client::shutdown();
-}
-
-}}