From d25c2d8f8156b33c78b797cd4aa4823d3ade02cc Mon Sep 17 00:00:00 2001 From: Matthew Newhook Date: Wed, 9 Sep 2009 15:46:16 -0230 Subject: - cpp/demo/Ice/session now uses a timer for the periodic reaping. - cpp/demo/Glacier2/chat now uses a custom permissions verifier, and a timer for refresh of the Glacier2 session. Squashed commit of the following: commit 82732512d64b4b6782b9c96e9c558ad56ea232af Author: Matthew Newhook Date: Wed Sep 9 15:35:47 2009 -0230 Simplify session demo. commit 07cf68b9d12e8d648980d4bcae354e7531411b47 Author: Matthew Newhook Date: Wed Sep 9 14:59:15 2009 -0230 chat demo now uses a custom perissions verifier, and a timer task. --- cpp/demo/Ice/session/ReapTask.cpp | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cpp/demo/Ice/session/ReapTask.cpp (limited to 'cpp/demo/Ice/session/ReapTask.cpp') diff --git a/cpp/demo/Ice/session/ReapTask.cpp b/cpp/demo/Ice/session/ReapTask.cpp new file mode 100644 index 00000000000..e64ed458445 --- /dev/null +++ b/cpp/demo/Ice/session/ReapTask.cpp @@ -0,0 +1,59 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include + +using namespace std; +using namespace Demo; + +ReapTask::ReapTask() : + _timeout(IceUtil::Time::seconds(10)) +{ +} + +void +ReapTask::runTimerTask() +{ + Lock sync(*this); + + list::iterator p = _sessions.begin(); + while(p != _sessions.end()) + { + try + { + // + // Session destruction may take time in a + // real-world example. Therefore the current time + // is computed for each iteration. + // + if((IceUtil::Time::now(IceUtil::Time::Monotonic) - p->session->timestamp()) > _timeout) + { + string name = p->proxy->getName(); + p->proxy->destroy(); + cout << "The session " << name << " has timed out." << endl; + p = _sessions.erase(p); + } + else + { + ++p; + } + } + catch(const Ice::ObjectNotExistException&) + { + p = _sessions.erase(p); + } + } +} + +void +ReapTask::add(const SessionPrx& proxy, const SessionIPtr& session) +{ + Lock sync(*this); + _sessions.push_back(SessionProxyPair(proxy, session)); +} -- cgit v1.2.3