|
Knopflerfish OSGi 2.4.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap
org.knopflerfish.util.CacheMap
public class CacheMap
Timeout version of a HashMap
.
Entries in the map have a limited lifelength, and the get
method will only return the stored object during a limited time period.
After the timeout period, thr object will be removed.
CachedObject
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Field Summary | |
---|---|
protected long |
timeout
|
Constructor Summary | |
---|---|
CacheMap()
Create a map with default timeout period. |
|
CacheMap(long timeout)
Create a map with a specified timeout period. |
Method Summary | |
---|---|
boolean |
containsKey(java.lang.Object key)
Check if an object exists in the map. |
java.lang.Object |
get(java.lang.Object key)
Get an object from the map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Store an object in the map. |
void |
update()
Force timeout check on all items in map and remove all expired keys and objects. |
Methods inherited from class java.util.HashMap |
---|
clear, clone, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Field Detail |
---|
protected long timeout
Constructor Detail |
---|
public CacheMap()
Equivalent to CacheMap(CachedObject.DEFAULT_TIMEOUT)
CachedObject.DEFAULT_TIMEOUT
,
CachedObject
public CacheMap(long timeout)
After an object has been stored in the map using put
, it
will only be available for timeout
milliseconds. After
that period, get
will return null
timeout
- timeout period in milliseconds for cached objects.Method Detail |
---|
public java.lang.Object get(java.lang.Object key)
null
.
Note: Since the timeout check is done for each cached object, be
careful when looping over a map using iterators or other sequences of
get
. The result from a new get
can become
null
faster than you might think. Thus always
check for null
return values from get
.
get
in interface java.util.Map
get
in class java.util.HashMap
public boolean containsKey(java.lang.Object key)
false
.
containsKey
in interface java.util.Map
containsKey
in class java.util.HashMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.HashMap
public void update()
Normally, the timeout check is only done at get
calls, but
if necessary (for example at periodic complete printouts or before loops)
you can (and probably want to) force a timeout check on all cached
objects.
|
Knopflerfish OSGi 2.4.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |