diff options
| author | Alan Conway <aconway@apache.org> | 2007-09-24 21:15:46 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-09-24 21:15:46 +0000 |
| commit | b3992a21f76f38797723f70168ecda6be21e3719 (patch) | |
| tree | 9654292603c8b2bc31d5685e8f965b4713352f72 /cpp/src/qpid/broker/SessionManager.cpp | |
| parent | 96c24e0cd7359cfb2fb026c742cbd1b2d23a0015 (diff) | |
| download | qpid-python-b3992a21f76f38797723f70168ecda6be21e3719.tar.gz | |
2007-09-24 Alan Conway <aconway@redhat.com>
* cpp/src/qpid/broker/SessionManager.cpp: Manage suspended sessions.
Replaces SuspendedSessions.
* cpp/src/qpid/broker/SessionState.cpp: Work with SessionManager.
* cpp/src/qpid/broker/SessionHandler.cpp: Owns SessionState.
* cpp/src/qpid/broker/Connection.h, .cpp: Owns session handlers.
* cpp/src/qpid/broker/Broker.h: Added SessionManager member.
* cpp/src/Makefile.am: Added broker/SessionManager.cpp
* amqp.0-10-preview.xml: Added session-busy and channel-busy constants.
* cpp/src/tests/.valgrind.supp-default: Added suppresssions for F7.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@578975 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/SessionManager.cpp')
| -rw-r--r-- | cpp/src/qpid/broker/SessionManager.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/SessionManager.cpp b/cpp/src/qpid/broker/SessionManager.cpp new file mode 100644 index 0000000000..20dd29bc31 --- /dev/null +++ b/cpp/src/qpid/broker/SessionManager.cpp @@ -0,0 +1,84 @@ +/* + * + * 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 "SessionManager.h" +#include "SessionState.h" +#include "qpid/framing/reply_exceptions.h" +#include "qpid/memory.h" + +#include <boost/bind.hpp> + +#include <algorithm> +#include <functional> + +namespace qpid { +namespace broker { + +using namespace sys; +using namespace framing; +using std::make_pair; + +SessionManager::SessionManager() {} + +SessionManager::~SessionManager() {} + +std::auto_ptr<SessionState> SessionManager::open( + SessionHandler& h, uint32_t timeout_) +{ + Mutex::ScopedLock l(lock); + std::auto_ptr<SessionState> session(new SessionState(*this, h, timeout_)); + active.insert(session->getId()); + return session; +} + +void SessionManager::suspend(std::auto_ptr<SessionState> session) { + Mutex::ScopedLock l(lock); + session->expiry = AbsTime(now(),session->getTimeout()); + suspended.push_back(session.release()); // In expiry order + eraseExpired(); +} + +std::auto_ptr<SessionState> SessionManager::resume(const Uuid& id) { + Mutex::ScopedLock l(lock); + eraseExpired(); + if (active.find(id) != active.end()) + throw SessionBusyException( + QPID_MSG("Session already active: " << id)); + Suspended::iterator i = std::find_if( + suspended.begin(), suspended.end(), + boost::bind(std::equal_to<Uuid>(), id, boost::bind(&SessionState::getId, _1)) + ); + if (i == suspended.end()) + throw InvalidArgumentException( + QPID_MSG("No suspended session with id=" << id)); + active.insert(id); + return make_auto_ptr(suspended.release(i).release()); +} + +void SessionManager::eraseExpired() { + // Called with lock held. + Suspended::iterator i = std::lower_bound( + suspended.begin(), suspended.end(), now(), + boost::bind(std::less<AbsTime>(), boost::bind(&SessionState::expiry, _1), _2)); + suspended.erase(suspended.begin(), i); +} + +}} // namespace qpid::broker |
