|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sofya.graphs.GraphCache
public abstract class GraphCache
Abstract base implementation of a disk backed soft memory cache for graphs produced by the Sofya system.
A least recently used (LRU) policy is used to move graphs from memory to disk files when a minimum free memory threshold is crossed. It is the responsibility of subclasses to implement the methods responsible for actually serializing graphs of a particular type to file.
Nested Class Summary | |
---|---|
static class |
GraphCache.CachedGraph
Container class used to encapsulate a cached graph and its associated status for passing to external users of the cache. |
Constructor Summary | |
---|---|
GraphCache()
Creates a new graph cache with a default minimum memory threshold and disk caching policy. |
|
GraphCache(int initRemoveNum)
Creates a new graph cache with a default minimum memory threshold which immediately caches a given number of graphs to disk when the threshold is passed. |
|
GraphCache(int initRemoveNum,
float lowMemThreshold)
Creates a new graph cache which immediately caches the specified number of graphs when the given minimum memory threshold is passed. |
Method Summary | |
---|---|
void |
clear()
Clears the cache. |
boolean |
containsKey(MethodSignature method)
Reports whether the cache contains a mapping for a given key. |
GraphCache.CachedGraph |
get(MethodSignature method)
Gets a graph from the cache. |
java.util.Collection |
getForClass(java.lang.String className)
Gets all of the graphs in the cache for a given class. |
java.util.Iterator |
iterator()
Gets an iterator over the graphs in the cache. |
java.util.Iterator |
iterator(java.lang.String className)
Gets an iterator over the graphs in the cache which are associated with a specified class. |
java.util.Set |
keySet()
Gets the key set for the cache, in no particular order. |
java.util.Set |
keySet(java.lang.String className)
Gets the key set consisting of the keys for all graphs in the cache associated with a particular class, in no particular order. |
GraphCache.CachedGraph |
put(MethodSignature method,
Graph g)
Adds a new graph to the cache. |
protected abstract Graph |
readFromDisk(MethodSignature method)
Reads a graph from a disk cache file. |
boolean |
remove(MethodSignature method)
Removes a graph from the cache. |
int |
size()
Gets the number of graphs currently in the cache. |
java.util.Iterator |
sortedIterator()
Gets a sorted iterator over the graphs in the cache. |
java.util.Iterator |
sortedIterator(java.lang.String className)
Gets a sorted iterator over the graphs in the cache which are associated with a specified class. |
protected abstract void |
writeToDisk(MethodSignature method,
Graph g)
Writes a graph to a disk cache file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GraphCache()
public GraphCache(int initRemoveNum)
initRemoveNum
- Number of graphs to immediately cache to disk
when available memory falls below the minimum threshold. Higher
values may improve performance by immediately clearing more memory
and thus reducing the frequency with which the cache must search
for and cache eligible graphs.public GraphCache(int initRemoveNum, float lowMemThreshold)
initRemoveNum
- Number of graphs to immediately cache to disk
when available memory falls below the minimum threshold. Higher
values may improve performance by immediately clearing more memory
and thus reducing the frequency with which the cache must search
for and cache eligible graphs.lowMemThreshold
- Minimum free memory, as a percentage of total
memory, that the cache must attempt to keep free. Setting this value
too high may result in disk thrashing.Method Detail |
---|
public GraphCache.CachedGraph put(MethodSignature method, Graph g) throws CacheException
This action may result in existing graphs being cached to disk, if the addition of the new graph causes free memory to drop below the minimum threshold.
method
- Signature of the method for which a graph is being
cached, used as the key to retrieve the graph later.g
- Graph being added to the cache.
GraphCache.CachedGraph
which can be used to modify
the publicly visible status of the graph. The graph itself cannot be
accessed through this object (GraphCache.CachedGraph.getGraph()
will return null
) since the existence of a strong
reference would prevent it from being removed from memory. The
get(sofya.base.MethodSignature)
method should be used instead to retrieve the
graph.
CacheException
- If the operation results in an attempt to
cache graphs to disk, and that operation fails for any reason.public GraphCache.CachedGraph get(MethodSignature method) throws CacheException
The graph will be read from disk, if necessary. This method may also result in graphs being cached to disk, if the retrieval of the current graph causes free memory to fall below the minimum threshold.
method
- Signature of the method for which to retrieve a
graph.
GraphCache.CachedGraph
which may be used to
access the graph and modify the publicly visible status of the graph.
CacheException
- If no graph exists in the cache for the
requested method, or if the graph must be read from a cache file
and that operation fails for any reason.public boolean remove(MethodSignature method)
method
- Signature of the method for which the graph is
to be removed.
true
if a graph was found for the method
and successfully removed, false
otherwise.public void clear()
public int size()
public java.util.Collection getForClass(java.lang.String className)
className
- Name of the class for which to retrieve all of
its graphs.
java.lang.OutOfMemoryError
- If there is not enough space in memory to hold
all of the graphs. For this reason, it is recommended that graphs instead
be retrieved using either a direct iterator or by iterating over the
key set.public java.util.Set keySet()
public java.util.Set keySet(java.lang.String className) throws CacheException
className
- Name of the class for which the keys of
associated graphs are to be retrieved.
CacheException
- If no graphs associated with the given
class are found in the cache.public boolean containsKey(MethodSignature method)
method
- Method signature which is the key for which to check
if a mapping exists in the cache.
true
if the cache contains a mapping for the
given key, false
otherwise.public java.util.Iterator iterator()
public java.util.Iterator sortedIterator()
The order of iteration is consistent with the lexical ordering of the names of the methods with which the graphs are associated.
MethodSignature.NameComparator
public java.util.Iterator iterator(java.lang.String className) throws CacheException
className
- Name of the class with which the graphs returned
by the iterator should be associated.
CacheException
public java.util.Iterator sortedIterator(java.lang.String className) throws CacheException
The order of iteration is consistent with the lexical ordering of the names of the methods with which the graphs are associated.
className
- Name of the class with which the graphs returned by
the iterator should be associated.
CacheException
MethodSignature.NameComparator
protected abstract Graph readFromDisk(MethodSignature method) throws CacheException
method
- Signature of the method for which the graph is to be
read back from a disk cache file.
CacheException
- If no disk cache file exists for the specified
method, or if cache file is unreadable or invalid.protected abstract void writeToDisk(MethodSignature method, Graph g) throws CacheException
method
- Signature of the method for which the graph is to be
written to disk.g
- Graph which is to be written to disk.
CacheException
- If the cache file cannot be created, or if
there is a problem writing the graph to the file.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |