summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/NodeSessionI.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/NodeSessionI.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/NodeSessionI.cpp')
-rw-r--r--cpp/src/IceGrid/NodeSessionI.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/NodeSessionI.cpp b/cpp/src/IceGrid/NodeSessionI.cpp
new file mode 100644
index 00000000000..b3a41d21488
--- /dev/null
+++ b/cpp/src/IceGrid/NodeSessionI.cpp
@@ -0,0 +1,101 @@
+// **********************************************************************
+//
+// 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/NodeSessionI.h>
+#include <IceGrid/Database.h>
+
+using namespace std;
+using namespace IceGrid;
+
+NodeSessionI::NodeSessionI(const DatabasePtr& database, const string& name, const NodePrx& node) :
+ _database(database),
+ _name(name),
+ _node(node),
+ _startTime(IceUtil::Time::now()),
+ _timestamp(_startTime),
+ _destroy(false)
+{
+ __setNoDelete(true);
+ try
+ {
+ _database->addNode(name, this);
+
+ //
+ // TODO: Notify observers, node's up.
+ //
+ }
+ catch(...)
+ {
+ __setNoDelete(false);
+ throw;
+ }
+ __setNoDelete(false);
+}
+
+void
+NodeSessionI::keepAlive(const Ice::Current& current)
+{
+ Lock sync(*this);
+ if(_destroy)
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+
+ _timestamp = IceUtil::Time::now();
+}
+
+Ice::StringSeq
+NodeSessionI::getServers(const Ice::Current& current)
+{
+ return _database->getAllNodeServers(_name);
+}
+
+void
+NodeSessionI::destroy(const Ice::Current& current)
+{
+ Lock sync(*this);
+ if(_destroy)
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+
+ _destroy = true;
+
+ _database->removeNode(_name);
+
+ //
+ // TODO: Notify observers, node's down.
+ //
+
+ try
+ {
+ current.adapter->remove(current.id);
+ }
+ catch(const Ice::ObjectAdapterDeactivatedException&)
+ {
+ }
+}
+
+const NodePrx&
+NodeSessionI::getNode() const
+{
+ return _node;
+}
+
+IceUtil::Time
+NodeSessionI::timestamp() const
+{
+ Lock sync(*this);
+ if(_destroy)
+ {
+ throw Ice::ObjectNotExistException(__FILE__, __LINE__);
+ }
+ return _timestamp;
+}