Class PrivateMaxEntriesMap<K,V>
- Type Parameters:
K
- the type of keys maintained by this mapV
- the type of mapped values
- All Implemented Interfaces:
Serializable
,ConcurrentMap<K,
,V> Map<K,
V>
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 PrivateMaxEntriesMap.Builder
.
An entry is evicted from the map when the entry size exceeds its maximum capacity threshold.
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
Modifier and TypeClassDescriptionstatic final class
A builder that createsPrivateMaxEntriesMap
instances.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Method Summary
Modifier and TypeMethodDescriptionlong
capacity()
Retrieves the maximum capacity of the map.void
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
isEmpty()
keySet()
putIfAbsent
(K key, V value) boolean
boolean
void
setCapacity
(long capacity) Sets the maximum capacity of the map and eagerly evicts entries until it shrinks to the appropriate size.int
size()
values()
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Method Details
-
capacity
public long capacity()Retrieves the maximum capacity of the map.- Returns:
- the maximum capacity
-
setCapacity
public void setCapacity(long capacity) Sets the maximum capacity of the map and eagerly evicts entries until it shrinks to the appropriate size.- Parameters:
capacity
- the maximum capacity of the map- Throws:
IllegalArgumentException
- if the capacity is negative
-
isEmpty
public boolean isEmpty() -
size
public int size() -
clear
public void clear() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classAbstractMap<K,
V>
-
get
-
put
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceConcurrentMap<K,
V> - Specified by:
putIfAbsent
in interfaceMap<K,
V>
-
remove
-
remove
-
replace
-
replace
-
keySet
-
values
-
entrySet
-