backtype.storm.utils
Class TimeCacheMap<K,V>

java.lang.Object
  extended by backtype.storm.utils.TimeCacheMap<K,V>

public class TimeCacheMap<K,V>
extends java.lang.Object

Expires keys that have not been updated in the configured number of seconds. The algorithm used will take between expirationSecs and expirationSecs * (1 + 1 / (numBuckets-1)) to actually expire the message. get, put, remove, containsKey, and size take O(numBuckets) time to run. The advantage of this design is that the expiration thread only locks the object for O(1) time, meaning the object is essentially always available for gets/puts.


Nested Class Summary
static interface TimeCacheMap.ExpiredCallback<K,V>
           
 
Constructor Summary
TimeCacheMap(int expirationSecs)
           
TimeCacheMap(int expirationSecs, int numBuckets)
           
TimeCacheMap(int expirationSecs, int numBuckets, TimeCacheMap.ExpiredCallback<K,V> callback)
           
TimeCacheMap(int expirationSecs, TimeCacheMap.ExpiredCallback<K,V> callback)
           
 
Method Summary
 boolean containsKey(K key)
           
protected  void finalize()
           
 V get(K key)
           
 void put(K key, V value)
           
 java.lang.Object remove(K key)
           
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeCacheMap

public TimeCacheMap(int expirationSecs,
                    int numBuckets,
                    TimeCacheMap.ExpiredCallback<K,V> callback)

TimeCacheMap

public TimeCacheMap(int expirationSecs,
                    TimeCacheMap.ExpiredCallback<K,V> callback)

TimeCacheMap

public TimeCacheMap(int expirationSecs)

TimeCacheMap

public TimeCacheMap(int expirationSecs,
                    int numBuckets)
Method Detail

containsKey

public boolean containsKey(K key)

get

public V get(K key)

put

public void put(K key,
                V value)

remove

public java.lang.Object remove(K key)

size

public int size()

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable