org.mapdb
Class LongConcurrentLRUMap<V>

java.lang.Object
  extended by org.mapdb.LongMap<V>
      extended by org.mapdb.LongConcurrentLRUMap<V>

public class LongConcurrentLRUMap<V>
extends LongMap<V>

A LRU cache implementation based upon ConcurrentHashMap and other techniques to reduce contention and synchronization overhead to utilize multiple CPU cores more effectively.

Note that the implementation does not follow a true LRU (least-recently-used) eviction strategy. Instead it strives to remove least recently used items but when the initial cleanup does not remove enough items to reach the 'acceptableWaterMark' limit, it can remove more items forcefully regardless of access order. MapDB note: reworked to implement LongMap. Original comes from: https://svn.apache.org/repos/asf/lucene/dev/trunk/solr/core/src/java/org/apache/solr/util/ConcurrentLRUCache.java


Nested Class Summary
 
Nested classes/interfaces inherited from class org.mapdb.LongMap
LongMap.LongMapIterator<V>
 
Field Summary
protected  int acceptableWaterMark
           
protected  AtomicLong accessCounter
           
protected  AtomicLong evictionCounter
           
protected  boolean isCleaning
           
protected  int lowerWaterMark
           
protected  LongConcurrentHashMap<org.mapdb.LongConcurrentLRUMap.CacheEntry<V>> map
           
protected  ReentrantLock markAndSweepLock
           
protected  AtomicLong missCounter
           
protected  long oldestEntry
           
protected  AtomicLong putCounter
           
protected  AtomicInteger size
           
protected  int upperWaterMark
           
 
Constructor Summary
LongConcurrentLRUMap(int size, int lowerWatermark)
           
LongConcurrentLRUMap(int upperWaterMark, int lowerWaterMark, int acceptableWatermark, int initialSize)
           
 
Method Summary
 void clear()
          Removes all mappings from this hash map, leaving it empty.
protected  void evictedEntry(long key, V value)
          override this method to get notified about evicted entries
 V get(long key)
          Returns the value of the mapping with the specified key.
 LongMap<org.mapdb.LongConcurrentLRUMap.CacheEntry<V>> getMap()
           
 boolean isEmpty()
          Returns whether this map is empty.
 LongMap.LongMapIterator<V> longMapIterator()
           
 V put(long key, V val)
          Maps the specified key to the specified value.
 V remove(long key)
          Removes the mapping from this map
 int size()
          Returns the number of elements in this map.
 Iterator<V> valuesIterator()
           
 
Methods inherited from class org.mapdb.LongMap
toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

map

protected final LongConcurrentHashMap<org.mapdb.LongConcurrentLRUMap.CacheEntry<V>> map

upperWaterMark

protected final int upperWaterMark

lowerWaterMark

protected final int lowerWaterMark

markAndSweepLock

protected final ReentrantLock markAndSweepLock

isCleaning

protected boolean isCleaning

acceptableWaterMark

protected final int acceptableWaterMark

oldestEntry

protected long oldestEntry

accessCounter

protected final AtomicLong accessCounter

putCounter

protected final AtomicLong putCounter

missCounter

protected final AtomicLong missCounter

evictionCounter

protected final AtomicLong evictionCounter

size

protected final AtomicInteger size
Constructor Detail

LongConcurrentLRUMap

public LongConcurrentLRUMap(int upperWaterMark,
                            int lowerWaterMark,
                            int acceptableWatermark,
                            int initialSize)

LongConcurrentLRUMap

public LongConcurrentLRUMap(int size,
                            int lowerWatermark)
Method Detail

get

public V get(long key)
Description copied from class: LongMap
Returns the value of the mapping with the specified key.

Specified by:
get in class LongMap<V>
Parameters:
key - the key.
Returns:
the value of the mapping with the specified key, or null if no mapping for the specified key is found.

isEmpty

public boolean isEmpty()
Description copied from class: LongMap
Returns whether this map is empty.

Specified by:
isEmpty in class LongMap<V>
Returns:
true if this map has no elements, false otherwise.
See Also:
LongMap.size()

remove

public V remove(long key)
Description copied from class: LongMap
Removes the mapping from this map

Specified by:
remove in class LongMap<V>
Parameters:
key - to remove
Returns:
value contained under this key, or null if value did not exist

put

public V put(long key,
             V val)
Description copied from class: LongMap
Maps the specified key to the specified value.

Specified by:
put in class LongMap<V>
Parameters:
key - the key.
val - the value.
Returns:
the value of any previous mapping with the specified key or null if there was no such mapping.

size

public int size()
Description copied from class: LongMap
Returns the number of elements in this map.

Specified by:
size in class LongMap<V>
Returns:
the number of elements in this map.

valuesIterator

public Iterator<V> valuesIterator()
Specified by:
valuesIterator in class LongMap<V>
Returns:
iterator over values in map

longMapIterator

public LongMap.LongMapIterator<V> longMapIterator()
Specified by:
longMapIterator in class LongMap<V>

clear

public void clear()
Description copied from class: LongMap
Removes all mappings from this hash map, leaving it empty.

Specified by:
clear in class LongMap<V>
See Also:
LongMap.isEmpty(), LongMap.size()

getMap

public LongMap<org.mapdb.LongConcurrentLRUMap.CacheEntry<V>> getMap()

evictedEntry

protected void evictedEntry(long key,
                            V value)
override this method to get notified about evicted entries



Copyright © 2014. All Rights Reserved.