org.apache.camel.util
Class LRUCache<K,V>

java.lang.Object
  extended by org.apache.camel.util.LRUCache<K,V>
All Implemented Interfaces:
com.googlecode.concurrentlinkedhashmap.EvictionListener<K,V>, Serializable, Map<K,V>
Direct Known Subclasses:
LRUSoftCache, LRUWeakCache

public class LRUCache<K,V>
extends Object
implements Map<K,V>, com.googlecode.concurrentlinkedhashmap.EvictionListener<K,V>, Serializable

A Least Recently Used Cache.

If this cache stores Service then this implementation will on eviction invoke the Service.stop() method, to auto-stop the service.

See Also:
LRUSoftCache, LRUWeakCache, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
LRUCache(int maximumCacheSize)
          Constructs an empty LRUCache instance with the specified maximumCacheSize, and will stop on eviction.
LRUCache(int initialCapacity, int maximumCacheSize)
          Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize, and will stop on eviction.
LRUCache(int initialCapacity, int maximumCacheSize, boolean stopOnEviction)
          Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.
 
Method Summary
 void clear()
           
 boolean containsKey(Object o)
           
 boolean containsValue(Object o)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object o)
           
 long getEvicted()
          Gets the number of evicted entries.
 long getHits()
          Gets the number of cache hits
 int getMaxCacheSize()
          Returns the maxCacheSize.
 long getMisses()
          Gets the number of cache misses.
 boolean isEmpty()
           
 Set<K> keySet()
           
 void onEviction(K key, V value)
           
 V put(K k, V v)
           
 void putAll(Map<? extends K,? extends V> map)
           
 V remove(Object o)
           
 void resetStatistics()
          Rest the cache statistics such as hits and misses.
 int size()
           
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LRUCache

public LRUCache(int maximumCacheSize)
Constructs an empty LRUCache instance with the specified maximumCacheSize, and will stop on eviction.

Parameters:
maximumCacheSize - the max capacity.
Throws:
IllegalArgumentException - if the initial capacity is negative

LRUCache

public LRUCache(int initialCapacity,
                int maximumCacheSize)
Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize, and will stop on eviction.

Parameters:
initialCapacity - the initial capacity.
maximumCacheSize - the max capacity.
Throws:
IllegalArgumentException - if the initial capacity is negative

LRUCache

public LRUCache(int initialCapacity,
                int maximumCacheSize,
                boolean stopOnEviction)
Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.

Parameters:
initialCapacity - the initial capacity.
maximumCacheSize - the max capacity.
stopOnEviction - whether to stop service on eviction.
Throws:
IllegalArgumentException - if the initial capacity is negative
Method Detail

get

public V get(Object o)
Specified by:
get in interface Map<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

containsKey

public boolean containsKey(Object o)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object o)
Specified by:
containsValue in interface Map<K,V>

put

public V put(K k,
             V v)
Specified by:
put in interface Map<K,V>

remove

public V remove(Object o)
Specified by:
remove in interface Map<K,V>

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>

clear

public void clear()
Specified by:
clear in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>

onEviction

public void onEviction(K key,
                       V value)
Specified by:
onEviction in interface com.googlecode.concurrentlinkedhashmap.EvictionListener<K,V>

getHits

public long getHits()
Gets the number of cache hits


getMisses

public long getMisses()
Gets the number of cache misses.


getEvicted

public long getEvicted()
Gets the number of evicted entries.


getMaxCacheSize

public int getMaxCacheSize()
Returns the maxCacheSize.


resetStatistics

public void resetStatistics()
Rest the cache statistics such as hits and misses.


toString

public String toString()
Overrides:
toString in class Object


Apache Camel