summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/SessionManager.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-09-28 16:21:34 +0000
committerAlan Conway <aconway@apache.org>2007-09-28 16:21:34 +0000
commit8b82aef0397d65de0c7278476e4f409fcc636306 (patch)
treea25d9bbb01203335bc1450a5e5ed0c29074913ae /cpp/src/qpid/broker/SessionManager.cpp
parentf689c47486b4cfc7655e37da2b232fe27be1cc42 (diff)
downloadqpid-python-8b82aef0397d65de0c7278476e4f409fcc636306.tar.gz
* 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
Diffstat (limited to 'cpp/src/qpid/broker/SessionManager.cpp')
-rw-r--r--cpp/src/qpid/broker/SessionManager.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/cpp/src/qpid/broker/SessionManager.cpp b/cpp/src/qpid/broker/SessionManager.cpp
index 20dd29bc31..e422e50657 100644
--- a/cpp/src/qpid/broker/SessionManager.cpp
+++ b/cpp/src/qpid/broker/SessionManager.cpp
@@ -22,19 +22,22 @@
#include "SessionManager.h"
#include "SessionState.h"
#include "qpid/framing/reply_exceptions.h"
+#include "qpid/log/Statement.h"
+#include "qpid/log/Helpers.h"
#include "qpid/memory.h"
#include <boost/bind.hpp>
+#include <boost/range.hpp>
#include <algorithm>
#include <functional>
+#include <ostream>
namespace qpid {
namespace broker {
using namespace sys;
using namespace framing;
-using std::make_pair;
SessionManager::SessionManager() {}
@@ -51,12 +54,16 @@ std::auto_ptr<SessionState> SessionManager::open(
void SessionManager::suspend(std::auto_ptr<SessionState> session) {
Mutex::ScopedLock l(lock);
- session->expiry = AbsTime(now(),session->getTimeout());
+ active.erase(session->getId());
+ session->expiry = AbsTime(now(),session->getTimeout()*TIME_SEC);
+ session->handler = 0;
suspended.push_back(session.release()); // In expiry order
eraseExpired();
}
-std::auto_ptr<SessionState> SessionManager::resume(const Uuid& id) {
+std::auto_ptr<SessionState> SessionManager::resume(
+ SessionHandler& sh, const Uuid& id)
+{
Mutex::ScopedLock l(lock);
eraseExpired();
if (active.find(id) != active.end())
@@ -70,15 +77,20 @@ std::auto_ptr<SessionState> SessionManager::resume(const Uuid& id) {
throw InvalidArgumentException(
QPID_MSG("No suspended session with id=" << id));
active.insert(id);
- return make_auto_ptr(suspended.release(i).release());
+ std::auto_ptr<SessionState> state(suspended.release(i).release());
+ state->handler = &sh;
+ return state;
}
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);
+ if (!suspended.empty()) {
+ Suspended::iterator keep = std::lower_bound(
+ suspended.begin(), suspended.end(), now(),
+ boost::bind(std::less<AbsTime>(), boost::bind(&SessionState::expiry, _1), _2));
+ QPID_LOG(debug, "Expiring sessions: " << log::formatList(suspended.begin(), keep));
+ suspended.erase(suspended.begin(), keep);
+ }
}
}} // namespace qpid::broker