diff options
author | Benoit Foucher <benoit@zeroc.com> | 2004-08-14 02:27:40 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2004-08-14 02:27:40 +0000 |
commit | a1cb0798dffe02820fc6e8d4ee0884331075707a (patch) | |
tree | 7f277f5dd8548ca9878be5c545c1c11e18452a16 /cpp/src | |
parent | Ice.StdErr and Ice.StdOut (diff) | |
download | ice-a1cb0798dffe02820fc6e8d4ee0884331075707a.tar.bz2 ice-a1cb0798dffe02820fc6e8d4ee0884331075707a.tar.xz ice-a1cb0798dffe02820fc6e8d4ee0884331075707a.zip |
Fixed deadlock that would occur if multiple nodes were started at the same
time.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePack/AdapterRegistryI.cpp | 3 | ||||
-rw-r--r-- | cpp/src/IcePack/NodeRegistryI.cpp | 79 |
2 files changed, 45 insertions, 37 deletions
diff --git a/cpp/src/IcePack/AdapterRegistryI.cpp b/cpp/src/IcePack/AdapterRegistryI.cpp index 1f34ee5e6e8..c0e43498a76 100644 --- a/cpp/src/IcePack/AdapterRegistryI.cpp +++ b/cpp/src/IcePack/AdapterRegistryI.cpp @@ -100,7 +100,8 @@ IcePack::AdapterRegistryI::findById(const string& id, const Ice::Current&) { try { - return AdapterPrx::checkedCast(p->second->ice_collocationOptimization(false)); + p->second->ice_ping(); + return AdapterPrx::uncheckedCast(p->second->ice_collocationOptimization(false)); } catch(const Ice::ObjectNotExistException&) { diff --git a/cpp/src/IcePack/NodeRegistryI.cpp b/cpp/src/IcePack/NodeRegistryI.cpp index 14d75679d79..8485dfb03a4 100644 --- a/cpp/src/IcePack/NodeRegistryI.cpp +++ b/cpp/src/IcePack/NodeRegistryI.cpp @@ -48,47 +48,57 @@ IcePack::NodeRegistryI::NodeRegistryI(const Ice::CommunicatorPtr& communicator, } void -IcePack::NodeRegistryI::add(const string& name, const NodePrx& node, const Ice::Current&) +IcePack::NodeRegistryI::add(const string& name, const NodePrx& node, const Ice::Current& current) { - IceUtil::Mutex::Lock sync(*this); - - Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); - StringObjectProxyDict dict(connection, _dbName); - - StringObjectProxyDict::iterator p = dict.find(name); - if(p != dict.end()) + while(true) { + NodePrx oldNode; try { - sync.release(); - p->second->ice_ping(); - sync.acquire(); + oldNode = findByName(name, current); + oldNode->ice_ping(); throw NodeActiveException(); } - catch(const Ice::LocalException&) + catch(const NodeNotExistException& ex) { - // - // Node not active. - // - sync.acquire(); } - p.set(node); + catch(const Ice::LocalException& ex) + { + } + + IceUtil::Mutex::Lock sync(*this); - if(_traceLevels->nodeRegistry > 0) + Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); + StringObjectProxyDict dict(connection, _dbName); + + StringObjectProxyDict::iterator p = dict.find(name); + if(p != dict.end()) { - Ice::Trace out(_traceLevels->logger, _traceLevels->nodeRegistryCat); - out << "updated node `" << name << "' proxy"; + if(oldNode != p->second) + { + continue; + } + + p.set(node); + + if(_traceLevels->nodeRegistry > 0) + { + Ice::Trace out(_traceLevels->logger, _traceLevels->nodeRegistryCat); + out << "updated node `" << name << "' proxy"; + } } - } - else - { - dict.put(pair<const string, const Ice::ObjectPrx>(name, node)); - - if(_traceLevels->nodeRegistry > 0) + else { - Ice::Trace out(_traceLevels->logger, _traceLevels->nodeRegistryCat); - out << "added node `" << name << "'"; + dict.put(pair<const string, const Ice::ObjectPrx>(name, node)); + + if(_traceLevels->nodeRegistry > 0) + { + Ice::Trace out(_traceLevels->logger, _traceLevels->nodeRegistryCat); + out << "added node `" << name << "'"; + } } + + break; } try @@ -96,12 +106,10 @@ IcePack::NodeRegistryI::add(const string& name, const NodePrx& node, const Ice:: _adapterRegistry->findById("IcePack.Node." + name); // - // TODO: ensure this adapter has been created by the adapter - // factory. It's possible that an adapter has been created - // with the same name. In such a case, the best is probably to - // prevent the node registration by throwing an appropriate - // exception. The user would then need to remove the adapter - // from the adapter registry to be able to run the node. + // TODO: ensure this adapter has been created by the adapter factory. It's possible that an + // adapter has been created with the same name. In such a case, the best is probably to + // prevent the node registration by throwing an appropriate exception. The user would then + // need to remove the adapter from the adapter registry to be able to run the node. // } catch(const AdapterNotExistException&) @@ -127,8 +135,7 @@ IcePack::NodeRegistryI::remove(const string& name, const Ice::Current&) IceUtil::Mutex::Lock sync(*this); Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); - StringObjectProxyDict dict(connection, _dbName); - + StringObjectProxyDict dict(connection, _dbName); StringObjectProxyDict::iterator p = dict.find(name); if(p == dict.end()) |