diff options
Diffstat (limited to 'cpp/src/IceGrid/NodeSessionI.cpp')
-rw-r--r-- | cpp/src/IceGrid/NodeSessionI.cpp | 101 |
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; +} |