diff options
author | Benoit Foucher <benoit@zeroc.com> | 2006-02-08 15:08:21 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2006-02-08 15:08:21 +0000 |
commit | 3a43c1da619fc434ea2598651dbd8ec07922e3c7 (patch) | |
tree | 7edab64b7725d209545c50ef865ffd6b5181b811 /cpp/src/Ice/LocatorInfo.cpp | |
parent | Fixes to alternate sequence code to get around Sun issues. (diff) | |
download | ice-3a43c1da619fc434ea2598651dbd8ec07922e3c7.tar.bz2 ice-3a43c1da619fc434ea2598651dbd8ec07922e3c7.tar.xz ice-3a43c1da619fc434ea2598651dbd8ec07922e3c7.zip |
Added ice_locatorCacheTimeout(int) and ice_getLocatorCacheTimeout() proxy
methods.
Diffstat (limited to 'cpp/src/Ice/LocatorInfo.cpp')
-rw-r--r-- | cpp/src/Ice/LocatorInfo.cpp | 97 |
1 files changed, 68 insertions, 29 deletions
diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index 6639ad9d355..5daf974dd62 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -92,10 +92,13 @@ IceInternal::LocatorManager::get(const LocatorPrx& loc) if(t == _locatorTables.end()) { t = _locatorTables.insert(_locatorTables.begin(), - pair<const Identity, LocatorTablePtr>(locator->ice_getIdentity(), new LocatorTable())); + pair<const Identity, LocatorTablePtr>(locator->ice_getIdentity(), + new LocatorTable())); } - _tableHint = _table.insert(_tableHint, pair<const LocatorPrx, LocatorInfoPtr>(locator, new LocatorInfo(locator, t->second))); + _tableHint = _table.insert(_tableHint, + pair<const LocatorPrx, LocatorInfoPtr>(locator, + new LocatorInfo(locator, t->second))); } else { @@ -119,21 +122,23 @@ IceInternal::LocatorTable::clear() } bool -IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, vector<EndpointIPtr>& endpoints) const +IceInternal::LocatorTable::getAdapterEndpoints(const string& adapter, int ttl, vector<EndpointIPtr>& endpoints) { + if(ttl == 0) // No locator cache. + { + return false; + } + IceUtil::Mutex::Lock sync(*this); - map<string, vector<EndpointIPtr> >::const_iterator p = _adapterEndpointsMap.find(adapter); + map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter); - if(p != _adapterEndpointsMap.end()) + if(p != _adapterEndpointsMap.end() && checkTTL(p->second.first, ttl)) { - endpoints = p->second; + endpoints = p->second.second; return true; } - else - { - return false; - } + return false; } void @@ -141,7 +146,16 @@ IceInternal::LocatorTable::addAdapterEndpoints(const string& adapter, const vect { IceUtil::Mutex::Lock sync(*this); - _adapterEndpointsMap.insert(make_pair(adapter, endpoints)); + map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter); + + if(p != _adapterEndpointsMap.end()) + { + p->second = make_pair(IceUtil::Time::now(), endpoints); + } + else + { + _adapterEndpointsMap.insert(p, make_pair(adapter, make_pair(IceUtil::Time::now(), endpoints))); + } } vector<EndpointIPtr> @@ -149,13 +163,13 @@ IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter) { IceUtil::Mutex::Lock sync(*this); - map<string, vector<EndpointIPtr> >::iterator p = _adapterEndpointsMap.find(adapter); + map<string, pair<IceUtil::Time, vector<EndpointIPtr> > >::iterator p = _adapterEndpointsMap.find(adapter); if(p == _adapterEndpointsMap.end()) { return vector<EndpointIPtr>(); } - vector<EndpointIPtr> endpoints = p->second; + vector<EndpointIPtr> endpoints = p->second.second; _adapterEndpointsMap.erase(p); @@ -163,28 +177,40 @@ IceInternal::LocatorTable::removeAdapterEndpoints(const string& adapter) } bool -IceInternal::LocatorTable::getProxy(const Identity& id, ObjectPrx& proxy) const +IceInternal::LocatorTable::getProxy(const Identity& id, int ttl, ObjectPrx& proxy) { + if(ttl == 0) // No locator cache + { + return false; + } + IceUtil::Mutex::Lock sync(*this); - map<Identity, ObjectPrx>::const_iterator p = _objectMap.find(id); + map<Identity, pair<IceUtil::Time, ObjectPrx> >::iterator p = _objectMap.find(id); - if(p != _objectMap.end()) + if(p != _objectMap.end() && checkTTL(p->second.first, ttl)) { - proxy = p->second; + proxy = p->second.second; return true; } - else - { - return false; - } + return false; } void IceInternal::LocatorTable::addProxy(const Identity& id, const ObjectPrx& proxy) { IceUtil::Mutex::Lock sync(*this); - _objectMap.insert(make_pair(id, proxy)); + + map<Identity, pair<IceUtil::Time, ObjectPrx> >::iterator p = _objectMap.find(id); + + if(p != _objectMap.end()) + { + p->second = make_pair(IceUtil::Time::now(), proxy); + } + else + { + _objectMap.insert(make_pair(id, make_pair(IceUtil::Time::now(), proxy))); + } } ObjectPrx @@ -192,17 +218,31 @@ IceInternal::LocatorTable::removeProxy(const Identity& id) { IceUtil::Mutex::Lock sync(*this); - map<Identity, ObjectPrx>::iterator p = _objectMap.find(id); + map<Identity, pair<IceUtil::Time, ObjectPrx> >::iterator p = _objectMap.find(id); if(p == _objectMap.end()) { return 0; } - ObjectPrx proxy = p->second; + ObjectPrx proxy = p->second.second; _objectMap.erase(p); return proxy; } +bool +IceInternal::LocatorTable::checkTTL(const IceUtil::Time& time, int ttl) const +{ + assert(ttl != 0); + if (ttl < 0) // TTL = infinite + { + return true; + } + else + { + return IceUtil::Time::now() - time <= IceUtil::Time::seconds(ttl); + } +} + IceInternal::LocatorInfo::LocatorInfo(const LocatorPrx& locator, const LocatorTablePtr& table) : _locator(locator), _table(table) @@ -266,17 +306,16 @@ IceInternal::LocatorInfo::getLocatorRegistry() } vector<EndpointIPtr> -IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, bool& cached) +IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, int ttl, bool& cached) { vector<EndpointIPtr> endpoints; ObjectPrx object; cached = true; - try { if(!ref->getAdapterId().empty()) { - if(!_table->getAdapterEndpoints(ref->getAdapterId(), endpoints)) + if(!_table->getAdapterEndpoints(ref->getAdapterId(), ttl, endpoints)) { cached = false; @@ -291,7 +330,7 @@ IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, bool& ca else { bool objectCached = true; - if(!_table->getProxy(ref->getIdentity(), object)) + if(!_table->getProxy(ref->getIdentity(), ttl, object)) { objectCached = false; object = _locator->findObjectById(ref->getIdentity()); @@ -312,7 +351,7 @@ IceInternal::LocatorInfo::getEndpoints(const IndirectReferencePtr& ref, bool& ca assert(oir); if(!oir->getAdapterId().empty()) { - endpoints = getEndpoints(oir, endpointsCached); + endpoints = getEndpoints(oir, ttl, endpointsCached); } } } |