Rice Pastry API

rice.persistence
Class PersistentStorage

java.lang.Object
  |
  +--rice.persistence.PersistentStorage
All Implemented Interfaces:
Catalog, Storage

public class PersistentStorage
extends java.lang.Object
implements Storage

This class is an implementation of Storage which provides persistent storage to disk. This class also guarentees that the data will be consistent, even after a crash. This class also provides these services is a non-blocking fashion by launching a seperate thread which is tasked with actaully writing the data to disk.


Constructor Summary
PersistentStorage(rice.p2p.commonapi.IdFactory factory, java.lang.String rootDir, int size)
          Builds a PersistentStorage given a root directory in which to persist the data.
PersistentStorage(rice.p2p.commonapi.IdFactory factory, java.lang.String name, java.lang.String rootDir, int size)
          Builds a PersistentStorage given and an instance name and a root directoy in which to persist the data.
 
Method Summary
 boolean exists(rice.p2p.commonapi.Id id)
          Returns whether or not an object is present in the location id.
 void exists(rice.p2p.commonapi.Id id, rice.Continuation c)
          Returns whether or not an object is present in the location id.
 void getObject(rice.p2p.commonapi.Id id, rice.Continuation c)
          Returns the object identified by the given id.
 java.lang.String getRoot()
          gets the root directory that the persistence Manager uses
 long getStorageSize()
          gets the amount of storage that the persistence Manager uses
 void getTotalSize(rice.Continuation c)
          Returns the total size of the stored data in bytes.The result is returned via the receiveResult method on the provided Continuation with an Integer representing the size.
 rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
          Return the objects identified by the given range of ids.
 void scan(rice.p2p.commonapi.IdRange range, rice.Continuation c)
          Return the objects identified by the given range of ids.
 boolean setRoot(java.lang.String dir)
          Sets the root directory that the persistence Manager uses
 boolean setStorageSize(int size)
          Sets the amount of storage that the persistence Manager uses
 void store(rice.p2p.commonapi.Id id, java.io.Serializable obj, rice.Continuation c)
          Makes the object persistent to disk and stored permanantly If the object is already persistent, this method will simply update the object's serialized image.
 void unstore(rice.p2p.commonapi.Id id, rice.Continuation c)
          Request to remove the object from the list of persistend objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentStorage

public PersistentStorage(rice.p2p.commonapi.IdFactory factory,
                         java.lang.String rootDir,
                         int size)
Builds a PersistentStorage given a root directory in which to persist the data. Uses a default instance name.

Parameters:
factory - The factory to use for creating Ids.
rootDir - The root directory of the persisted disk.
size - the size of the storage in bytes

PersistentStorage

public PersistentStorage(rice.p2p.commonapi.IdFactory factory,
                         java.lang.String name,
                         java.lang.String rootDir,
                         int size)
Builds a PersistentStorage given and an instance name and a root directoy in which to persist the data.

Parameters:
factory - The factory to use for creating Ids.
name - the name of this instance
rootDir - The root directory of the persisted disk.
size - the size of the storage in bytes
Method Detail

store

public void store(rice.p2p.commonapi.Id id,
                  java.io.Serializable obj,
                  rice.Continuation c)
Makes the object persistent to disk and stored permanantly If the object is already persistent, this method will simply update the object's serialized image. This is implemented atomically so that this may succeed and store the new object, or fail and leave the previous object intact. This method completes by calling recieveResult() of the provided continuation with the success or failure of the operation.

Specified by:
store in interface Storage
Parameters:
obj - The object to be made persistent.
id - The object's id.
c - The command to run once the operation is complete
Returns:
true if the action succeeds, else false.

unstore

public void unstore(rice.p2p.commonapi.Id id,
                    rice.Continuation c)
Request to remove the object from the list of persistend objects. Delete the serialized image of the object from stable storage. If necessary. If the object was not in the cached list in the first place, nothing happens and false is returned. This method also guarantees that the data on disk will remain consistent, even after a crash by performing the delete atomically. This method completes by calling recieveResult() of the provided continuation with the success or failure of the operation.

Specified by:
unstore in interface Storage
Parameters:
id - The object's persistence id
c - The command to run once the operation is complete
Returns:
true if the action succeeds, else false.

exists

public boolean exists(rice.p2p.commonapi.Id id)
Returns whether or not an object is present in the location id.

Specified by:
exists in interface Catalog
Parameters:
id - The id of the object in question.
Returns:
Whether or not an object is present at id.

exists

public void exists(rice.p2p.commonapi.Id id,
                   rice.Continuation c)
Returns whether or not an object is present in the location id. The result is returned via the receiveResult method on the provided Continuation with an Boolean represnting the result.

Specified by:
exists in interface Catalog
Parameters:
c - The command to run once the operation is complete
id - The id of the object in question.
Returns:
Whether or not an object is present at id.

getObject

public void getObject(rice.p2p.commonapi.Id id,
                      rice.Continuation c)
Returns the object identified by the given id.

Specified by:
getObject in interface Catalog
Parameters:
id - The id of the object in question.
c - The command to run once the operation is complete
Returns:
The object, or null if there is no cooresponding object (through receiveResult on c).

scan

public void scan(rice.p2p.commonapi.IdRange range,
                 rice.Continuation c)
Return the objects identified by the given range of ids. The IdSet returned contains the Ids of the stored objects. The range is partially inclusive, the lower range is inclusive, and the upper exclusive. When the operation is complete, the receiveResult() method is called on the provided continuation with an IdSet result containing the resulting IDs.

Specified by:
scan in interface Catalog
Parameters:
range - The range to query
c - The command to run once the operation is complete
Returns:
The idset containg the keys

scan

public rice.p2p.commonapi.IdSet scan(rice.p2p.commonapi.IdRange range)
Return the objects identified by the given range of ids. The IdSet returned contains the Ids of the stored objects. The range is partially inclusive, the lower range is inclusive, and the upper exclusive. NOTE: This method blocks so if the behavior of this method changes and uses the disk, this method may be deprecated.

Specified by:
scan in interface Catalog
Parameters:
range - The range to query
Returns:
The idset containg the keys

getTotalSize

public void getTotalSize(rice.Continuation c)
Returns the total size of the stored data in bytes.The result is returned via the receiveResult method on the provided Continuation with an Integer representing the size.

Specified by:
getTotalSize in interface Catalog
Parameters:
c - The command to run once the operation is complete
Returns:
The total size, in bytes, of data stored.

setRoot

public boolean setRoot(java.lang.String dir)
Sets the root directory that the persistence Manager uses

Parameters:
dir - the String representing the directory to use
Returns:
boolean, true if the operation suceeds false if it doesn't

getRoot

public java.lang.String getRoot()
gets the root directory that the persistence Manager uses

Returns:
String the directory for the root

getStorageSize

public long getStorageSize()
gets the amount of storage that the persistence Manager uses

Returns:
int the amount of storage in MB allocated for use

setStorageSize

public boolean setStorageSize(int size)
Sets the amount of storage that the persistence Manager uses

Parameters:
size - the amount of storage available to use in MB
Returns:
boolean, true if the operation suceeds false if it doesn't

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection