diff options
author | Benoit Foucher <benoit@zeroc.com> | 2005-06-08 14:29:54 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2005-06-08 14:29:54 +0000 |
commit | bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9 (patch) | |
tree | cabdd6919e7747b08ee6f076fea6cbf549c8c069 /cpp/src/IceGrid/IceGridNode.cpp | |
parent | Fixed but reported in http://www.zeroc.com/vbulletin/showthread.php?t=1480 (diff) | |
download | ice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.tar.bz2 ice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.tar.xz ice-bd4c28900c1e5306bea0a4cb2448f83d29dfa5e9.zip |
Added node session support.
Diffstat (limited to 'cpp/src/IceGrid/IceGridNode.cpp')
-rw-r--r-- | cpp/src/IceGrid/IceGridNode.cpp | 95 |
1 files changed, 36 insertions, 59 deletions
diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index b07cade381f..805a05c28a6 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -39,12 +39,14 @@ using namespace IceGrid; namespace IceGrid { -class RegistrationThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> +class KeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex> { public: - RegistrationThread(const RegistryPrx& registry, const string& name, const NodePrx& node, const LoggerPtr& logger) : - _registry(registry), _name(name), _node(node), _logger(logger), _shutdown(false) + KeepAliveThread(const NodeIPtr& node, int timeout) : + _node(node), + _timeout(IceUtil::Time::seconds(timeout)), + _shutdown(false) { } @@ -54,45 +56,30 @@ public: Lock sync(*this); while(!_shutdown) { - try - { - _registry->registerNode(_name, _node); - break; - } - catch(const NodeActiveException& ex) - { - _logger->error("a node with the same name is already registered and active"); - } - catch(const Ice::LocalException& ex) + _node->keepAlive(); + + if(!_shutdown) { - _logger->warning("couldn't contact the IceGrid registry"); + timedWait(_timeout); } - - timedWait(IceUtil::Time::seconds(30)); } } virtual void terminate() { - { - Lock(*this); - _shutdown = true; - notifyAll(); - } - - getThreadControl().join(); + Lock sync(*this); + _shutdown = true; + notifyAll(); } private: - const RegistryPrx _registry; - const string _name; - const NodePrx _node; - const Ice::LoggerPtr _logger; + const NodeIPtr _node; + const IceUtil::Time _timeout; bool _shutdown; }; -typedef IceUtil::Handle<RegistrationThread> RegistrationThreadPtr; +typedef IceUtil::Handle<KeepAliveThread> KeepAliveThreadPtr; class NodeService : public Service { @@ -116,7 +103,8 @@ private: ActivatorPtr _activator; WaitQueuePtr _waitQueue; RegistryIPtr _registry; - RegistrationThreadPtr _registrationThread; + NodeIPtr _node; + KeepAliveThreadPtr _keepAliveThread; }; class CollocatedRegistry : public RegistryI @@ -402,7 +390,6 @@ NodeService::start(int argc, char* argv[]) // // Create the node object adapter. // - properties->setProperty("IceGrid.Node.AdapterId", "IceGrid.Node." + name); ObjectAdapterPtr adapter = communicator()->createObjectAdapter("IceGrid.Node"); // @@ -416,38 +403,17 @@ NodeService::start(int argc, char* argv[]) // for the server and server adapter. It also takes care of installing the // evictors and object factories necessary to store these objects. // - NodeIPtr node = new NodeI(communicator(), _activator, _waitQueue, traceLevels, name); Identity id = stringToIdentity(IceUtil::generateUUID()); - adapter->add(node, id); - NodePrx nodeProxy = NodePrx::uncheckedCast(adapter->createDirectProxy(id)); + NodePrx nodeProxy = NodePrx::uncheckedCast(adapter->createProxy(id)); + _node = new NodeI(adapter, _activator, _waitQueue, traceLevels, nodeProxy, name); + adapter->add(_node, nodeProxy->ice_getIdentity()); // // Register this node with the node registry. // - RegistryPrx registry = - RegistryPrx::uncheckedCast(communicator()->stringToProxy("IceGrid/Registry@IceGrid.Registry.Internal")); - try - { - node->checkConsistency(registry->registerNode(name, nodeProxy)); - } - catch(const NodeActiveException&) - { - error("a node with the same name is already registered and active"); - return false; - } - catch(const LocalException& ex) - { - if(properties->getPropertyAsInt("IceGrid.Node.BackgroundRegistration") > 0) - { - _registrationThread = new RegistrationThread(registry, name, nodeProxy, communicator()->getLogger()); - _registrationThread->start(); - } - else - { - error("couldn't contact the IceGrid registry"); - return false; - } - } + int timeout = properties->getPropertyAsIntWithDefault("IceGrid.Node.KeepAliveTimeout", 5); // 5 seconds + _keepAliveThread = new KeepAliveThread(_node, timeout); + _keepAliveThread->start(); // // Start the activator. @@ -551,9 +517,10 @@ NodeService::stop() // // Terminate the registration thread if it was started. // - if(_registrationThread) + if(_keepAliveThread) { - _registrationThread->terminate(); + _keepAliveThread->terminate(); + _keepAliveThread->getThreadControl().join(); } // @@ -570,6 +537,16 @@ NodeService::stop() _activator = 0; + _node->stop(); + + // + // Shutdown the collocated registry. + // + if(_registry) + { + _registry->stop(); + } + return true; } |