The Horus Object Tools: Directory Server

This document is a part of the online Horus Documentation, under Horus Object Tools.


  • In the HOT Directory, data entries are (key, value) pairs. The key is a HorusString object; the value may be an instance of any subclass of HorusBase that supports stream-like message I/O operations.

    There are two classes in HOT, HorusDirectoryServer and HorusDirectoryClient, that provide replicated-directory functionality.

  • The HorusDirectoryServer class implements a directory server. The only public methods of this class are constructors. For example:
    	// 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.

  • The HorusDirectoryClient class implements the functionality of a directory client. It allows to lookup/install and lock/unlock data entries. The public methods are declared as follows:
      	// 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
    

    send mail to alexey@cs.cornell.edu