summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/session/ReapTask.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/Ice/session/ReapTask.cpp')
-rw-r--r--cpp/demo/Ice/session/ReapTask.cpp59
1 files changed, 59 insertions, 0 deletions
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 <ReapTask.h>
+
+using namespace std;
+using namespace Demo;
+
+ReapTask::ReapTask() :
+ _timeout(IceUtil::Time::seconds(10))
+{
+}
+
+void
+ReapTask::runTimerTask()
+{
+ Lock sync(*this);
+
+ list<SessionProxyPair>::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));
+}