This document is a part of the online Horus Documentation, under Horus Object Tools.
There are two classes in HOT, HorusDirectoryServer and HorusDirectoryClient, that provide replicated-directory functionality.
// create a directory-server object and join the group "lapa-dirsvr" HorusDirectoryServer svr("lapa-dirsvr");NOTE: You may start up several copies of HorusDirectoryServer objects simultaneously. That will provide fault-tolerance (through active replication) and load-balancing of read requests.
// lock `key' (returns 1 if succeeds, 0 if fails) int lock(HorusString& key); // unlock `key' void unlock(HorusString& key); // lookup the value of `key' // (returns 1 if succeeds, 0 if fails) int lookup(HorusString& key, HorusBase& value); // install `value' under `key' void install(HorusString& key, HorusBase& value);NOTE: lookup/install operations do not block even if the entry is locked. However, if an entry is locked, a following call to lock will block.
Example:
// Note that in order to be used with HorusDirectory, // Foo must define the stream-like message I/O operators, // void operator>>(HorusMessage&) and // void operator<<(HorusMessage&). class Foo: public HorusBase { public: void operator >> (HorusMessage& msg) { msg << value; } void operator << (HorusMessage& msg) { msg >> value; } .... private: int key, value; }; HorusDirectoryClient dir; // create a directory client object Foo f1, f2; .... HorusString name("foo"); dir.lock(name); // lock the entry of "foo" dir.install(name, f1); // install f1 under name "foo" .... dir.lookup(name, f2); // lookup "foo" into f2 dir.unlock(name); // unlock the entry of "foo" HorusEntity ent; dir.lookup(name, ent); // error! can't put Foo into HorusEntity