|
SolarMetric Kodo JDO 3.0.3 generated on February 20 2004 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--kodo.util.CacheMap
A map that keeps hard references to a fixed number of elements and moves expired references to a soft reference map. Additionally, objects that are pinned are not counted towards the max size of the map. This implementation is thread-safe.
Inner classes inherited from class java.util.Map |
Map.Entry |
Field Summary | |
protected org.apache.commons.logging.Log |
_log
The log to write to. |
protected serp.util.LRUMap |
_lruMap
The map for non-expired and pinned references. |
protected HashMap |
_pinnedMap
The set of objects pinned into the cache. |
protected serp.util.SoftValueMap |
_softMap
The map for expired references. |
Constructor Summary | |
CacheMap()
Create a new CacheMap with an initial maximum
unpinned object size of 1000. |
|
CacheMap(int size)
Create a new CacheMap with an initial and maximum
unpinned object size of size . |
|
CacheMap(int size,
float load)
Create a new CacheMap with an initial and maximum
unpinned object size of size and a load factor of
load . |
|
CacheMap(int size,
float load,
int max)
Create a new CacheMap with an initial unpinned object
size of size , a load factory of load , and a
maximum unpinned object size of max . |
Method Summary | |
void |
clear()
Removes pinned objects as well as unpinned ones. |
boolean |
containsKey(Object o)
|
boolean |
containsValue(Object o)
|
Set |
entrySet()
|
protected void |
flush()
Remove unpinned items from the end of the LRU cache until the LRU cache size is less than or equal to the maximum. |
Object |
get(Object key)
|
int |
getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to. |
boolean |
getKeepSoftReferences()
Returns whether or not this cache will keep soft references when objects expire. |
org.apache.commons.logging.Log |
getLog()
The log to write to. |
Set |
getPinnedKeys()
Returns the keys to the objects currently pinned into memory. |
int |
getSoftReferenceSize()
Returns the maximum number of unpinned objects to keep soft references to. |
boolean |
isEmpty()
|
protected void |
keyRemoved(Object key,
boolean expired)
Invoked when a key-value pair is evicted from this data structure. |
Set |
keySet()
|
boolean |
pin(Object key)
Locks the key-value pair identified by key
into the map. |
Object |
put(Object key,
Object value)
|
void |
putAll(Map map)
|
Object |
remove(Object key)
If key is pinned into the cache, the pin is
cleared and the object is removed. |
void |
setCacheSize(int size)
Sets the maximum number of unpinned objects to keep hard references to. |
void |
setKeepSoftReferences(boolean val)
Configures whether or not this cache will keep soft references when objects expire. |
void |
setLog(org.apache.commons.logging.Log log)
The log to write to. |
void |
setSoftReferenceSize(int size)
Sets the maximum number of unpinned objects to keep soft references to. |
int |
size()
|
boolean |
unpin(Object key)
Removes the key-value pair identified by key from
the set of pinned objects. |
Collection |
values()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Map |
equals, hashCode |
Field Detail |
protected final serp.util.SoftValueMap _softMap
protected final serp.util.LRUMap _lruMap
protected final HashMap _pinnedMap
protected org.apache.commons.logging.Log _log
Constructor Detail |
public CacheMap()
CacheMap
with an initial maximum
unpinned object size of 1000.public CacheMap(int size)
CacheMap
with an initial and maximum
unpinned object size of size
.public CacheMap(int size, float load)
CacheMap
with an initial and maximum
unpinned object size of size
and a load factor of
load
.public CacheMap(int size, float load, int max)
CacheMap
with an initial unpinned object
size of size
, a load factory of load
, and a
maximum unpinned object size of max
.Method Detail |
public org.apache.commons.logging.Log getLog()
public void setLog(org.apache.commons.logging.Log log)
public void setCacheSize(int size)
size
, then this method will result in the cache
flushing old values. If this is -1
, the cache
will never be flushed.public int getCacheSize()
public void setSoftReferenceSize(int size)
size
, then this method will result in the cache
flushing some of the soft references. If this is
-1
, the cache will store a limitless number of
soft references. Defaults to -1
.public int getSoftReferenceSize()
public void setKeepSoftReferences(boolean val)
public boolean getKeepSoftReferences()
public Set getPinnedKeys()
public boolean pin(Object key)
Locks the key-value pair identified by key
into the map. Objects pinned into the map are not counted
towards the maximum size of the map, and are never removed
except by explicit calls to remove(java.lang.Object)
or
clear()
.
If a key that is not currently in the cache is pinned, it will not be considered pinned once that key is used in the cache.
true
if key
's value was
pinned into the cache; false
if the
key is not in the cache.public boolean unpin(Object key)
key
from
the set of pinned objects. This key becomes a candidate for
removal from the LRU map if the map exceeds the maximum size.true
if key
's value was
unpinned from the cache; false
if the
key is not in the cache.protected void flush()
protected void keyRemoved(Object key, boolean expired)
Invoked when a key-value pair is evicted from this data
structure. This is invoked with expired
set to
true
when an object is dropped because of space
requirements or through garbage collection of soft
references. It is invoked with expired
set to
false
when an object is explicitly removed via
the remove
or clear()
methods.
This may be invoked more than once for a given key.
public Object get(Object key)
get
in interface Map
public Object put(Object key, Object value)
put
in interface Map
public void putAll(Map map)
putAll
in interface Map
public Object remove(Object key)
key
is pinned into the cache, the pin is
cleared and the object is removed.remove
in interface Map
public void clear()
keyRemoved
to be invoked.clear
in interface Map
public int size()
size
in interface Map
public boolean isEmpty()
isEmpty
in interface Map
public boolean containsKey(Object o)
containsKey
in interface Map
public boolean containsValue(Object o)
containsValue
in interface Map
public Set keySet()
keySet
in interface Map
public Collection values()
values
in interface Map
public Set entrySet()
entrySet
in interface Map
|
SolarMetric Kodo JDO 3.0.3 generated on February 20 2004 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |