|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--anthill.nestor.LocalStorage
LocalStorage
is a simple implementation of the Storage
interface, aimed at serving as resource repository for nests during the off-line
simulation. Each LocalStorage
is characterized by its capacity, i.e.
by the number of documents that can be simultaneously maintained in it.
Due to the fact that the capacity is limited, resources are stored
following a last-recently-used (LRU) policy.
This data structure is designed for single-threaded off-line simulation, i.e. its methods are not synchronized.
Field Summary | |
protected int |
capacity
Current capacity (i.e., number of resources) of this storage |
protected java.util.LinkedList |
list
LRU queue |
protected java.util.HashMap |
map
Hash map for obtaining resources |
protected int |
size
Current size (i.e., number of resources currently stored in this storage) |
Constructor Summary | |
LocalStorage(int capacity)
Builds a new empty storage, with the given capacity. |
Method Summary | |
void |
addAntResource(Resource resource)
Add a resource to the storage. |
void |
addClientResource(Resource resource)
Add a resource to the storage. |
void |
clear()
Restores the object to its initial state. |
Resource[] |
getResources(java.lang.Object request)
Returns the Resource objects which satisfy the specified
request. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int size
protected int capacity
protected java.util.LinkedList list
protected java.util.HashMap map
Constructor Detail |
public LocalStorage(int capacity)
capacity
- the number of resources which can be stored in this objectMethod Detail |
public Resource[] getResources(java.lang.Object request)
Resource
objects which satisfy the specified
request. This implementations assumes that a request for a documents
is constituted by a string containing the object itself. If the resource
is present, it is moved to the first position of the LRU queue.getResources
in interface Storage
request
- the request to be satisfiedpublic void addAntResource(Resource resource)
addAntResource
in interface Storage
resource
- the resource to be addedpublic void addClientResource(Resource resource)
addClientResource
in interface Storage
resource
- the resource to be addedpublic void clear()
clear
in interface Clearable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |