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

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
              extended by org.apache.camel.util.LRUCache<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, Service
Direct Known Subclasses:
LRUSoftCache

public class LRUCache<K,V>
extends LinkedHashMap<K,V>
implements Service

A Least Recently Used Cache

Version:
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
LRUCache(int maximumCacheSize)
           
LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder)
          Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.
 
Method Summary
 V get(Object o)
           
 long getHits()
          Gets the number of cache hits
 int getMaxCacheSize()
          Returns the maxCacheSize.
 long getMisses()
          Gets the number of cache misses.
protected  boolean removeEldestEntry(Map.Entry<K,V> entry)
           
 void resetStatistics()
          Rest the cache statistics such as hits and misses.
 void start()
          Starts the service
 void stop()
          Stops the service
 String toString()
           
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

LRUCache

public LRUCache(int maximumCacheSize)

LRUCache

public LRUCache(int initialCapacity,
                int maximumCacheSize,
                float loadFactor,
                boolean accessOrder)
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.
loadFactor - the load factor.
accessOrder - the ordering mode - true for access-order, false for insertion-order.
Throws:
IllegalArgumentException - if the initial capacity is negative or the load factor is non positive.
Method Detail

get

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

getHits

public long getHits()
Gets the number of cache hits


getMisses

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


getMaxCacheSize

public int getMaxCacheSize()
Returns the maxCacheSize.


resetStatistics

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


removeEldestEntry

protected boolean removeEldestEntry(Map.Entry<K,V> entry)
Overrides:
removeEldestEntry in class LinkedHashMap<K,V>

start

public void start()
           throws Exception
Description copied from interface: Service
Starts the service

Specified by:
start in interface Service
Throws:
Exception - is thrown if starting failed

stop

public void stop()
          throws Exception
Description copied from interface: Service
Stops the service

Specified by:
stop in interface Service
Throws:
Exception - is thrown if stopping failed

toString

public String toString()
Overrides:
toString in class AbstractMap<K,V>


Apache CAMEL