diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-09-06 15:39:41 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-09-06 15:39:41 +0000 |
commit | 6f46bb760b30ef883b386dfa8e695c8d5004f05f (patch) | |
tree | c3dabd2d404b72a8e4ad16996a913ceee963815e /cpp/src/IceGrid/ReplicaCache.cpp | |
parent | Fixed bug 1209 (diff) | |
download | ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.tar.bz2 ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.tar.xz ice-6f46bb760b30ef883b386dfa8e695c8d5004f05f.zip |
The master now waits for the replicas to be updated before to return.
Added support for dynamic registration of adapters in the replicas.
Diffstat (limited to 'cpp/src/IceGrid/ReplicaCache.cpp')
-rw-r--r-- | cpp/src/IceGrid/ReplicaCache.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/ReplicaCache.cpp b/cpp/src/IceGrid/ReplicaCache.cpp index f411e170730..e60fd1a21e8 100644 --- a/cpp/src/IceGrid/ReplicaCache.cpp +++ b/cpp/src/IceGrid/ReplicaCache.cpp @@ -89,6 +89,24 @@ ReplicaCache::remove(const string& name) out << "replica `" << name << "' down"; } } + + { + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_waitForUpdatesMonitor); + map<string, set<string> >::iterator p = _waitForUpdates.begin(); + while(p != _waitForUpdates.end()) + { + p->second.erase(name); + if(p->second.empty()) + { + _waitForUpdates.erase(p++); + _waitForUpdatesMonitor.notifyAll(); + } + else + { + ++p; + } + } + } try { @@ -172,6 +190,61 @@ ReplicaCache::getEndpoints(const string& name, const Ice::ObjectPrx& proxy) cons return _communicator->stringToProxy("dummy")->ice_endpoints(endpoints); } +void +ReplicaCache::waitForUpdateReplication(const string& name, int serial) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_waitForUpdatesMonitor); + + vector<string> replicas = getAll(""); + if(replicas.empty()) + { + return; + } + + ostringstream os; + os << name << "-" << serial; + const string key = os.str(); + + _waitForUpdates.insert(make_pair(key, set<string>(replicas.begin(), replicas.end()))); + + // + // Wait until all the updates are received. + // + while(true) + { + map<string, set<string> >::const_iterator p = _waitForUpdates.find(key); + if(p == _waitForUpdates.end()) + { + return; + } + else + { + _waitForUpdatesMonitor.wait(); + } + } +} + +void +ReplicaCache::replicaReceivedUpdate(const string& name, const string& update, int serial) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_waitForUpdatesMonitor); + + ostringstream os; + os << update << "-" << serial; + const string key = os.str(); + + map<string, set<string> >::iterator p = _waitForUpdates.find(key); + if(p != _waitForUpdates.end()) + { + p->second.erase(name); + if(p->second.empty()) + { + _waitForUpdates.erase(p); + _waitForUpdatesMonitor.notifyAll(); + } + } +} + ReplicaEntry::ReplicaEntry(const std::string& name, const ReplicaSessionIPtr& session) : _name(name), _session(session) |