diff options
| author | Alan Conway <aconway@apache.org> | 2008-10-07 17:27:06 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2008-10-07 17:27:06 +0000 |
| commit | 41d33af55b9fbf4c664ccb56accb1a37bd1ef006 (patch) | |
| tree | de5e5b5e431bf695b2c44e198ee93d179201a0e2 /cpp/src/qpid/client | |
| parent | a653ebe5bdfad1d44a576d2ab23f7e6ea80ba96f (diff) | |
| download | qpid-python-41d33af55b9fbf4c664ccb56accb1a37bd1ef006.tar.gz | |
broker: Fixed incorrect pass-by-reference of Queue::shared_ptr in several files.
cluster: added FailoverExchange - send cluster membership to clients.
client: added FailoverListener - receive cluster updates from failover exchange.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@702552 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/client')
| -rw-r--r-- | cpp/src/qpid/client/FailoverListener.cpp | 59 | ||||
| -rw-r--r-- | cpp/src/qpid/client/FailoverListener.h | 58 |
2 files changed, 117 insertions, 0 deletions
diff --git a/cpp/src/qpid/client/FailoverListener.cpp b/cpp/src/qpid/client/FailoverListener.cpp new file mode 100644 index 0000000000..95c137d922 --- /dev/null +++ b/cpp/src/qpid/client/FailoverListener.cpp @@ -0,0 +1,59 @@ +/* + * + * 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 "FailoverListener.h" + +namespace qpid { +namespace client { + +static const std::string AMQ_FAILOVER("amq.failover"); + +FailoverListener::FailoverListener(Connection c) + : connection(c), session(c.newSession()), subscriptions(session) +{ + std::string qname=AMQ_FAILOVER + "." + session.getId().getName(); + if (session.exchangeQuery(arg::exchange=AMQ_FAILOVER).getType().empty()) + return; // Failover exchange not implemented. + session.queueDeclare(arg::queue=qname, arg::exclusive=true, arg::autoDelete=true); + session.exchangeBind(arg::queue=qname, arg::exchange=AMQ_FAILOVER); + subscriptions.subscribe(*this, qname, FlowControl::unlimited()); + thread = sys::Thread(subscriptions); +} + +FailoverListener::~FailoverListener() { + subscriptions.stop(); + if (thread.id()) thread.join(); +} + +void FailoverListener::received(Message& msg) { + sys::Mutex::ScopedLock l(lock); + knowBrokers.clear(); + framing::Array urlArray; + msg.getHeaders().getArray("amq.failover", urlArray); + for (framing::Array::ValueVector::const_iterator i = urlArray.begin(); i < urlArray.end(); ++i ) + knowBrokers.push_back(Url((*i)->get<std::string>())); +} + +std::vector<Url> FailoverListener::getKnownBrokers() const { + sys::Mutex::ScopedLock l(lock); + return knowBrokers; +} + +}} // namespace qpid::client diff --git a/cpp/src/qpid/client/FailoverListener.h b/cpp/src/qpid/client/FailoverListener.h new file mode 100644 index 0000000000..2c06947300 --- /dev/null +++ b/cpp/src/qpid/client/FailoverListener.h @@ -0,0 +1,58 @@ +#ifndef QPID_CLIENT_FAILOVERLISTENER_H +#define QPID_CLIENT_FAILOVERLISTENER_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/Connection.h" +#include "qpid/client/Session.h" +#include "qpid/client/MessageListener.h" +#include "qpid/client/SubscriptionManager.h" +#include "qpid/Url.h" +#include "qpid/sys/Mutex.h" +#include "qpid/sys/Thread.h" +#include <vector> + +namespace qpid { +namespace client { + +/** + * @internal Listen for failover updates from the amq.failover exchange. + */ +class FailoverListener : public MessageListener +{ + public: + FailoverListener(Connection); + ~FailoverListener(); + std::vector<Url> getKnownBrokers() const; + void received(Message& msg); + + private: + mutable sys::Mutex lock; + Connection connection; + Session session; + SubscriptionManager subscriptions; + sys::Thread thread; + std::vector<Url> knowBrokers; +}; +}} // namespace qpid::client + +#endif /*!QPID_CLIENT_FAILOVERLISTENER_H*/ |
