diff options
author | Bernard Normier <bernard@zeroc.com> | 2003-11-25 20:34:55 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2003-11-25 20:34:55 +0000 |
commit | b3165c39f075d54ec310b23166bea90e40540b0e (patch) | |
tree | d9c7eedeba9131611e3f9959f4b2fe27c8790da3 /cpp | |
parent | More Freeze tracing (diff) | |
download | ice-b3165c39f075d54ec310b23166bea90e40540b0e.tar.bz2 ice-b3165c39f075d54ec310b23166bea90e40540b0e.tar.xz ice-b3165c39f075d54ec310b23166bea90e40540b0e.zip |
Added support for re-indexing
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/Freeze/phonebook/Collocated.cpp | 18 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ContactFactory.cpp | 19 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ContactFactory.h | 14 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBookI.cpp | 12 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBookI.h | 8 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Server.cpp | 18 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/config | 2 | ||||
-rw-r--r-- | cpp/src/Freeze/SharedDb.cpp | 4 |
8 files changed, 67 insertions, 28 deletions
diff --git a/cpp/demo/Freeze/phonebook/Collocated.cpp b/cpp/demo/Freeze/phonebook/Collocated.cpp index c7bb8a6a411..d2d4a9d8689 100644 --- a/cpp/demo/Freeze/phonebook/Collocated.cpp +++ b/cpp/demo/Freeze/phonebook/Collocated.cpp @@ -14,6 +14,8 @@ #include <Ice/Application.h> #include <ContactFactory.h> +#include <NameIndex.h> +#include <PhoneBookI.h> #include <Parser.h> using namespace std; @@ -48,6 +50,12 @@ PhoneBookCollocated::run(int argc, char* argv[]) PropertiesPtr properties = communicator()->getProperties(); // + // Create and install a factory for contacts. + // + ContactFactoryPtr contactFactory = new ContactFactory(); + communicator()->addObjectFactory(contactFactory, "::Contact"); + + // // Create the name index. // NameIndexPtr index = new NameIndex("name"); @@ -65,6 +73,8 @@ PhoneBookCollocated::run(int argc, char* argv[]) evictor->setSize(evictorSize); } + contactFactory->setEvictor(evictor); + // // Create an Object Adapter, use the Evictor as Servant Locator. // @@ -74,16 +84,10 @@ PhoneBookCollocated::run(int argc, char* argv[]) // // Create the phonebook, and add it to the Object Adapter. // - PhoneBookIPtr phoneBook = new PhoneBookI(evictor, index); + PhoneBookIPtr phoneBook = new PhoneBookI(evictor, contactFactory, index); adapter->add(phoneBook, stringToIdentity("phonebook")); // - // Create and install a factory for contacts. - // - ObjectFactoryPtr contactFactory = new ContactFactory(evictor); - communicator()->addObjectFactory(contactFactory, "::Contact"); - - // // Everything ok, let's go. // int runParser(int, char*[], const CommunicatorPtr&); diff --git a/cpp/demo/Freeze/phonebook/ContactFactory.cpp b/cpp/demo/Freeze/phonebook/ContactFactory.cpp index cda6adc5df6..112f4364485 100644 --- a/cpp/demo/Freeze/phonebook/ContactFactory.cpp +++ b/cpp/demo/Freeze/phonebook/ContactFactory.cpp @@ -13,13 +13,13 @@ // ********************************************************************** #include <ContactFactory.h> +#include <PhoneBookI.h> using namespace std; using namespace Ice; using namespace Freeze; -ContactFactory::ContactFactory(const Freeze::EvictorPtr& evictor) : - _evictor(evictor) +ContactFactory::ContactFactory() { } @@ -27,7 +27,7 @@ ObjectPtr ContactFactory::create(const string& type) { assert(type == "::Contact"); - return new ContactI(_evictor); + return new ContactI(this); } void @@ -38,3 +38,16 @@ ContactFactory::destroy() // _evictor = 0; } + +void +ContactFactory::setEvictor(const Freeze::EvictorPtr& evictor) +{ + _evictor = evictor; +} + +const Freeze::EvictorPtr& +ContactFactory::getEvictor() const +{ + return _evictor; +} + diff --git a/cpp/demo/Freeze/phonebook/ContactFactory.h b/cpp/demo/Freeze/phonebook/ContactFactory.h index 0c783e0844f..c1d3f03c4b3 100644 --- a/cpp/demo/Freeze/phonebook/ContactFactory.h +++ b/cpp/demo/Freeze/phonebook/ContactFactory.h @@ -15,14 +15,13 @@ #ifndef CONTACT_FACTORY_H #define CONTACT_FACTORY_H -#include <PhoneBookI.h> -#include <NameIndex.h> +#include <Freeze/Freeze.h> class ContactFactory : virtual public Ice::ObjectFactory { public: - ContactFactory(const Freeze::EvictorPtr&); + ContactFactory(); // // Operations from ObjectFactory @@ -30,9 +29,18 @@ public: virtual Ice::ObjectPtr create(const std::string&); virtual void destroy(); + void + setEvictor(const Freeze::EvictorPtr&); + + const Freeze::EvictorPtr& + getEvictor() const; + + private: Freeze::EvictorPtr _evictor; }; +typedef IceUtil::Handle<ContactFactory> ContactFactoryPtr; + #endif diff --git a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp index 9e3ddae0d9e..388fa9ab006 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp +++ b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp @@ -18,8 +18,8 @@ using namespace std; using namespace Ice; -ContactI::ContactI(const Freeze::EvictorPtr& evictor) : - _evictor(evictor) +ContactI::ContactI(const ContactFactoryPtr& contactFactory) : + _factory(contactFactory) { } @@ -71,7 +71,7 @@ ContactI::destroy(const Ice::Current& c) IceUtil::RWRecMutex::RLock sync(*this); try { - _evictor->destroyObject(c.id); + _factory->getEvictor()->destroyObject(c.id); } catch(const Freeze::DatabaseException& ex) { @@ -81,8 +81,10 @@ ContactI::destroy(const Ice::Current& c) } } -PhoneBookI::PhoneBookI(const Freeze::EvictorPtr& evictor, const NameIndexPtr& index) : +PhoneBookI::PhoneBookI(const Freeze::EvictorPtr& evictor, const ContactFactoryPtr& contactFactory, + const NameIndexPtr& index) : _evictor(evictor), + _contactFactory(contactFactory), _index(index) { } @@ -119,7 +121,7 @@ PhoneBookI::createContact(const Ice::Current& c) // // Create a new Contact Servant. // - ContactIPtr contact = new ContactI(_evictor); + ContactIPtr contact = new ContactI(_contactFactory); // // Create a new Ice Object in the evictor, using the new identity diff --git a/cpp/demo/Freeze/phonebook/PhoneBookI.h b/cpp/demo/Freeze/phonebook/PhoneBookI.h index 13487b8f367..90595856546 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBookI.h +++ b/cpp/demo/Freeze/phonebook/PhoneBookI.h @@ -20,6 +20,7 @@ #include <Freeze/Freeze.h> #include <PhoneBook.h> #include <NameIndex.h> +#include <ContactFactory.h> class PhoneBookI; typedef IceUtil::Handle<PhoneBookI> PhoneBookIPtr; @@ -32,7 +33,7 @@ class ContactI : public Contact, { public: - ContactI(const Freeze::EvictorPtr&); + ContactI(const ContactFactoryPtr&); virtual std::string getName(const Ice::Current&) const; virtual void setName(const std::string&, const Ice::Current&); @@ -47,14 +48,14 @@ public: private: - Freeze::EvictorPtr _evictor; + ContactFactoryPtr _factory; }; class PhoneBookI : public PhoneBook { public: - PhoneBookI(const Freeze::EvictorPtr& evictor, const NameIndexPtr& index); + PhoneBookI(const Freeze::EvictorPtr& evictor, const ContactFactoryPtr& factory, const NameIndexPtr& index); virtual ContactPrx createContact(const Ice::Current&); virtual Contacts findContacts(const std::string&, const Ice::Current&) const; @@ -64,6 +65,7 @@ public: private: Freeze::EvictorPtr _evictor; + ContactFactoryPtr _contactFactory; NameIndexPtr _index; }; diff --git a/cpp/demo/Freeze/phonebook/Server.cpp b/cpp/demo/Freeze/phonebook/Server.cpp index 6e1ca0fca9c..19623a48f98 100644 --- a/cpp/demo/Freeze/phonebook/Server.cpp +++ b/cpp/demo/Freeze/phonebook/Server.cpp @@ -14,6 +14,8 @@ #include <Ice/Application.h> #include <ContactFactory.h> +#include <NameIndex.h> +#include <PhoneBookI.h> using namespace std; using namespace Ice; @@ -47,6 +49,12 @@ PhoneBookServer::run(int argc, char* argv[]) PropertiesPtr properties = communicator()->getProperties(); // + // Create and install a factory for contacts. + // + ContactFactoryPtr contactFactory = new ContactFactory(); + communicator()->addObjectFactory(contactFactory, "::Contact"); + + // // Create the name index. // NameIndexPtr index = new NameIndex("name"); @@ -63,6 +71,8 @@ PhoneBookServer::run(int argc, char* argv[]) { evictor->setSize(evictorSize); } + + contactFactory->setEvictor(evictor); // // Create an object adapter, use the evictor as servant locator. @@ -73,16 +83,10 @@ PhoneBookServer::run(int argc, char* argv[]) // // Create the phonebook, and add it to the object adapter. // - PhoneBookIPtr phoneBook = new PhoneBookI(evictor, index); + PhoneBookIPtr phoneBook = new PhoneBookI(evictor, contactFactory, index); adapter->add(phoneBook, stringToIdentity("phonebook")); // - // Create and install a factory for contacts. - // - ObjectFactoryPtr contactFactory = new ContactFactory(evictor); - communicator()->addObjectFactory(contactFactory, "::Contact"); - - // // Everything ok, let's go. // shutdownOnInterrupt(); diff --git a/cpp/demo/Freeze/phonebook/config b/cpp/demo/Freeze/phonebook/config index 8584db36212..d6e8d6874c7 100644 --- a/cpp/demo/Freeze/phonebook/config +++ b/cpp/demo/Freeze/phonebook/config @@ -4,6 +4,8 @@ Ice.Warn.Connections=1 Freeze.Trace.Evictor=2 Freeze.Trace.DbEnv=2 +Freeze.Evictor.db.contacts.SavePeriod=10000 +Freeze.Evictor.db.contacts.PopulateEmptyIndices=1 PhoneBook.Endpoints=default -p 10000 PhoneBook.Proxy=phonebook:default -p 10000 diff --git a/cpp/src/Freeze/SharedDb.cpp b/cpp/src/Freeze/SharedDb.cpp index 19e88243a29..7cba35768f6 100644 --- a/cpp/src/Freeze/SharedDb.cpp +++ b/cpp/src/Freeze/SharedDb.cpp @@ -166,6 +166,9 @@ Freeze::SharedDb::SharedDb(const MapKey& key, out << "opening Db \"" << _key.dbName << "\""; } + // set_pagesize(1024); + + try { u_int32_t flags = DB_AUTO_COMMIT | DB_THREAD; @@ -174,6 +177,7 @@ Freeze::SharedDb::SharedDb(const MapKey& key, flags |= DB_CREATE; } open(0, key.dbName.c_str(), 0, DB_BTREE, flags, FREEZE_DB_MODE); + set_cache_priority(DB_PRIORITY_VERY_HIGH); } catch(const ::DbException& dx) { |