Interface horb.orb.ObjectStorage
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Interface horb.orb.ObjectStorage

public interface ObjectStorage
extends Object
ObjectStorage is an (very simple) object database. It provides saving, loading objects and file locking.

If you want to have a system ObjectStorage, start it from a configuration file.

  sample.conf:
	object[0].className=horb.orb.ObjectStorage
	object[0].implementation=horb.orb.ObjectStorage_Impl
	object[0].objectID=ObjectStorage
  command line:
	horb -conf sample.conf
This object storage can be accessed as;
  local:
	ObjectStorage os = (ObjectStorage)HORBServer.getObject("ObjectStorage");
	os.saveObject(obj, "obj.fof");
  remote:
	ObjectStorage os = new ObjectStorage_Proxy(new HorbURL("horb://host/ObjectStorage"));
	os.saveObject(obj, "obj.fof");

Method Index

 o copy(String, String)
copy a file from fname1 to fname2.
 o delete(String)
delete a file.
 o exists(String)
Returns true if the file exists.
 o isLocked(String)
Returns locking condition of a file.
 o loadObject(String)
returns an object from a given filename.
 o lock(String, long)
get lock of a file.
 o makeTemporaryFileName()
returns a temporary filename.
 o rename(String, String)
rename a file.
 o saveObject(Object, String)
save an object as a given filename.
 o unlock(String)
Unlock file.

Methods

 o saveObject
  public abstract String saveObject(Object obj,
                                    String fname) throws HORBException, IOException
save an object as a given filename. Caution for security.

If a client does not give a filename, a temporary file is created and the filename is returned. If a client gives a filename, the filename may not include ".." in it and it may not be an absolute path. Thus filenames must be relative filename, for example, "data.fof" or "directory/data.fof". If ObjectStorage_Impl was instantiated with a directory name, the directory name is prepended to the filename.

Parameters:
fname - filename.
Returns:
filename.
See Also:
ObjectStorage_Impl
 o loadObject
  public abstract Object loadObject(String fname) throws HORBException, IOException
returns an object from a given filename. Caution for security.

Filename may not include ".." in it and it may not be an absolute path. Thus filenames must be relative filename, for example, "data.fof" or "directory/data.fof".

Parameters:
fname - filename.
Returns:
object saved in fname.
 o lock
  public abstract boolean lock(String fname,
                               long timeout) throws HORBException
get lock of a file. The file may not be exist yet.

This locking system runs on memory, that is, the locking is valid while the HORB server is running.

Here is an example of atomic update of an object.

  HorbURL url = new HorbURL(host, "ObjectStorage");
  ObjectStorage_Proxy os = new ObjectStorage_Proxy(url);
  os.lock(file, 0);
  Data data = os.loadObject(file);
  data.update();
  os.saveObject(data, file);
  os.unlock(file);
 o unlock
  public abstract void unlock(String fname) throws IllegalMonitorStateException
Unlock file. Unlocking should be done within the same session (connection). Once you lock a file from a proxy object of ObjectStorage, the lock should be released before releasing the connection of the proxy object.

If someone is waiting for the file, unlocking gives the next lock to the someone.

Parameters:
fname - filename to be unlocked.
Throws: IllegalMonitorStateException
if the current client is not the owner of the lock.
 o isLocked
  public abstract boolean isLocked(String fname)
Returns locking condition of a file. If you need atomic test and set, don't use this method. Use lock() instead of this.
Parameters:
fname - filename to be unlocked.
Throws: IllegalMonitorStateException
if the current client is not the owner of the lock.
 o delete
  public abstract boolean delete(String fname) throws HORBException, IOException
delete a file. Returns true if the file was deleted.
 o rename
  public abstract boolean rename(String fname1,
                                 String fname2) throws HORBException, IOException
rename a file. Returns true if the file could be renamed.
 o copy
  public abstract void copy(String fname1,
                            String fname2) throws IOException
copy a file from fname1 to fname2. Lock files before calling copy(), if needed.
 o makeTemporaryFileName
  public abstract String makeTemporaryFileName()
returns a temporary filename.
 o exists
  public abstract boolean exists(String fname) throws HORBException, IOException
Returns true if the file exists.

All Packages  Class Hierarchy  This Package  Previous  Next  Index