summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/ReapThread.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2005-06-08 14:29:54 +0000
committerBenoit Foucher <benoit@zeroc.com>2005-06-08 14:29:54 +0000
commitbd4c28900c1e5306bea0a4cb2448f83d29dfa5e9 (patch)
treecabdd6919e7747b08ee6f076fea6cbf549c8c069 /cpp/src/IceGrid/ReapThread.cpp
parentFixed but reported in http://www.zeroc.com/vbulletin/showthread.php?t=1480 (diff)
downloadice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.tar.bz2
ice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.tar.xz
ice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.zip
Added node session support.
Diffstat (limited to 'cpp/src/IceGrid/ReapThread.cpp')
-rw-r--r--cpp/src/IceGrid/ReapThread.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/ReapThread.cpp b/cpp/src/IceGrid/ReapThread.cpp
new file mode 100644
index 00000000000..9ea1bbcfc1c
--- /dev/null
+++ b/cpp/src/IceGrid/ReapThread.cpp
@@ -0,0 +1,83 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 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 <Ice/Ice.h>
+#include <IceGrid/ReapThread.h>
+
+using namespace std;
+using namespace IceGrid;
+
+ReapThread::ReapThread(int timeout) :
+ _timeout(IceUtil::Time::milliSeconds(timeout)),
+ _terminated(false)
+{
+}
+
+void
+ReapThread::run()
+{
+ Lock sync(*this);
+
+ while(!_terminated)
+ {
+ list<pair<NodeSessionIPtr, NodeSessionPrx> >::iterator p = _sessions.begin();
+ while(p != _sessions.end())
+ {
+ try
+ {
+ if((IceUtil::Time::now() - p->first->timestamp()) > _timeout)
+ {
+ p->second->destroy();
+ p = _sessions.erase(p);
+ }
+ else
+ {
+ ++p;
+ }
+ }
+ catch(const Ice::ObjectNotExistException&)
+ {
+ p = _sessions.erase(p);
+ }
+ }
+
+ timedWait(_timeout);
+ }
+}
+
+void
+ReapThread::terminate()
+{
+ Lock sync(*this);
+
+ _terminated = true;
+ notify();
+
+ for(list<pair<NodeSessionIPtr, NodeSessionPrx> >::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p)
+ {
+ try
+ {
+ p->second->destroy();
+ }
+ catch(const Ice::Exception&)
+ {
+ // Ignore.
+ }
+ }
+
+ _sessions.clear();
+}
+
+void
+ReapThread::add(const NodeSessionPrx& proxy, const NodeSessionIPtr& session)
+{
+ Lock sync(*this);
+ _sessions.push_back(make_pair(session, proxy));
+}
+