diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-19 05:45:46 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-19 05:45:46 +0000 |
commit | ee8d48c4267fcf61854f566c52e9a519168f36d3 (patch) | |
tree | 60fced55f088e7ad00365bc0b598b2fba50fe67d /cpp/src | |
parent | slice2docbook fixes, Evictor for Freeze (diff) | |
download | ice-ee8d48c4267fcf61854f566c52e9a519168f36d3.tar.bz2 ice-ee8d48c4267fcf61854f566c52e9a519168f36d3.tar.xz ice-ee8d48c4267fcf61854f566c52e9a519168f36d3.zip |
many Freeze fixes
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Freeze/DBI.cpp | 32 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.cpp | 56 | ||||
-rw-r--r-- | cpp/src/Freeze/EvictorI.h | 7 |
3 files changed, 88 insertions, 7 deletions
diff --git a/cpp/src/Freeze/DBI.cpp b/cpp/src/Freeze/DBI.cpp index 6a47191d8cb..80180c1ee83 100644 --- a/cpp/src/Freeze/DBI.cpp +++ b/cpp/src/Freeze/DBI.cpp @@ -258,6 +258,38 @@ Freeze::DBI::del(const string& key) ex.message = s.str(); throw ex; } + + // + // TODO: Do I need transactions for del()? + // + DBT dbKey; + int ret; + + memset(&dbKey, 0, sizeof(dbKey)); + dbKey.data = const_cast<void*>(static_cast<const void*>(key.c_str())); + dbKey.size = key.size(); + + ret = _db->del(_db, 0, &dbKey, 0); + switch (ret) + { + case 0: + { + // + // Everything ok + // + break; + } + + default: + { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "DB->del: " << db_strerror(ret); + DBException ex; + ex.message = s.str(); + throw ex; + } + } } void diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp index d6cc72b47ed..8786c0c994f 100644 --- a/cpp/src/Freeze/EvictorI.cpp +++ b/cpp/src/Freeze/EvictorI.cpp @@ -22,8 +22,41 @@ Freeze::EvictorI::EvictorI(const DBPtr& db) : } void +Freeze::EvictorI::setSize(Int evictorSize) +{ + JTCSyncT<JTCMutex> sync(*this); + + // + // The minimum size is one. + // + if (evictorSize < 1) + { + evictorSize = 1; + } + _evictorSize = static_cast<map<string, EvictorElement>::size_type>(evictorSize); + + // + // Evict elements if necessary + // + if (_evictorMap.size() > _evictorSize) + { + evict(); + } +} + +Int +Freeze::EvictorI::getSize() +{ + JTCSyncT<JTCMutex> sync(*this); + + return static_cast<Int>(_evictorSize); +} + +void Freeze::EvictorI::createObject(const string& identity, const ObjectPtr& servant) { + JTCSyncT<JTCMutex> sync(*this); + // // Save the new Ice Object to the database. // @@ -40,6 +73,8 @@ Freeze::EvictorI::createObject(const string& identity, const ObjectPtr& servant) void Freeze::EvictorI::destroyObject(const string& identity) { + JTCSyncT<JTCMutex> sync(*this); + // // Delete the Ice Object from the database. // @@ -56,8 +91,16 @@ Freeze::EvictorI::destroyObject(const string& identity) } } +void +Freeze::EvictorI::installServantInitializer(const ServantInitializerPtr& initializer) +{ + JTCSyncT<JTCMutex> sync(*this); + + _initializer = initializer; +} + ObjectPtr -Freeze::EvictorI::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) +Freeze::EvictorI::locate(const ObjectAdapterPtr& adapter, const string& identity, ObjectPtr&) { JTCSyncT<JTCMutex> sync(*this); @@ -99,14 +142,13 @@ Freeze::EvictorI::locate(const ObjectAdapterPtr&, const string& identity, Object return 0; } -/* // - // TODO: That's the only PhoneBook specific stuff! + // If an initializer is installed, call it now. // - ContactIPtr entry = ContactIPtr::dynamicCast(servant); - assert(entry); - entry->setIdentity(identity); -*/ + if (_initializer) + { + _initializer->initialize(adapter, identity, servant); + } // // Add the new Ice Object and its Servant diff --git a/cpp/src/Freeze/EvictorI.h b/cpp/src/Freeze/EvictorI.h index 7e4380d4f6a..403d82e617c 100644 --- a/cpp/src/Freeze/EvictorI.h +++ b/cpp/src/Freeze/EvictorI.h @@ -29,9 +29,14 @@ public: EvictorI(const Freeze::DBPtr&); + virtual void setSize(Ice::Int); + virtual Ice::Int getSize(); + virtual void createObject(const std::string&, const Ice::ObjectPtr&); virtual void destroyObject(const std::string&); + virtual void installServantInitializer(const ServantInitializerPtr&); + virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const std::string&, Ice::ObjectPtr&); virtual void finished(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&, const Ice::ObjectPtr&); @@ -52,6 +57,8 @@ private: std::map<std::string, EvictorElement> _evictorMap; std::list<std::string> _evictorList; std::map<std::string, EvictorElement>::size_type _evictorSize; + + ServantInitializerPtr _initializer; }; } |