diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2011-05-27 15:44:23 +0000 |
commit | 66765100f4257159622cefe57bed50125a5ad017 (patch) | |
tree | a88ee23bb194eb91f0ebb2d9b23ff423e3ea8e37 /cpp/src/qpid/client/Dispatcher.cpp | |
parent | 1aeaa7b16e5ce54f10c901d75c4d40f9f88b9db6 (diff) | |
parent | 88b98b2f4152ef59a671fad55a0d08338b6b78ca (diff) | |
download | qpid-python-rajith_jms_client.tar.gz |
Creating a branch for experimenting with some ideas for JMS client.rajith_jms_client
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/rajith_jms_client@1128369 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/client/Dispatcher.cpp')
-rw-r--r-- | cpp/src/qpid/client/Dispatcher.cpp | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/cpp/src/qpid/client/Dispatcher.cpp b/cpp/src/qpid/client/Dispatcher.cpp deleted file mode 100644 index a715c623bf..0000000000 --- a/cpp/src/qpid/client/Dispatcher.cpp +++ /dev/null @@ -1,151 +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/Dispatcher.h" -#include "qpid/client/SubscriptionImpl.h" -#include "qpid/client/SessionImpl.h" - -#include "qpid/framing/FrameSet.h" -#include "qpid/framing/MessageTransferBody.h" -#include "qpid/log/Statement.h" -#include "qpid/sys/BlockingQueue.h" -#include "qpid/client/Message.h" -#include "qpid/client/MessageImpl.h" - -#include <boost/version.hpp> -#if (BOOST_VERSION >= 104000) -# include <boost/serialization/state_saver.hpp> - using boost::serialization::state_saver; -#else -# include <boost/state_saver.hpp> - using boost::state_saver; -#endif /* BOOST_VERSION */ - -using qpid::framing::FrameSet; -using qpid::framing::MessageTransferBody; -using qpid::sys::Mutex; -using qpid::sys::ScopedLock; -using qpid::sys::Thread; - -namespace qpid { -namespace client { - -Dispatcher::Dispatcher(const Session& s, const std::string& q) - : session(s), - running(false), - autoStop(true), - failoverHandler(0) -{ - Demux& demux = SessionBase_0_10Access(session).get()->getDemux(); - queue = q.empty() ? demux.getDefault() : demux.get(q); -} - -void Dispatcher::start() -{ - worker = Thread(this); -} - -void Dispatcher::wait() -{ - worker.join(); -} - -void Dispatcher::run() -{ - Mutex::ScopedLock l(lock); - if (running) - throw Exception("Dispatcher is already running."); - state_saver<bool> reset(running); // Reset to false on exit. - running = true; - try { - while (!queue->isClosed()) { - Mutex::ScopedUnlock u(lock); - FrameSet::shared_ptr content = queue->pop(); - if (content->isA<MessageTransferBody>()) { - Message msg(new MessageImpl(*content)); - boost::intrusive_ptr<SubscriptionImpl> listener = find(msg.getDestination()); - if (!listener) { - QPID_LOG(error, "No listener found for destination " << msg.getDestination()); - } else { - assert(listener); - listener->received(msg); - } - } else { - if (handler.get()) { - handler->handle(*content); - } else { - QPID_LOG(warning, "No handler found for " << *(content->getMethod())); - } - } - } - session.sync(); // Make sure all our acks are received before returning. - } - catch (const ClosedException&) { - QPID_LOG(debug, QPID_MSG(session.getId() << ": closed by peer")); - } - catch (const TransportFailure&) { - QPID_LOG(info, QPID_MSG(session.getId() << ": transport failure")); - throw; - } - catch (const std::exception& e) { - if ( failoverHandler ) { - QPID_LOG(debug, QPID_MSG(session.getId() << " failover: " << e.what())); - failoverHandler(); - } else { - QPID_LOG(error, session.getId() << " error: " << e.what()); - throw; - } - } -} - -void Dispatcher::stop() -{ - ScopedLock<Mutex> l(lock); - queue->close(); // Will interrupt thread blocked in pop() -} - -void Dispatcher::setAutoStop(bool b) -{ - ScopedLock<Mutex> l(lock); - autoStop = b; -} - -boost::intrusive_ptr<SubscriptionImpl> Dispatcher::find(const std::string& name) -{ - ScopedLock<Mutex> l(lock); - Listeners::iterator i = listeners.find(name); - if (i == listeners.end()) { - return defaultListener; - } - return i->second; -} - -void Dispatcher::listen(const boost::intrusive_ptr<SubscriptionImpl>& subscription) { - ScopedLock<Mutex> l(lock); - listeners[subscription->getName()] = subscription; -} - -void Dispatcher::cancel(const std::string& destination) { - ScopedLock<Mutex> l(lock); - if (listeners.erase(destination) && running && autoStop && listeners.empty()) - queue->close(); -} - -}} |