diff options
Diffstat (limited to 'cpp/src/IceGrid/ObjectCache.cpp')
-rw-r--r-- | cpp/src/IceGrid/ObjectCache.cpp | 231 |
1 files changed, 6 insertions, 225 deletions
diff --git a/cpp/src/IceGrid/ObjectCache.cpp b/cpp/src/IceGrid/ObjectCache.cpp index 29132c8c221..c2b58f08833 100644 --- a/cpp/src/IceGrid/ObjectCache.cpp +++ b/cpp/src/IceGrid/ObjectCache.cpp @@ -44,7 +44,7 @@ struct ObjectLoadCI : binary_function<pair<Ice::ObjectPrx, float>&, pair<Ice::Ob }; -ObjectCache::TypeEntry::TypeEntry() : _allocatablesCount(0) +ObjectCache::TypeEntry::TypeEntry() { } @@ -55,12 +55,6 @@ ObjectCache::TypeEntry::add(const ObjectEntryPtr& obj) // No mutex protection here, this is called with the cache locked. // _objects.insert(lower_bound(_objects.begin(), _objects.end(), obj, ObjectEntryCI()), obj); - _allocatablesCount += obj->isAllocatable() ? 1 : 0; - - if(!_requests.empty()) - { - canTryAllocate(obj, false); - } } bool @@ -69,93 +63,25 @@ ObjectCache::TypeEntry::remove(const ObjectEntryPtr& obj) // // No mutex protection here, this is called with the cache locked. // - _allocatablesCount -= obj->isAllocatable() ? 1 : 0; vector<ObjectEntryPtr>::iterator q = lower_bound(_objects.begin(), _objects.end(), obj, ObjectEntryCI()); assert(q->get() == obj.get()); _objects.erase(q); - - if(!_requests.empty() && !_allocatablesCount) - { - for(list<ObjectAllocationRequestPtr>::const_iterator p = _requests.begin(); p != _requests.end(); ++p) - { - (*p)->cancel(AllocationException("no allocatable objects with type `" + obj->getType() + "' registered")); - } - } return _objects.empty(); } -void -ObjectCache::TypeEntry::addAllocationRequest(const ObjectAllocationRequestPtr& request) -{ - // - // No mutex protection here, this is called with the cache locked. - // - assert(_allocatablesCount); - if(request->pending()) - { - _requests.push_back(request); - } -} - -bool -ObjectCache::TypeEntry::canTryAllocate(const ObjectEntryPtr& entry, bool fromRelease) -{ - // - // No mutex protection here, this is called with the cache locked. - // - list<ObjectAllocationRequestPtr>::iterator p = _requests.begin(); - while(p != _requests.end()) - { - AllocationRequestPtr request = *p; - try - { - if(request->isCanceled()) // If the request has been canceled, we just remove it. - { - p = _requests.erase(p); - } - else if(entry->tryAllocate(request, fromRelease)) - { - p = _requests.erase(p); - return true; // The request successfully allocated the entry! - } - else if(entry->getSession()) // If entry is allocated, we're done - { - return false; - } - else - { - ++p; - } - } - catch(const SessionDestroyedException&) - { - p = _requests.erase(p); - } - } - return false; -} - -bool -ObjectCache::TypeEntry::hasAllocatables() const -{ - return _allocatablesCount; -} - -ObjectCache::ObjectCache(const Ice::CommunicatorPtr& communicator, AdapterCache& adapterCache) : - _communicator(communicator), - _adapterCache(adapterCache) +ObjectCache::ObjectCache(const Ice::CommunicatorPtr& communicator) : _communicator(communicator) { } void -ObjectCache::add(const ObjectInfo& info, const string& application, bool allocatable, const AllocatablePtr& parent) +ObjectCache::add(const ObjectInfo& info, const string& application) { const Ice::Identity& id = info.proxy->ice_getIdentity(); Lock sync(*this); assert(!getImpl(id)); - ObjectEntryPtr entry = new ObjectEntry(*this, info, application, allocatable, parent); + ObjectEntryPtr entry = new ObjectEntry(*this, info, application); addImpl(id, entry); map<string, TypeEntry>::iterator p = _types.find(entry->getType()); @@ -207,51 +133,6 @@ ObjectCache::remove(const Ice::Identity& id) return entry; } -void -ObjectCache::allocateByType(const string& type, const ObjectAllocationRequestPtr& request) -{ - Lock sync(*this); - map<string, TypeEntry>::iterator p = _types.find(type); - if(p == _types.end() || !p->second.hasAllocatables()) - { - throw AllocationException("no allocatable objects with type `" + type + "' registered"); - } - - vector<ObjectEntryPtr> objects = p->second.getObjects(); - random_shuffle(objects.begin(), objects.end(), _rand); // TODO: OPTIMIZE - try - { - for(vector<ObjectEntryPtr>::const_iterator q = objects.begin(); q != objects.end(); ++q) - { - if((*q)->tryAllocate(request)) - { - return; - } - } - } - catch(const SessionDestroyedException&) - { - return; - } - - p->second.addAllocationRequest(request); -} - -bool -ObjectCache::canTryAllocate(const ObjectEntryPtr& entry) -{ - // - // Notify the type entry that an object was released. - // - Lock sync(*this); - map<string, TypeEntry>::iterator p = _types.find(entry->getType()); - if(p == _types.end()) - { - return false; - } - return p->second.canTryAllocate(entry, true); -} - Ice::ObjectProxySeq ObjectCache::getObjectsByType(const string& type) { @@ -304,16 +185,10 @@ ObjectCache::getAllByType(const string& type) return infos; } -ObjectEntry::ObjectEntry(ObjectCache& cache, - const ObjectInfo& info, - const string& application, - bool allocatable, - const AllocatablePtr& parent) : - Allocatable(allocatable, parent), +ObjectEntry::ObjectEntry(ObjectCache& cache, const ObjectInfo& info, const string& application) : _cache(cache), _info(info), - _application(application), - _destroyed(false) + _application(application) { } @@ -347,97 +222,3 @@ ObjectEntry::canRemove() return true; } -void -ObjectEntry::allocated(const SessionIPtr& session) -{ - // - // Add the object allocation to the session. The object will be - // released once the session is destroyed. - // - session->addAllocation(this); - - TraceLevelsPtr traceLevels = _cache.getTraceLevels(); - if(traceLevels && traceLevels->object > 1) - { - Ice::Trace out(traceLevels->logger, traceLevels->objectCat); - const Ice::Identity id = _info.proxy->ice_getIdentity(); - out << "object `" << _cache.communicator()->identityToString(id) << "' allocated by `" << session->getId() - << "' (" << _count << ")"; - } - - Glacier2::SessionControlPrx ctl = session->getSessionControl(); - if(ctl) - { - try - { - Ice::IdentitySeq seq(1); - seq.push_back(_info.proxy->ice_getIdentity()); - ctl->identities()->add(seq); - } - catch(const Ice::ObjectNotExistException&) - { - } - } -} - -void -ObjectEntry::released(const SessionIPtr& session) -{ - // - // Remove the object allocation from the session. - // - session->removeAllocation(this); - - Glacier2::SessionControlPrx ctl = session->getSessionControl(); - if(ctl) - { - try - { - Ice::IdentitySeq seq(1); - seq.push_back(_info.proxy->ice_getIdentity()); - ctl->identities()->remove(seq); - } - catch(const Ice::ObjectNotExistException&) - { - } - } - - TraceLevelsPtr traceLevels = _cache.getTraceLevels(); - if(traceLevels && traceLevels->object > 1) - { - Ice::Trace out(traceLevels->logger, traceLevels->objectCat); - const Ice::Identity id = _info.proxy->ice_getIdentity(); - out << "object `" << _cache.communicator()->identityToString(id) << "' released by `" << session->getId() - << "' (" << _count << ")"; - } -} - -void -ObjectEntry::destroy() -{ - SessionIPtr session; - { - Lock sync(*this); - _destroyed = true; - session = _session; - } - release(session); -} - -void -ObjectEntry::checkAllocatable() -{ - if(_destroyed) - { - throw ObjectNotRegisteredException(_info.proxy->ice_getIdentity()); - } - - Allocatable::checkAllocatable(); -} - -bool -ObjectEntry::canTryAllocate() -{ - return _cache.canTryAllocate(this); -} - |