ecologylab.generic
Class AutoCleanerMap<KEY,VALUE>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.concurrent.ConcurrentHashMap<KEY,VALUE>
          extended by ecologylab.generic.AutoCleanerMap<KEY,VALUE>
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, java.util.concurrent.ConcurrentMap<KEY,VALUE>, java.util.Map<KEY,VALUE>

public class AutoCleanerMap<KEY,VALUE>
extends java.util.concurrent.ConcurrentHashMap<KEY,VALUE>
implements java.lang.Runnable

This class runs in order to clean out unrefreshed elements of a Map on a specified interval. Access to the Map should go through this object to ensure proper sychonous access. Note that this object will automatically remove elements that have been in the map, and unused, for too long (per the liveTime argument) and will persist for at LEAST as long as the liveTime argument. I'm sure there's a nice mathmematical way to explain it, but each item lasts until the next cleanupInterval...if, at the interval, it has been idle for more than liveTime, it is removed and Java GC will take care of it when it gets around to it. This object automatically starts up a monitoring thread whenever it contains items, and shuts itself off when there are no items.

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
AutoCleanerMap(long liveTime, long cleanupInterval)
           
 
Method Summary
 void access(KEY key)
           
 VALUE get(java.lang.Object key)
          Finds the matching value, calls access for it, then returns it.
 VALUE put(KEY key, VALUE value)
           
 VALUE remove(java.lang.Object key)
           
 void run()
           
 
Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, contains, containsKey, containsValue, elements, entrySet, isEmpty, keys, keySet, putAll, putIfAbsent, remove, replace, replace, size, values
 
Methods inherited from class java.util.AbstractMap
clone, 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
 

Constructor Detail

AutoCleanerMap

public AutoCleanerMap(long liveTime,
                      long cleanupInterval)
Method Detail

get

public VALUE get(java.lang.Object key)
Finds the matching value, calls access for it, then returns it.

Specified by:
get in interface java.util.Map<KEY,VALUE>
Overrides:
get in class java.util.concurrent.ConcurrentHashMap<KEY,VALUE>
See Also:
ConcurrentHashMap.get(java.lang.Object)

put

public VALUE put(KEY key,
                 VALUE value)
Specified by:
put in interface java.util.Map<KEY,VALUE>
Overrides:
put in class java.util.concurrent.ConcurrentHashMap<KEY,VALUE>

remove

public VALUE remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<KEY,VALUE>
Overrides:
remove in class java.util.concurrent.ConcurrentHashMap<KEY,VALUE>

access

public void access(KEY key)

run

public void run()
Specified by:
run in interface java.lang.Runnable