|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.regionserver.LruHashMap<K,V>
public class LruHashMap<K extends HeapSize,V extends HeapSize>
The LruHashMap is a memory-aware HashMap with a configurable maximum memory footprint.
It maintains an ordered list of all entries in the map ordered by access time. When space needs to be freed becase the maximum has been reached, or the application has asked to free memory, entries will be evicted according to an LRU (least-recently-used) algorithm. That is, those entries which have not been accessed the longest will be evicted first.
Both the Key and Value Objects used for this class must extend
HeapSize
in order to track heap usage.
This class contains internal synchronization and is thread-safe.
Nested Class Summary | |
---|---|
protected static class |
LruHashMap.Entry<K extends HeapSize,V extends HeapSize>
Entry to store key/value mappings. |
Constructor Summary | |
---|---|
LruHashMap()
Constructs a new, empty map with the default initial capacity, load factor and maximum memory usage. |
|
LruHashMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity and with the default load factor and maximum memory usage. |
|
LruHashMap(int initialCapacity,
float loadFactor)
Constructs a new, empty map with the specified initial capacity and load factor, and default maximum memory usage. |
|
LruHashMap(int initialCapacity,
float loadFactor,
long maxMemUsage)
Constructs a new, empty map with the specified initial capacity, load factor, and maximum memory usage. |
|
LruHashMap(long maxMemUsage)
Constructs a new, empty map with the specified maximum memory usage and with default initial capacity and load factor. |
Method Summary | |
---|---|
void |
clear()
Clears all entries from the map. |
boolean |
containsKey(Object key)
Checks whether there is a value in the map for the specified key. |
boolean |
containsValue(Object value)
Checks whether this is a mapping which contains the specified value. |
List<LruHashMap.Entry<K,V>> |
entryLruList()
Debugging function that returns a List sorted by access time. |
Set<Map.Entry<K,V>> |
entrySet()
Intentionally unimplemented. |
Set<LruHashMap.Entry<K,V>> |
entryTableSet()
Debugging function that returns a Set of all entries in the hash table. |
boolean |
equals(Object o)
Intentionally unimplemented. |
long |
freeMemory(long requestedAmount)
Free the requested amount of memory from the LRU map. |
V |
get(Object key)
Retrieves the value associated with the specified key. |
LruHashMap.Entry |
getHeadPtr()
Get the head of the linked list (least recently used). |
long |
getHitCount()
Get the number of hits to the map. |
double |
getHitRatio()
Get the hit ratio. |
long |
getMemFree()
Get the currently available memory for this LRU in bytes. |
long |
getMemMax()
Get the maximum memory allowed for this LRU in bytes. |
long |
getMemUsed()
Get the currently used memory for this LRU in bytes. |
long |
getMissCount()
Get the number of misses to the map. |
LruHashMap.Entry |
getTailPtr()
Get the tail of the linked list (most recently used). |
int |
hashCode()
Intentionally unimplemented. |
long |
heapSize()
The total memory usage of this map |
boolean |
isEmpty()
Checks whether the map is currently empty. |
Set<K> |
keySet()
Intentionally unimplemented. |
V |
put(K key,
V value)
Insert a key-value mapping into the map. |
void |
putAll(Map<? extends K,? extends V> m)
Intentionally unimplemented. |
V |
remove(Object key)
Deletes the mapping for the specified key if it exists. |
int |
size()
Gets the size (number of entries) of the map. |
Collection<V> |
values()
Intentionally unimplemented. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LruHashMap(int initialCapacity, float loadFactor, long maxMemUsage)
initialCapacity
- the initial capacityloadFactor
- the load factormaxMemUsage
- the maximum total memory usage
IllegalArgumentException
- if the initial capacity is less than one
IllegalArgumentException
- if the initial capacity is greater than
the maximum capacity
IllegalArgumentException
- if the load factor is <= 0
IllegalArgumentException
- if the max memory usage is too small
to support the base overheadpublic LruHashMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacityloadFactor
- the load factor
IllegalArgumentException
- if the initial capacity is less than one
IllegalArgumentException
- if the initial capacity is greater than
the maximum capacity
IllegalArgumentException
- if the load factor is <= 0public LruHashMap(int initialCapacity)
initialCapacity
- the initial capacity
IllegalArgumentException
- if the initial capacity is less than one
IllegalArgumentException
- if the initial capacity is greater than
the maximum capacitypublic LruHashMap(long maxMemUsage)
maxMemUsage
- the maximum total memory usage
IllegalArgumentException
- if the max memory usage is too small
to support the base overheadpublic LruHashMap()
Method Detail |
---|
public long getMemFree()
public long getMemMax()
public long getMemUsed()
public long getHitCount()
public long getMissCount()
public double getHitRatio()
public long freeMemory(long requestedAmount) throws Exception
requestedAmount
- memory to free from LRU in bytes
Exception
public long heapSize()
heapSize
in interface HeapSize
public V get(Object key)
get
in interface Map<K extends HeapSize,V extends HeapSize>
key
- the key
NullPointerException
- if key is nullpublic V put(K key, V value)
put
in interface Map<K extends HeapSize,V extends HeapSize>
key
- the keyvalue
- the value
UnsupportedOperationException
- if either objects do not
implement HeapSize
NullPointerException
- if the key or value is nullpublic V remove(Object key)
remove
in interface Map<K extends HeapSize,V extends HeapSize>
key
- the key of the entry to be removed from the map
public int size()
size
in interface Map<K extends HeapSize,V extends HeapSize>
public boolean isEmpty()
isEmpty
in interface Map<K extends HeapSize,V extends HeapSize>
public void clear()
clear
in interface Map<K extends HeapSize,V extends HeapSize>
public boolean containsKey(Object key)
containsKey
in interface Map<K extends HeapSize,V extends HeapSize>
key
- the key to check
NullPointerException
- if the key is nullpublic boolean containsValue(Object value)
containsValue
in interface Map<K extends HeapSize,V extends HeapSize>
value
- the value to check
NullPointerException
- if the value is nullpublic List<LruHashMap.Entry<K,V>> entryLruList()
public Set<LruHashMap.Entry<K,V>> entryTableSet()
public LruHashMap.Entry getHeadPtr()
public LruHashMap.Entry getTailPtr()
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K extends HeapSize,V extends HeapSize>
public boolean equals(Object o)
equals
in interface Map<K extends HeapSize,V extends HeapSize>
equals
in class Object
public int hashCode()
hashCode
in interface Map<K extends HeapSize,V extends HeapSize>
hashCode
in class Object
public Set<K> keySet()
keySet
in interface Map<K extends HeapSize,V extends HeapSize>
public void putAll(Map<? extends K,? extends V> m)
putAll
in interface Map<K extends HeapSize,V extends HeapSize>
public Collection<V> values()
values
in interface Map<K extends HeapSize,V extends HeapSize>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |