From ecffd4bacaaddde679f00bc9e11d556820df6073 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 13 May 2010 18:55:06 +0000 Subject: Moved FailoverUpdates to qpid::messaging namespace. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@943975 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/include/qpid/client/amqp0_10/FailoverUpdates.h | 55 -------------- cpp/include/qpid/messaging/FailoverUpdates.h | 49 ++++++++++++ cpp/src/CMakeLists.txt | 3 +- cpp/src/Makefile.am | 8 +- cpp/src/qpid/client/amqp0_10/FailoverUpdates.cpp | 86 ---------------------- cpp/src/qpid/messaging/FailoverUpdates.cpp | 83 +++++++++++++++++++++ cpp/src/tests/qpid_receive.cpp | 4 +- cpp/src/tests/qpid_send.cpp | 4 +- 8 files changed, 141 insertions(+), 151 deletions(-) delete mode 100644 cpp/include/qpid/client/amqp0_10/FailoverUpdates.h create mode 100644 cpp/include/qpid/messaging/FailoverUpdates.h delete mode 100644 cpp/src/qpid/client/amqp0_10/FailoverUpdates.cpp create mode 100644 cpp/src/qpid/messaging/FailoverUpdates.cpp (limited to 'cpp') diff --git a/cpp/include/qpid/client/amqp0_10/FailoverUpdates.h b/cpp/include/qpid/client/amqp0_10/FailoverUpdates.h deleted file mode 100644 index 159745e67c..0000000000 --- a/cpp/include/qpid/client/amqp0_10/FailoverUpdates.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_H -#define QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_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/client/ClientImportExport.h" - -namespace qpid { - -namespace messaging { -class Connection; -} - -namespace client { -namespace amqp0_10 { - -struct FailoverUpdatesImpl; -/** - * A utility to listen for updates on cluster membership - published - * via the amq.failover exchange - and update the list of known urls - * for a connection accordingly. - */ -class FailoverUpdates -{ - public: - QPID_CLIENT_EXTERN FailoverUpdates(qpid::messaging::Connection& connection); - QPID_CLIENT_EXTERN ~FailoverUpdates(); - private: - FailoverUpdatesImpl* impl; - - //no need to copy instances of this class - FailoverUpdates(const FailoverUpdates&); - FailoverUpdates& operator=(const FailoverUpdates&); -}; -}}} // namespace qpid::client::amqp0_10 - -#endif /*!QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_H*/ diff --git a/cpp/include/qpid/messaging/FailoverUpdates.h b/cpp/include/qpid/messaging/FailoverUpdates.h new file mode 100644 index 0000000000..1d4cfaa10d --- /dev/null +++ b/cpp/include/qpid/messaging/FailoverUpdates.h @@ -0,0 +1,49 @@ +#ifndef QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_H +#define QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_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/client/ClientImportExport.h" + +namespace qpid { +namespace messaging { +class Connection; +class FailoverUpdatesImpl; + +/** + * A utility to listen for updates on cluster membership and update + * the list of known urls for a connection accordingly. + */ +class FailoverUpdates +{ + public: + QPID_CLIENT_EXTERN FailoverUpdates(Connection& connection); + QPID_CLIENT_EXTERN ~FailoverUpdates(); + private: + FailoverUpdatesImpl* impl; + + //no need to copy instances of this class + FailoverUpdates(const FailoverUpdates&); + FailoverUpdates& operator=(const FailoverUpdates&); +}; +}} // namespace qpid::messaging + +#endif /*!QPID_CLIENT_AMQP0_10_FAILOVERUPDATES_H*/ diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt index e40bfd3d7d..3cd54f1084 100644 --- a/cpp/src/CMakeLists.txt +++ b/cpp/src/CMakeLists.txt @@ -711,13 +711,14 @@ set (qpidclient_SOURCES qpid/messaging/SessionImpl.h qpid/messaging/Sender.cpp qpid/messaging/SenderImpl.h + qpid/messaging/FailoverUpdates.h + qpid/messaging/FailoverUpdates.cpp qpid/client/amqp0_10/AcceptTracker.h qpid/client/amqp0_10/AcceptTracker.cpp qpid/client/amqp0_10/AddressResolution.h qpid/client/amqp0_10/AddressResolution.cpp qpid/client/amqp0_10/ConnectionImpl.h qpid/client/amqp0_10/ConnectionImpl.cpp - qpid/client/amqp0_10/FailoverUpdates.cpp qpid/client/amqp0_10/IncomingMessages.h qpid/client/amqp0_10/IncomingMessages.cpp qpid/client/amqp0_10/MessageSink.h diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index eaf961d6e7..4a5e26db79 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -724,13 +724,13 @@ libqpidclient_la_SOURCES = \ qpid/messaging/SenderImpl.h \ qpid/messaging/ReceiverImpl.h \ qpid/messaging/SessionImpl.h \ + qpid/messaging/FailoverUpdates.cpp \ qpid/client/amqp0_10/AcceptTracker.h \ qpid/client/amqp0_10/AcceptTracker.cpp \ qpid/client/amqp0_10/AddressResolution.h \ qpid/client/amqp0_10/AddressResolution.cpp \ qpid/client/amqp0_10/ConnectionImpl.h \ qpid/client/amqp0_10/ConnectionImpl.cpp \ - qpid/client/amqp0_10/FailoverUpdates.cpp \ qpid/client/amqp0_10/IncomingMessages.h \ qpid/client/amqp0_10/IncomingMessages.cpp \ qpid/client/amqp0_10/MessageSink.h \ @@ -828,11 +828,11 @@ nobase_include_HEADERS += \ ../include/qpid/messaging/Message.h \ ../include/qpid/messaging/Receiver.h \ ../include/qpid/messaging/Sender.h \ - ../include/qpid/messaging/Session.h \ + ../include/qpid/messaging/Session.h \ + ../include/qpid/messaging/FailoverUpdates.h \ ../include/qpid/types/Exception.h \ ../include/qpid/types/Uuid.h \ - ../include/qpid/types/Variant.h \ - ../include/qpid/client/amqp0_10/FailoverUpdates.h + ../include/qpid/types/Variant.h # Force build of qpidd during dist phase so help2man will work. dist-hook: $(BUILT_SOURCES) diff --git a/cpp/src/qpid/client/amqp0_10/FailoverUpdates.cpp b/cpp/src/qpid/client/amqp0_10/FailoverUpdates.cpp deleted file mode 100644 index 09a9aa06d3..0000000000 --- a/cpp/src/qpid/client/amqp0_10/FailoverUpdates.cpp +++ /dev/null @@ -1,86 +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/client/amqp0_10/FailoverUpdates.h" -#include "qpid/messaging/Connection.h" -#include "qpid/messaging/Message.h" -#include "qpid/messaging/Receiver.h" -#include "qpid/messaging/Session.h" -#include "qpid/sys/Runnable.h" -#include "qpid/sys/Thread.h" -#include "qpid/log/Statement.h" -#include "qpid/Exception.h" -#include "qpid/Url.h" -#include - -namespace qpid { -namespace client { -namespace amqp0_10 { - -using namespace qpid::messaging; - -struct FailoverUpdatesImpl : qpid::sys::Runnable -{ - Connection connection; - Session session; - Receiver receiver; - qpid::sys::Thread thread; - - FailoverUpdatesImpl(Connection& c) : connection(c) - { - session = connection.createSession("failover-updates"); - receiver = session.createReceiver("amq.failover"); - thread = qpid::sys::Thread(*this); - } - - ~FailoverUpdatesImpl() { - try { - session.close(); - } catch(...) {} // Squash exceptions in a destructor. - thread.join(); - } - - void run() - { - try { - Message message; - while (receiver.fetch(message)) { - connection.setOption("reconnect-urls", message.getProperties()["amq.failover"]); - QPID_LOG(debug, "Set reconnect-urls to " << message.getProperties()["amq.failover"]); - session.acknowledge(); - } - } - catch (const ClosedException&) {} - catch (const qpid::TransportFailure& e) { - QPID_LOG(warning, "Failover updates stopped on loss of connection. " << e.what()); - } - catch (const std::exception& e) { - QPID_LOG(warning, "Failover updates stopped due to exception: " << e.what()); - } - } -}; - -FailoverUpdates::FailoverUpdates(Connection& connection) : impl(new FailoverUpdatesImpl(connection)) {} -FailoverUpdates::~FailoverUpdates() { if (impl) { delete impl; } } -FailoverUpdates::FailoverUpdates(const FailoverUpdates&) : impl(0) {} -FailoverUpdates& FailoverUpdates::operator=(const FailoverUpdates&) { return *this; } - - -}}} // namespace qpid::client::amqp0_10 diff --git a/cpp/src/qpid/messaging/FailoverUpdates.cpp b/cpp/src/qpid/messaging/FailoverUpdates.cpp new file mode 100644 index 0000000000..27b94aaa7a --- /dev/null +++ b/cpp/src/qpid/messaging/FailoverUpdates.cpp @@ -0,0 +1,83 @@ +/* + * + * 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/FailoverUpdates.h" +#include "qpid/messaging/Connection.h" +#include "qpid/messaging/Message.h" +#include "qpid/messaging/Receiver.h" +#include "qpid/messaging/Session.h" +#include "qpid/sys/Runnable.h" +#include "qpid/sys/Thread.h" +#include "qpid/log/Statement.h" +#include "qpid/Exception.h" +#include "qpid/Url.h" +#include + +namespace qpid { +namespace messaging { + +struct FailoverUpdatesImpl : qpid::sys::Runnable +{ + Connection connection; + Session session; + Receiver receiver; + qpid::sys::Thread thread; + + FailoverUpdatesImpl(Connection& c) : connection(c) + { + session = connection.createSession("failover-updates"); + receiver = session.createReceiver("amq.failover"); + thread = qpid::sys::Thread(*this); + } + + ~FailoverUpdatesImpl() { + try { + session.close(); + } catch(...) {} // Squash exceptions in a destructor. + thread.join(); + } + + void run() + { + try { + Message message; + while (receiver.fetch(message)) { + connection.setOption("reconnect-urls", message.getProperties()["amq.failover"]); + QPID_LOG(debug, "Set reconnect-urls to " << message.getProperties()["amq.failover"]); + session.acknowledge(); + } + } + catch (const ClosedException&) {} + catch (const qpid::TransportFailure& e) { + QPID_LOG(warning, "Failover updates stopped on loss of connection. " << e.what()); + } + catch (const std::exception& e) { + QPID_LOG(warning, "Failover updates stopped due to exception: " << e.what()); + } + } +}; + +FailoverUpdates::FailoverUpdates(Connection& connection) : impl(new FailoverUpdatesImpl(connection)) {} +FailoverUpdates::~FailoverUpdates() { if (impl) { delete impl; } } +FailoverUpdates::FailoverUpdates(const FailoverUpdates&) : impl(0) {} +FailoverUpdates& FailoverUpdates::operator=(const FailoverUpdates&) { return *this; } + + +}} // namespace qpid::messaging diff --git a/cpp/src/tests/qpid_receive.cpp b/cpp/src/tests/qpid_receive.cpp index 53d1d7d1fe..15b8d763eb 100644 --- a/cpp/src/tests/qpid_receive.cpp +++ b/cpp/src/tests/qpid_receive.cpp @@ -25,10 +25,10 @@ #include #include #include +#include #include #include #include -#include #include "TestOptions.h" #include "Statistics.h" @@ -37,8 +37,6 @@ using namespace qpid::messaging; using namespace qpid::types; -using qpid::client::amqp0_10::FailoverUpdates; - using namespace std; namespace qpid { diff --git a/cpp/src/tests/qpid_send.cpp b/cpp/src/tests/qpid_send.cpp index 57282f7399..7fef57a966 100644 --- a/cpp/src/tests/qpid_send.cpp +++ b/cpp/src/tests/qpid_send.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include "TestOptions.h" @@ -37,7 +37,7 @@ using namespace std; using namespace qpid::messaging; using namespace qpid::types; -using qpid::client::amqp0_10::FailoverUpdates; + typedef std::vector string_vector; namespace qpid { -- cgit v1.2.1