Rice Pastry API

rice.persistence
Class MemoryStorage

java.lang.Object
  extended by rice.persistence.MemoryStorage
All Implemented Interfaces:
Catalog, Storage

public class MemoryStorage
extends java.lang.Object
implements Storage

This class is an implementation of Storage which provides in-memory storage. This class is specifically *NOT* designed to provide persistent storage, and simply functions as an enhanced hash table.


Constructor Summary
MemoryStorage(IdFactory factory)
          Builds a MemoryStorage object.
 
Method Summary
 boolean exists(Id id)
          Returns whether or not the provided id exists
 void flush(Continuation c)
          Method which is used to erase all data stored in the Storage.
 java.io.Serializable getMetadata(Id id)
          Returns the metadata associated with the provided object, or null if no metadata exists.
 void getObject(Id id, Continuation c)
          Returns the object identified by the given id, or null if there is no cooresponding object (through receiveResult on c).
 int getSize()
          Returns the number of Ids currently stored in the catalog
 long getTotalSize()
          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.
 void rename(Id oldId, Id newId, Continuation c)
          Renames the given object to the new id.
 IdSet scan()
          Return all objects currently stored by this catalog NOTE: This method blocks so if the behavior of this method changes and no longer stored in memory, this method may be deprecated.
 IdSet scan(IdRange range)
          Return the objects identified by the given range of ids.
 java.util.SortedMap scanMetadata()
          Returns a map which contains keys mapping ids to the associated metadata.
 java.util.SortedMap scanMetadata(IdRange range)
          Returns a map which contains keys mapping ids to the associated metadata.
 java.util.SortedMap scanMetadataValuesHead(java.lang.Object value)
          Returns the submapping of ids which have metadata less than the provided value.
 java.util.SortedMap scanMetadataValuesNull()
          Returns the submapping of ids which have metadata null
 void setMetadata(Id id, java.io.Serializable metadata, Continuation command)
          Updates the metadata stored under the given key to be the provided value.
 void store(Id id, java.io.Serializable metadata, java.io.Serializable obj, Continuation c)
          Stores the object under the key id.
 void unstore(Id id, Continuation c)
          Removes the object from the list of stored objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryStorage

public MemoryStorage(IdFactory factory)
Builds a MemoryStorage object.

Parameters:
factory - The factory to build protocol-specific Ids from.
Method Detail

flush

public void flush(Continuation c)
Method which is used to erase all data stored in the Storage. Use this method with care!

Specified by:
flush in interface Catalog
Parameters:
c - The command to run once done

rename

public void rename(Id oldId,
                   Id newId,
                   Continuation c)
Renames the given object to the new id. This method is potentially faster than store/cache and unstore/uncache.

Specified by:
rename in interface Catalog
Parameters:
oldId - The id of the object in question.
newId - The new id of the object in question.
c - The command to run once the operation is complete

store

public void store(Id id,
                  java.io.Serializable metadata,
                  java.io.Serializable obj,
                  Continuation c)
Stores the object under the key id. If there is already an object under id, that object is replaced. 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.
metadata - The object's metadata
c - The command to run once the operation is complete

unstore

public void unstore(Id id,
                    Continuation c)
Removes the object from the list of stored objects. If the object was not in the cached list in the first place, nothing happens and false is returned. 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

exists

public boolean exists(Id id)
Returns whether or not the provided id exists

Specified by:
exists in interface Catalog
Parameters:
id - The id to check
Returns:
Whether or not the given id is stored

getMetadata

public java.io.Serializable getMetadata(Id id)
Returns the metadata associated with the provided object, or null if no metadata exists. The metadata must be stored in memory, so this operation is guaranteed to be fast and non-blocking.

Specified by:
getMetadata in interface Catalog
Parameters:
id - The id for which the metadata is needed
Returns:
The metadata, or null of non exists

setMetadata

public void setMetadata(Id id,
                        java.io.Serializable metadata,
                        Continuation command)
Updates the metadata stored under the given key to be the provided value. As this may require a disk access, the requestor must also provide a continuation to return the result to.

Specified by:
setMetadata in interface Catalog
Parameters:
id - The id for the metadata
metadata - The metadata to store
c - The command to run once the operation is complete

getObject

public void getObject(Id id,
                      Continuation c)
Returns the object identified by the given id, or null if there is no cooresponding object (through receiveResult on c).

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

scan

public IdSet scan(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 the guys don't fit in memory, this method may be deprecated.

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

scan

public IdSet scan()
Return all objects currently stored by this catalog NOTE: This method blocks so if the behavior of this method changes and no longer stored in memory, this method may be deprecated.

Specified by:
scan in interface Catalog
Returns:
The idset containg the keys

scanMetadata

public java.util.SortedMap scanMetadata(IdRange range)
Returns a map which contains keys mapping ids to the associated metadata.

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

scanMetadata

public java.util.SortedMap scanMetadata()
Returns a map which contains keys mapping ids to the associated metadata.

Specified by:
scanMetadata in interface Catalog
Returns:
The treemap mapping ids to metadata

scanMetadataValuesHead

public java.util.SortedMap scanMetadataValuesHead(java.lang.Object value)
Returns the submapping of ids which have metadata less than the provided value.

Specified by:
scanMetadataValuesHead in interface Catalog
Parameters:
value - The maximal metadata value
Returns:
The submapping

scanMetadataValuesNull

public java.util.SortedMap scanMetadataValuesNull()
Returns the submapping of ids which have metadata null

Specified by:
scanMetadataValuesNull in interface Catalog
Returns:
The submapping

getTotalSize

public long getTotalSize()
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 storage size

getSize

public int getSize()
Returns the number of Ids currently stored in the catalog

Specified by:
getSize in interface Catalog
Returns:
The number of ids in the catalog

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection