ants.freeant
Class UrlStorage

java.lang.Object
  |
  +--ants.freeant.UrlStorage
All Implemented Interfaces:
Clearable, GenericStorage, QueryStorage, ResourceManager, Storage

public class UrlStorage
extends Object
implements QueryStorage

Implementation of an Least Recently Used (LRU) based URL storage.

Version:
$Revision: 1.4 $
Author:
Hein Meling

Field Summary
protected  String name
          Name used to identify this component in the factory
static String PAR_CAPACITY
          The identifier of the configuration parameter
static String PAR_CONTROLLERNAME
          The identifier of the configuration parameter
 
Fields inherited from interface anthill.storage.Storage
DOC_STORAGE, PHR_STORAGE, URL_STORAGE
 
Constructor Summary
UrlStorage(Factory factory, String name)
           
 
Method Summary
 void addResource(Object key, Resource resource)
          Adds a resource to the storage and associates it to the specified key.
 void clear()
          Restores the object to its initial state.
 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.
 Resource[] getResources(Object query)
          Return the resource associated with the specified query.
 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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAR_CAPACITY

public static final String PAR_CAPACITY
The identifier of the configuration parameter

See Also:
Constant Field Values

PAR_CONTROLLERNAME

public static final String PAR_CONTROLLERNAME
The identifier of the configuration parameter

See Also:
Constant Field Values

name

protected String name
Name used to identify this component in the factory

Constructor Detail

UrlStorage

public UrlStorage(Factory factory,
                  String name)
Parameters:
factory - the factory to be used to read configuration arguments and to create other configurable objects
name - the name that is associated to this instance in the configuration file
Method Detail

clear

public void clear()
Restores the object to its initial state.

Specified by:
clear in interface Clearable

containsResource

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

Specified by:
containsResource in interface GenericStorage
Parameters:
key - the key to be searched
Returns:
true if the resource associated to key is contained in the storage

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.

Specified by:
getResource in interface GenericStorage
Parameters:
key - whose associated resource to retreive.
Returns:
resource with which the specified key is associated.

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 size() 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. This is a specialized implementation that will add URLs pointing to a file with the same resourceKey to a URL resource set before adding that URL set to the storage.

Specified by:
addResource in interface GenericStorage
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.

getResources

public Resource[] getResources(Object query)
Description copied from interface: QueryStorage
Return the resource associated with the specified query.

Specified by:
getResources in interface QueryStorage
Parameters:
query - whose associated resource to retreive.
Returns:
resources found in the storage with which the specified query matched.

removeResource

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

Specified by:
removeResource in interface GenericStorage
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.

Specified by:
iterator in interface GenericStorage
Returns:
iterator representing this storage object, allowing to inspect its content.

getCapacity

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

Specified by:
getCapacity in interface GenericStorage

getRemainingCapacity

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

Specified by:
getRemainingCapacity in interface GenericStorage