|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
org.apache.cayenne.util.concurrentlinkedhashmap.ConcurrentLinkedHashMap<K,V>
K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class ConcurrentLinkedHashMap<K,V>
A hash table supporting full concurrency of retrievals, adjustable expected concurrency
for updates, and a maximum capacity to bound the map by. This implementation differs
from ConcurrentHashMap
in that it maintains a page replacement algorithm that
is used to evict an entry when the map has exceeded its capacity. Unlike the
Java Collections Framework, this map does not have a publicly visible
constructor and instances are created through a ConcurrentLinkedHashMap.Builder
.
An entry is evicted from the map when the weighted capacity exceeds its
maximum weighted capacity threshold. A Weigher
instance determines how
many units of capacity that a value consumes. The default weigher assigns each value a
weight of 1 to bound the map by the total number of key-value pairs. A map
that holds collections may choose to weigh values by the number of elements in the
collection and bound the map by the total number of elements that it contains. A change
to a value that modifies its weight requires that an update operation is performed on
the map.
An EvictionListener
may be supplied for notification when an entry is evicted
from the map. This listener is invoked on a caller's thread and will not block other
threads from operating on the map. An implementation should be aware that the caller's
thread will not expect long execution times or failures as a side effect of the
listener being notified. Execution safety and a fast turn around time can be achieved
by performing the operation asynchronously, such as by submitting a task to an
ExecutorService
.
The concurrency level determines the number of threads that can concurrently modify the table. Using a significantly higher or lower value than needed can waste space or lead to thread contention, but an estimate within an order of magnitude of the ideal value does not usually have a noticeable impact. Because placement in hash tables is essentially random, the actual concurrency will vary.
This class and its views and iterators implement all of the optional methods
of the Map
and Iterator
interfaces.
Like Hashtable
but unlike HashMap
, this class does
not allow null to be used as a key or value. Unlike
LinkedHashMap
, this class does not provide predictable
iteration order. A snapshot of the keys and entries may be obtained in ascending and
descending order of retention.
Nested Class Summary | |
---|---|
static class |
ConcurrentLinkedHashMap.Builder<K,V>
A builder that creates ConcurrentLinkedHashMap instances. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Method Summary | |
---|---|
java.util.Set<K> |
ascendingKeySet()
Returns a unmodifiable snapshot Set view of the keys contained in this map. |
java.util.Set<K> |
ascendingKeySetWithLimit(int limit)
Returns an unmodifiable snapshot Set view of the keys contained in this
map. |
java.util.Map<K,V> |
ascendingMap()
Returns an unmodifiable snapshot Map view of the mappings contained in this
map. |
java.util.Map<K,V> |
ascendingMapWithLimit(int limit)
Returns an unmodifiable snapshot Map view of the mappings contained in this
map. |
int |
capacity()
Retrieves the maximum weighted capacity of the map. |
void |
clear()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set<K> |
descendingKeySet()
Returns an unmodifiable snapshot Set view of the keys contained in this
map. |
java.util.Set<K> |
descendingKeySetWithLimit(int limit)
Returns an unmodifiable snapshot Set view of the keys contained in this
map. |
java.util.Map<K,V> |
descendingMap()
Returns an unmodifiable snapshot Map view of the mappings contained in this
map. |
java.util.Map<K,V> |
descendingMapWithLimit(int limit)
Returns an unmodifiable snapshot Map view of the mappings contained in this
map. |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
V |
get(java.lang.Object key)
|
boolean |
isEmpty()
|
java.util.Set<K> |
keySet()
|
V |
put(K key,
V value)
|
V |
putIfAbsent(K key,
V value)
|
V |
remove(java.lang.Object key)
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
|
V |
replace(K key,
V value)
|
boolean |
replace(K key,
V oldValue,
V newValue)
|
void |
setCapacity(int capacity)
Sets the maximum weighted capacity of the map and eagerly evicts entries until it shrinks to the appropriate size. |
int |
size()
|
java.util.Collection<V> |
values()
|
int |
weightedSize()
Returns the weighted size of this map. |
Methods inherited from class java.util.AbstractMap |
---|
clone, equals, hashCode, putAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode, putAll |
Method Detail |
---|
public int capacity()
public void setCapacity(int capacity)
capacity
- the maximum weighted capacity of the map
java.lang.IllegalArgumentException
- if the capacity is negativepublic boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
isEmpty
in class java.util.AbstractMap<K,V>
public int size()
size
in interface java.util.Map<K,V>
size
in class java.util.AbstractMap<K,V>
public int weightedSize()
public void clear()
clear
in interface java.util.Map<K,V>
clear
in class java.util.AbstractMap<K,V>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
containsKey
in class java.util.AbstractMap<K,V>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
containsValue
in class java.util.AbstractMap<K,V>
public V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
get
in class java.util.AbstractMap<K,V>
public V put(K key, V value)
put
in interface java.util.Map<K,V>
put
in class java.util.AbstractMap<K,V>
public V putIfAbsent(K key, V value)
putIfAbsent
in interface java.util.concurrent.ConcurrentMap<K,V>
public V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
remove
in class java.util.AbstractMap<K,V>
public boolean remove(java.lang.Object key, java.lang.Object value)
remove
in interface java.util.concurrent.ConcurrentMap<K,V>
public V replace(K key, V value)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
public boolean replace(K key, V oldValue, V newValue)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
public java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
keySet
in class java.util.AbstractMap<K,V>
public java.util.Set<K> ascendingKeySet()
Set
view of the keys contained in this map.
The set's iterator returns the keys whose order of iteration is the ascending order
in which its entries are considered eligible for retention, from the least-likely
to be retained to the most-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT a
constant-time operation. Because of the asynchronous nature of the page replacement
policy, determining the retention ordering requires a traversal of the keys.
public java.util.Set<K> ascendingKeySetWithLimit(int limit)
Set
view of the keys contained in this
map. The set's iterator returns the keys whose order of iteration is the ascending
order in which its entries are considered eligible for retention, from the
least-likely to be retained to the most-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT a
constant-time operation. Because of the asynchronous nature of the page replacement
policy, determining the retention ordering requires a traversal of the keys.
limit
- the maximum size of the returned set
java.lang.IllegalArgumentException
- if the limit is negativepublic java.util.Set<K> descendingKeySet()
Set
view of the keys contained in this
map. The set's iterator returns the keys whose order of iteration is the descending
order in which its entries are considered eligible for retention, from the
most-likely to be retained to the least-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT a
constant-time operation. Because of the asynchronous nature of the page replacement
policy, determining the retention ordering requires a traversal of the keys.
public java.util.Set<K> descendingKeySetWithLimit(int limit)
Set
view of the keys contained in this
map. The set's iterator returns the keys whose order of iteration is the descending
order in which its entries are considered eligible for retention, from the
most-likely to be retained to the least-likely.
Beware that, unlike in keySet()
, obtaining the set is NOT a
constant-time operation. Because of the asynchronous nature of the page replacement
policy, determining the retention ordering requires a traversal of the keys.
limit
- the maximum size of the returned set
java.lang.IllegalArgumentException
- if the limit is negativepublic java.util.Collection<V> values()
values
in interface java.util.Map<K,V>
values
in class java.util.AbstractMap<K,V>
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
entrySet
in class java.util.AbstractMap<K,V>
public java.util.Map<K,V> ascendingMap()
Map
view of the mappings contained in this
map. The map's collections return the mappings whose order of iteration is the
ascending order in which its entries are considered eligible for retention, from
the least-likely to be retained to the most-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
public java.util.Map<K,V> ascendingMapWithLimit(int limit)
Map
view of the mappings contained in this
map. The map's collections return the mappings whose order of iteration is the
ascending order in which its entries are considered eligible for retention, from
the least-likely to be retained to the most-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit
- the maximum size of the returned map
java.lang.IllegalArgumentException
- if the limit is negativepublic java.util.Map<K,V> descendingMap()
Map
view of the mappings contained in this
map. The map's collections return the mappings whose order of iteration is the
descending order in which its entries are considered eligible for retention, from
the most-likely to be retained to the least-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
public java.util.Map<K,V> descendingMapWithLimit(int limit)
Map
view of the mappings contained in this
map. The map's collections return the mappings whose order of iteration is the
descending order in which its entries are considered eligible for retention, from
the most-likely to be retained to the least-likely.
Beware that obtaining the mappings is NOT a constant-time operation. Because of the asynchronous nature of the page replacement policy, determining the retention ordering requires a traversal of the entries.
limit
- the maximum size of the returned map
java.lang.IllegalArgumentException
- if the limit is negative
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |