|
Purple Code | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.util.AbstractMap
|
+--com.purpletech.util.TimeoutMap
A Map that eventually times out (removes) its elements.
The constructor automatically starts a background (daemon) thread to handle expiry.
You may pass in an existing Map as backing store; this could be, e.g., a WeakHashMap, or a Map that knows how to load its contents from elsewhere.
You may subclass the following methods:
| Nested Class Summary | |
static class |
TimeoutMap.Info
Information about an entry in the cache. |
| Field Summary | |
protected long |
tempo
|
protected long |
timeout
|
| Constructor Summary | |
TimeoutMap()
Allow this object to create its own backing store. |
|
TimeoutMap(long timeout)
|
|
TimeoutMap(java.util.Map contents)
Pass this constructor an implementation instance (for SortedMap, e.g.) -- does *not* follow conventions for java.util.Map, which would make a copy of the passed Map's contents. |
|
TimeoutMap(java.util.Map contents,
long timeout)
|
|
| Method Summary | |
java.util.Set |
entrySet()
|
protected boolean |
expire(java.lang.Object key,
TimeoutMap.Info info,
long now)
Subclasses should override this to provide their own expiration heuristic. |
java.lang.Object |
get(java.lang.Object key)
Get an item from the cache. |
long |
getAccessed(java.lang.Object key)
Convenience method to get the time this key's data was last accessed |
java.lang.Object |
getClean(java.lang.Object key)
Get an item from the cache. |
long |
getEntered(java.lang.Object key)
Convenience method to get the time this key's data was entered into the cache. |
TimeoutMap.Info |
getInfo(java.lang.Object key)
Get all information about this cache entry, including the times it was accessed and entered. |
int |
getSize()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object data)
Add an item to the cache explicitly. |
java.lang.Object |
remove(java.lang.Object key)
Explicitly remove item from cache |
void |
run()
|
void |
setTempo(long msec)
|
void |
setTimeout(long msec)
|
| Methods inherited from class java.util.AbstractMap |
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected long timeout
protected long tempo
| Constructor Detail |
public TimeoutMap()
public TimeoutMap(java.util.Map contents)
public TimeoutMap(long timeout)
public TimeoutMap(java.util.Map contents,
long timeout)
| Method Detail |
public void setTimeout(long msec)
msec - the maximum time an item can sit in the cache without being accessed before it gets removedpublic void setTempo(long msec)
msec - the time that the expiry thread sleeps before waking up and checking for expirable items (hence "tempo")public java.util.Set entrySet()
entrySet in interface java.util.MapentrySet in class java.util.AbstractMap
public java.lang.Object put(java.lang.Object key,
java.lang.Object data)
put in interface java.util.Mapput in class java.util.AbstractMappublic java.lang.Object get(java.lang.Object key)
get in interface java.util.Mapget in class java.util.AbstractMappublic java.lang.Object getClean(java.lang.Object key)
public TimeoutMap.Info getInfo(java.lang.Object key)
public long getEntered(java.lang.Object key)
public long getAccessed(java.lang.Object key)
public int getSize()
public java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Mapremove in class java.util.AbstractMappublic void run()
run in interface java.lang.Runnable
protected boolean expire(java.lang.Object key,
TimeoutMap.Info info,
long now)
key - key of object we're looking atinfo - info of object we're looking atnow - current system time
|
Documentation generated March 5 2003 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||