From 8b82aef0397d65de0c7278476e4f409fcc636306 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 28 Sep 2007 16:21:34 +0000 Subject: * src/tests/ClientSessionTest.cpp: Suspend/resume tests. * broker/SessionManager.cpp, broker/SessionHandler.cpp: Implement suspend/resume * client/ScopedAssociation.h, SessionCore.h, SessionHandler.h: Simplified relationships. - Removed ScopedAssociation. - SessionHandler: is now a member of SessionCore. - SessionCore: shared_ptr ownership by Session(s) and ConnectionImpl. - Using framing::FrameHandler interfaces. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@580403 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/ConnectionImpl.cpp | 46 ++++++++++++++-------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'cpp/src/qpid/client/ConnectionImpl.cpp') diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index 8ab60cff50..43576d2273 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -18,7 +18,11 @@ * under the License. * */ +#include "qpid/framing/reply_exceptions.h" + #include "ConnectionImpl.h" +#include "SessionCore.h" + #include #include @@ -26,7 +30,8 @@ using namespace qpid::client; using namespace qpid::framing; using namespace qpid::sys; -ConnectionImpl::ConnectionImpl(boost::shared_ptr c) : connector(c), isClosed(false) +ConnectionImpl::ConnectionImpl(boost::shared_ptr c) + : connector(c), isClosed(false) { handler.in = boost::bind(&ConnectionImpl::incoming, this, _1); handler.out = boost::bind(&Connector::send, connector, _1); @@ -37,22 +42,13 @@ ConnectionImpl::ConnectionImpl(boost::shared_ptr c) : connector(c), i connector->setShutdownHandler(this); } -void ConnectionImpl::allocated(SessionCore::shared_ptr session) -{ - Mutex::ScopedLock l(lock); - if (sessions.find(session->getId()) != sessions.end()) { - throw Exception("Id already in use."); - } - sessions[session->getId()] = session; -} - -void ConnectionImpl::released(SessionCore::shared_ptr session) +void ConnectionImpl::addSession(const boost::shared_ptr& session) { Mutex::ScopedLock l(lock); - SessionMap::iterator i = sessions.find(session->getId()); - if (i != sessions.end()) { - sessions.erase(i); - } + boost::shared_ptr& s = sessions[session->getChannel()]; + if (s) + throw ChannelBusyException(); + s = session; } void ConnectionImpl::handle(framing::AMQFrame& frame) @@ -62,7 +58,14 @@ void ConnectionImpl::handle(framing::AMQFrame& frame) void ConnectionImpl::incoming(framing::AMQFrame& frame) { - find(frame.getChannel())->handle(frame); + boost::shared_ptr s; + { + Mutex::ScopedLock l(lock); + s = sessions[frame.getChannel()]; + } + if (!s) + throw ChannelErrorException(); + s->in(frame); } void ConnectionImpl::open(const std::string& host, int port, @@ -117,23 +120,12 @@ void ConnectionImpl::signalClose(uint16_t code, const std::string& text) { Mutex::ScopedLock l(lock); for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); i++) { - Mutex::ScopedUnlock u(lock); i->second->closed(code, text); } sessions.clear(); isClosed = true; } -SessionCore::shared_ptr ConnectionImpl::find(uint16_t id) -{ - Mutex::ScopedLock l(lock); - SessionMap::iterator i = sessions.find(id); - if (i == sessions.end()) { - throw ConnectionException(504, (boost::format("Invalid channel number %g") % id).str()); - } - return i->second; -} - void ConnectionImpl::assertNotClosed() { Mutex::ScopedLock l(lock); -- cgit v1.2.1