summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/SuspendedSessions.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-08-27 15:52:47 +0000
committerAlan Conway <aconway@apache.org>2007-08-27 15:52:47 +0000
commitd7b1ad93da22a7c1caf499b9eec7200a7ae52b6e (patch)
tree4943e75d94dc060bd8ba0206de9be3d85481b7a4 /cpp/src/qpid/broker/SuspendedSessions.cpp
parent366b7287350d47f788a0d1af1a1bf73328e4ec1f (diff)
downloadqpid-python-d7b1ad93da22a7c1caf499b9eec7200a7ae52b6e.tar.gz
* src/qpid/broker/SessionState.h: State of a session.
* src/qpid/broker/SuspendedSessions.h, .cpp: Stores suspended sessions. * src/tests/Session.cpp: Test session classes. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@570164 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/SuspendedSessions.cpp')
-rw-r--r--cpp/src/qpid/broker/SuspendedSessions.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/SuspendedSessions.cpp b/cpp/src/qpid/broker/SuspendedSessions.cpp
new file mode 100644
index 0000000000..cc90f04809
--- /dev/null
+++ b/cpp/src/qpid/broker/SuspendedSessions.cpp
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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 "SuspendedSessions.h"
+#include <boost/bind.hpp>
+
+namespace qpid {
+namespace broker {
+
+using namespace framing;
+using namespace sys;
+using namespace boost;
+typedef Mutex::ScopedLock Lock;
+
+void SuspendedSessions::suspend(SessionState& s) {
+ Lock l(lock);
+ assert(s.isActive());
+ AbsTime expires(now(), Duration(s.timeout*TIME_SEC));
+ suspended.insert(std::make_pair(expires, s));
+ s.active = false;
+}
+
+SessionState SuspendedSessions::resume(const Uuid& id)
+{
+ Lock l(lock);
+ Map::iterator expired = suspended.lower_bound(now());
+ suspended.erase(suspended.begin(), expired);
+
+ Map::iterator resume = std::find_if(
+ suspended.begin(), suspended.end(),
+ bind(&SessionState::getId, bind(&Map::value_type::second, _1))==id);
+
+ if (resume == suspended.end())
+ throw Exception(QPID_MSG("Session timed out or invalid ID: " << id));
+ return resume->second;
+}
+
+}} // namespace qpid::broker
+
+
+