summaryrefslogtreecommitdiff
path: root/cpp/src/qpid
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
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')
-rw-r--r--cpp/src/qpid/broker/SessionState.h57
-rw-r--r--cpp/src/qpid/broker/SuspendedSessions.cpp58
-rw-r--r--cpp/src/qpid/broker/SuspendedSessions.h59
3 files changed, 174 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/SessionState.h b/cpp/src/qpid/broker/SessionState.h
new file mode 100644
index 0000000000..30f071ca55
--- /dev/null
+++ b/cpp/src/qpid/broker/SessionState.h
@@ -0,0 +1,57 @@
+#ifndef QPID_BROKER_SESSION_H
+#define QPID_BROKER_SESSION_H
+
+/*
+ *
+ * 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/framing/Uuid.h"
+
+namespace qpid {
+namespace broker {
+
+/**
+ * State of a session.
+ */
+class SessionState
+{
+ public:
+ /** Create a new, active session. */
+ SessionState(uint32_t timeoutSeconds)
+ : id(true), active(true), timeout(timeoutSeconds) {}
+
+ const framing::Uuid& getId() const { return id; }
+ uint32_t getTimeout() const { return timeout; }
+
+ /** Call SuspendedSessions::resume to re-activate a suspended session. */
+ bool isActive() const { return active; }
+
+ private:
+ friend class SuspendedSessions;
+ framing::Uuid id;
+ bool active;
+ uint32_t timeout;
+};
+
+}} // namespace qpid::broker
+
+
+
+#endif /*!QPID_BROKER_SESSION_H*/
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
+
+
+
diff --git a/cpp/src/qpid/broker/SuspendedSessions.h b/cpp/src/qpid/broker/SuspendedSessions.h
new file mode 100644
index 0000000000..03c5df27ed
--- /dev/null
+++ b/cpp/src/qpid/broker/SuspendedSessions.h
@@ -0,0 +1,59 @@
+#ifndef QPID_BROKER_SUSPENDEDSESSIONS_H
+#define QPID_BROKER_SUSPENDEDSESSIONS_H
+
+/*
+ *
+ * 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/broker/SessionState.h"
+#include "qpid/sys/Time.h"
+#include "qpid/sys/Mutex.h"
+
+#include <map>
+
+namespace qpid {
+namespace broker {
+
+/** Collection of suspended sessions.
+ * Thread safe.
+ */
+class SuspendedSessions {
+ typedef std::multimap<sys::AbsTime,SessionState> Map;
+
+ sys::Mutex lock;
+ Map suspended;
+
+ public:
+ /** Suspend a session, start it's timeout counter.*/
+ void suspend(SessionState& session);
+
+ /** Resume a suspended session.
+ *@throw Exception if timed out or non-existant.
+ */
+ SessionState resume(const framing::Uuid& id);
+};
+
+
+
+}} // namespace qpid::broker
+
+
+
+#endif /*!QPID_BROKER_SUSPENDEDSESSIONS_H*/