anthill.storage
Interface GenericStorage

All Superinterfaces:
Clearable, ResourceManager, Storage
All Known Subinterfaces:
QueryStorage
All Known Implementing Classes:
CmsStorage, LRUKeyStorage, LRUQueryStorage, MemoryStorage, UrlStorage, UrlStorage, UrlStorage

public interface GenericStorage
extends Storage

The GenericStorage represents a generic storage which enforce a simple policy based on a maximum capacity. It contains methods to add, remove and get resources from the storage. You may also inspect the content of the storage using the iterator and check its capacity and usage.

Version:
$Revision: 1.8 $
Author:
Alberto Montresor
, Hein Meling

Field Summary
 
Fields inherited from interface anthill.storage.Storage
DOC_STORAGE, PHR_STORAGE, URL_STORAGE
 
Method Summary
 void addResource(Object key, Resource resource)
          Adds a resource to the storage and associates it to the specified key.
 boolean containsResource(Object key)
          Returns true if the resource associated to key is contained in the storage, false otherwise.
 long getCapacity()
          Returns the initial capacity of this generic storage.
 long getRemainingCapacity()
          Returns the remaining capacity of this generic storage.
 Resource getResource(Object key)
          Returns the resource associated with the specified key.
 Iterator iterator()
          Returns the complete set of resources stored in this storage object using an iterator.
 void removeResource(Object key)
          Removes the resource associated with the specified key from the storage.
 
Methods inherited from interface anthill.util.Clearable
clear
 

Method Detail

getResource

public Resource getResource(Object key)
Returns the resource associated with the specified key. If the key is not associated with any resource, a null value is returned.

Parameters:
key - whose associated resource to retreive.
Returns:
resource with which the specified key is associated.

containsResource

public boolean containsResource(Object key)
Returns true if the resource associated to key is contained in the storage, false otherwise.

Parameters:
key - the key to be searched
Returns:
true if the resource associated to key is contained in the storage

addResource

public void addResource(Object key,
                        Resource resource)
                 throws CapacityException
Adds a resource to the storage and associates it to the specified key. If the remaining capacity of the storage is not sufficient to store the resource, a CapacityException is thrown containing information about the remaining capacity. Method getContentLength() may be invoked on the resource to determine the amount of space required by the resource. In order to be stored on persistent storage, resource must implement the Serializable interface.

Parameters:
key - the key identifying the resource
resource - the resource to be added
Throws:
CapacityException - raised if the given resource object exceeds the total available capacity for this storage.

removeResource

public void removeResource(Object key)
Removes the resource associated with the specified key from the storage.

Parameters:
key - the identifier of the resource to be removed

iterator

public Iterator iterator()
Returns the complete set of resources stored in this storage object using an iterator.

Returns:
iterator representing this storage object, allowing to inspect its content.

getCapacity

public long getCapacity()
Returns the initial capacity of this generic storage.


getRemainingCapacity

public long getRemainingCapacity()
Returns the remaining capacity of this generic storage.