diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-06-05 21:29:45 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-06-05 21:29:45 +0000 |
commit | 111dfa101179242b0bc09d0eb34ca92a68083137 (patch) | |
tree | c9074020091b1dbc569a8d1130e4e443f9fbb9c7 /cpp/src | |
parent | Bloody VC7 and aggregate initialization :-( (diff) | |
download | ice-111dfa101179242b0bc09d0eb34ca92a68083137.tar.bz2 ice-111dfa101179242b0bc09d0eb34ca92a68083137.tar.xz ice-111dfa101179242b0bc09d0eb34ca92a68083137.zip |
Added Evictor::saveObject
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Freeze/EvictorI.cpp | 33 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.h | 1 | ||||
-rw-r--r-- | cpp/src/Freeze/StrategyI.cpp | 45 | ||||
-rw-r--r-- | cpp/src/Freeze/StrategyI.h | 16 |
4 files changed, 90 insertions, 5 deletions
diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp index e440f823c26..317a7d5584e 100644 --- a/cpp/src/Freeze/EvictorI.cpp +++ b/cpp/src/Freeze/EvictorI.cpp @@ -166,6 +166,32 @@ Freeze::EvictorI::createObject(const Identity& ident, const ObjectPtr& servant) } void +Freeze::EvictorI::saveObject(const Identity& ident) +{ + IceUtil::Mutex::Lock sync(*this); + + if(_deactivated) + { + throw EvictorDeactivatedException(__FILE__, __LINE__); + } + + map<Identity, EvictorElementPtr>::iterator p = _evictorMap.find(ident); + if(p == _evictorMap.end()) + { + throw ObjectDestroyedException(__FILE__, __LINE__); + } + EvictorElementPtr element = p->second; + assert(!element->destroyed); + + // + // TODO: another lookup is not very efficient! + // + save(ident, element->rec.servant); + + _strategy->savedObject(this, ident, element->rec.servant, element->strategyCookie, element->usageCount); +} + +void Freeze::EvictorI::destroyObject(const Identity& ident) { IceUtil::Mutex::Lock sync(*this); @@ -544,6 +570,13 @@ Freeze::EvictorDeactivatedException::ice_print(ostream& out) const out << ":\nunknown local exception"; } +void +Freeze::ObjectDestroyedException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nunknown local exception"; +} + Freeze::EvictorIteratorI::EvictorIteratorI(const IdentityObjectRecordDict::const_iterator& begin, const IdentityObjectRecordDict::const_iterator& end) : _curr(begin), diff --git a/cpp/src/Freeze/EvictorI.h b/cpp/src/Freeze/EvictorI.h index 8323e0de291..61428981bcf 100644 --- a/cpp/src/Freeze/EvictorI.h +++ b/cpp/src/Freeze/EvictorI.h @@ -40,6 +40,7 @@ public: virtual Ice::Int getSize(); virtual void createObject(const Ice::Identity&, const Ice::ObjectPtr&); + virtual void saveObject(const Ice::Identity&); virtual void destroyObject(const Ice::Identity&); virtual void installServantInitializer(const ServantInitializerPtr&); diff --git a/cpp/src/Freeze/StrategyI.cpp b/cpp/src/Freeze/StrategyI.cpp index a9156955df8..b6034c04061 100644 --- a/cpp/src/Freeze/StrategyI.cpp +++ b/cpp/src/Freeze/StrategyI.cpp @@ -44,6 +44,7 @@ Freeze::EvictionStrategyI::evictedObject(const ObjectStorePtr& store, // CookiePtr c = CookiePtr::dynamicCast(cookie); assert(c); + if(c->mutated) { store->save(ident, servant); @@ -51,6 +52,25 @@ Freeze::EvictionStrategyI::evictedObject(const ObjectStorePtr& store, } } + +void +Freeze::EvictionStrategyI::savedObject(const ObjectStorePtr& store, + const Identity& ident, + const ObjectPtr& servant, + const LocalObjectPtr& cookie, + Ice::Int usageCount) +{ + assert(usageCount > 0); + + if(usageCount == 1) + { + CookiePtr c = CookiePtr::dynamicCast(cookie); + assert(c); + c->mutated = false; + } +} + + void Freeze::EvictionStrategyI::preOperation(const ObjectStorePtr& store, const Identity& ident, @@ -100,9 +120,9 @@ Freeze::IdleStrategyI::destroyedObject(const Identity& ident, const LocalObjectP void Freeze::IdleStrategyI::evictedObject(const ObjectStorePtr& store, - const Identity& ident, - const ObjectPtr& servant, - const LocalObjectPtr& cookie) + const Identity& ident, + const ObjectPtr& servant, + const LocalObjectPtr& cookie) { // // The object must reach the idle state in order for it to be @@ -115,6 +135,25 @@ Freeze::IdleStrategyI::evictedObject(const ObjectStorePtr& store, } void +Freeze::IdleStrategyI::savedObject(const ObjectStorePtr& store, + const Identity& ident, + const ObjectPtr& servant, + const LocalObjectPtr& cookie, + Ice::Int usageCount) +{ + assert(usageCount > 0); + + if(usageCount == 1) + { + CookiePtr c = CookiePtr::dynamicCast(cookie); + assert(c); + c->mutated = false; + } +} + + + +void Freeze::IdleStrategyI::preOperation(const ObjectStorePtr& store, const Identity& ident, const ObjectPtr& servant, diff --git a/cpp/src/Freeze/StrategyI.h b/cpp/src/Freeze/StrategyI.h index 5f10ee2df90..6ea188821d7 100644 --- a/cpp/src/Freeze/StrategyI.h +++ b/cpp/src/Freeze/StrategyI.h @@ -39,6 +39,12 @@ public: const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); + virtual void savedObject(const ObjectStorePtr&, + const Ice::Identity&, + const Ice::ObjectPtr&, + const Ice::LocalObjectPtr&, + Ice::Int); + virtual void preOperation(const ObjectStorePtr&, const Ice::Identity&, const Ice::ObjectPtr&, @@ -57,7 +63,7 @@ private: struct Cookie : public Ice::LocalObject { - bool mutated; + bool mutated; }; typedef IceUtil::Handle<Cookie> CookiePtr; }; @@ -76,6 +82,12 @@ public: const Ice::ObjectPtr&, const Ice::LocalObjectPtr&); + virtual void savedObject(const ObjectStorePtr&, + const Ice::Identity&, + const Ice::ObjectPtr&, + const Ice::LocalObjectPtr&, + Ice::Int); + virtual void preOperation(const ObjectStorePtr&, const Ice::Identity&, const Ice::ObjectPtr&, @@ -94,7 +106,7 @@ private: struct Cookie : public Ice::LocalObject { - bool mutated; + bool mutated; Ice::Int mutatingCount; }; typedef IceUtil::Handle<Cookie> CookiePtr; |