class MapMakerInternalMap<K,V>
extends java.util.AbstractMap<K,V>
implements java.util.concurrent.ConcurrentMap<K,V>, java.io.Serializable
MapMaker
.
This implementation is heavily derived from revision 1.96 of ConcurrentHashMap.java.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
MapMakerInternalMap.AbstractReferenceEntry<K,V> |
(package private) static class |
MapMakerInternalMap.AbstractSerializationProxy<K,V>
The actual object that gets serialized.
|
(package private) static class |
MapMakerInternalMap.CleanupMapTask |
(package private) static class |
MapMakerInternalMap.EntryFactory
Creates new entries.
|
(package private) class |
MapMakerInternalMap.EntryIterator |
(package private) class |
MapMakerInternalMap.EntrySet |
(package private) static class |
MapMakerInternalMap.EvictionQueue<K,V>
A custom queue for managing eviction order.
|
(package private) static class |
MapMakerInternalMap.ExpirationQueue<K,V>
A custom queue for managing expiration order.
|
(package private) class |
MapMakerInternalMap.HashIterator<E> |
(package private) class |
MapMakerInternalMap.KeyIterator |
(package private) class |
MapMakerInternalMap.KeySet |
private static class |
MapMakerInternalMap.NullEntry |
(package private) static interface |
MapMakerInternalMap.ReferenceEntry<K,V>
An entry in a reference map.
|
(package private) static class |
MapMakerInternalMap.Segment<K,V>
Segments are specialized versions of hash tables.
|
private static class |
MapMakerInternalMap.SerializationProxy<K,V>
The actual object that gets serialized.
|
(package private) static class |
MapMakerInternalMap.SoftEntry<K,V>
Used for softly-referenced keys.
|
(package private) static class |
MapMakerInternalMap.SoftEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.SoftExpirableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.SoftExpirableEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.SoftValueReference<K,V>
References a soft value.
|
(package private) static class |
MapMakerInternalMap.Strength |
(package private) static class |
MapMakerInternalMap.StrongEntry<K,V>
Used for strongly-referenced keys.
|
(package private) static class |
MapMakerInternalMap.StrongEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.StrongExpirableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.StrongExpirableEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.StrongValueReference<K,V>
References a strong value.
|
(package private) class |
MapMakerInternalMap.ValueIterator |
(package private) static interface |
MapMakerInternalMap.ValueReference<K,V>
A reference to a value.
|
(package private) class |
MapMakerInternalMap.Values |
(package private) static class |
MapMakerInternalMap.WeakEntry<K,V>
Used for weakly-referenced keys.
|
(package private) static class |
MapMakerInternalMap.WeakEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.WeakExpirableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.WeakExpirableEvictableEntry<K,V> |
(package private) static class |
MapMakerInternalMap.WeakValueReference<K,V>
References a weak value.
|
(package private) class |
MapMakerInternalMap.WriteThroughEntry
Custom Entry class used by EntryIterator.next(), that relays setValue changes to the
underlying map.
|
Modifier and Type | Field and Description |
---|---|
(package private) static long |
CLEANUP_EXECUTOR_DELAY_SECS |
(package private) int |
concurrencyLevel
The concurrency level.
|
(package private) static int |
CONTAINS_VALUE_RETRIES
Number of (unsynchronized) retries in the containsValue method.
|
(package private) static java.util.Queue<? extends java.lang.Object> |
DISCARDING_QUEUE |
(package private) static int |
DRAIN_MAX
Maximum number of entries to be drained in a single cleanup run.
|
(package private) static int |
DRAIN_THRESHOLD
Number of cache access operations that can be buffered per segment before the cache's recency
ordering information is updated.
|
(package private) MapMakerInternalMap.EntryFactory |
entryFactory
Factory used to create new entries.
|
(package private) java.util.Set<java.util.Map.Entry<K,V>> |
entrySet |
(package private) long |
expireAfterAccessNanos
How long after the last access to an entry the map will retain that entry.
|
(package private) long |
expireAfterWriteNanos
How long after the last write to an entry the map will retain that entry.
|
(package private) Equivalence<java.lang.Object> |
keyEquivalence
Strategy for comparing keys.
|
(package private) java.util.Set<K> |
keySet |
(package private) MapMakerInternalMap.Strength |
keyStrength
Strategy for referencing keys.
|
private static java.util.logging.Logger |
logger |
(package private) static int |
MAX_SEGMENTS
The maximum number of segments to allow; used to bound constructor arguments.
|
(package private) static int |
MAXIMUM_CAPACITY
The maximum capacity, used if a higher value is implicitly specified by either of the
constructors with arguments.
|
(package private) int |
maximumSize
The maximum size of this map.
|
(package private) MapMaker.RemovalListener<K,V> |
removalListener
A listener that is invoked when an entry is removed due to expiration or garbage collection of
soft/weak entries.
|
(package private) java.util.Queue<MapMaker.RemovalNotification<K,V>> |
removalNotificationQueue
Entries waiting to be consumed by the removal listener.
|
(package private) int |
segmentMask
Mask value for indexing into segments.
|
(package private) MapMakerInternalMap.Segment<K,V>[] |
segments
The segments, each of which is a specialized hash table.
|
(package private) int |
segmentShift
Shift value for indexing within segments.
|
private static long |
serialVersionUID |
(package private) Ticker |
ticker
Measures time in a testable way.
|
(package private) static MapMakerInternalMap.ValueReference<java.lang.Object,java.lang.Object> |
UNSET
Placeholder.
|
(package private) Equivalence<java.lang.Object> |
valueEquivalence
Strategy for comparing values.
|
(package private) java.util.Collection<V> |
values |
(package private) MapMakerInternalMap.Strength |
valueStrength
Strategy for referencing values.
|
Constructor and Description |
---|
MapMakerInternalMap(MapMaker builder)
Creates a new, empty map with the specified strategy, initial capacity and concurrency level.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
(package private) static <K,V> void |
connectEvictables(MapMakerInternalMap.ReferenceEntry<K,V> previous,
MapMakerInternalMap.ReferenceEntry<K,V> next)
Links the evitables together.
|
(package private) static <K,V> void |
connectExpirables(MapMakerInternalMap.ReferenceEntry<K,V> previous,
MapMakerInternalMap.ReferenceEntry<K,V> next) |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
copyEntry(MapMakerInternalMap.ReferenceEntry<K,V> original,
MapMakerInternalMap.ReferenceEntry<K,V> newNext)
This method is a convenience for testing.
|
(package private) MapMakerInternalMap.Segment<K,V> |
createSegment(int initialCapacity,
int maxSegmentSize) |
(package private) static <E> java.util.Queue<E> |
discardingQueue()
Queue that discards all elements.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
(package private) boolean |
evictsBySize() |
(package private) boolean |
expires() |
(package private) boolean |
expiresAfterAccess() |
(package private) boolean |
expiresAfterWrite() |
V |
get(java.lang.Object key) |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
getEntry(java.lang.Object key)
Returns the internal entry for the specified key.
|
(package private) V |
getLiveValue(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Gets the value from an entry.
|
(package private) int |
hash(java.lang.Object key) |
boolean |
isEmpty() |
(package private) boolean |
isExpired(MapMakerInternalMap.ReferenceEntry<K,V> entry)
Returns
true if the entry has expired. |
(package private) boolean |
isExpired(MapMakerInternalMap.ReferenceEntry<K,V> entry,
long now)
Returns
true if the entry has expired. |
(package private) boolean |
isLive(MapMakerInternalMap.ReferenceEntry<K,V> entry)
This method is a convenience for testing.
|
java.util.Set<K> |
keySet() |
(package private) MapMakerInternalMap.ReferenceEntry<K,V> |
newEntry(K key,
int hash,
MapMakerInternalMap.ReferenceEntry<K,V> next)
This method is a convenience for testing.
|
(package private) MapMakerInternalMap.Segment<K,V>[] |
newSegmentArray(int ssize) |
(package private) MapMakerInternalMap.ValueReference<K,V> |
newValueReference(MapMakerInternalMap.ReferenceEntry<K,V> entry,
V value)
This method is a convenience for testing.
|
(package private) static <K,V> MapMakerInternalMap.ReferenceEntry<K,V> |
nullEntry() |
(package private) static <K,V> void |
nullifyEvictable(MapMakerInternalMap.ReferenceEntry<K,V> nulled) |
(package private) static <K,V> void |
nullifyExpirable(MapMakerInternalMap.ReferenceEntry<K,V> nulled) |
(package private) void |
processPendingNotifications()
Notifies listeners that an entry has been automatically removed due to expiration, eviction,
or eligibility for garbage collection.
|
V |
put(K key,
V value) |
void |
putAll(java.util.Map<? extends K,? extends V> m) |
V |
putIfAbsent(K key,
V value) |
(package private) void |
reclaimKey(MapMakerInternalMap.ReferenceEntry<K,V> entry) |
(package private) void |
reclaimValue(MapMakerInternalMap.ValueReference<K,V> valueReference) |
(package private) static int |
rehash(int h)
Applies a supplemental hash function to a given hash code, which defends against poor quality
hash functions.
|
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) |
(package private) MapMakerInternalMap.Segment<K,V> |
segmentFor(int hash)
Returns the segment that should be used for a key with the given hash.
|
int |
size() |
(package private) static <K,V> MapMakerInternalMap.ValueReference<K,V> |
unset()
Singleton placeholder that indicates a value is being computed.
|
(package private) boolean |
usesKeyReferences() |
(package private) boolean |
usesValueReferences() |
java.util.Collection<V> |
values() |
(package private) java.lang.Object |
writeReplace() |
finalize, getClass, notify, notifyAll, wait, wait, wait
static final int MAXIMUM_CAPACITY
static final int MAX_SEGMENTS
static final int CONTAINS_VALUE_RETRIES
static final int DRAIN_THRESHOLD
This must be a (2^n)-1 as it is used as a mask.
static final int DRAIN_MAX
static final long CLEANUP_EXECUTOR_DELAY_SECS
private static final java.util.logging.Logger logger
final transient int segmentMask
final transient int segmentShift
final transient MapMakerInternalMap.Segment<K,V>[] segments
final int concurrencyLevel
final Equivalence<java.lang.Object> keyEquivalence
final Equivalence<java.lang.Object> valueEquivalence
final MapMakerInternalMap.Strength keyStrength
final MapMakerInternalMap.Strength valueStrength
final int maximumSize
final long expireAfterAccessNanos
final long expireAfterWriteNanos
final java.util.Queue<MapMaker.RemovalNotification<K,V>> removalNotificationQueue
final MapMaker.RemovalListener<K,V> removalListener
final transient MapMakerInternalMap.EntryFactory entryFactory
final Ticker ticker
static final MapMakerInternalMap.ValueReference<java.lang.Object,java.lang.Object> UNSET
static final java.util.Queue<? extends java.lang.Object> DISCARDING_QUEUE
transient java.util.Set<K> keySet
transient java.util.Collection<V> values
private static final long serialVersionUID
MapMakerInternalMap(MapMaker builder)
boolean evictsBySize()
boolean expires()
boolean expiresAfterWrite()
boolean expiresAfterAccess()
boolean usesKeyReferences()
boolean usesValueReferences()
static <K,V> MapMakerInternalMap.ValueReference<K,V> unset()
static <K,V> MapMakerInternalMap.ReferenceEntry<K,V> nullEntry()
static <E> java.util.Queue<E> discardingQueue()
static int rehash(int h)
h
- hash codeMapMakerInternalMap.ReferenceEntry<K,V> newEntry(K key, int hash, @Nullable MapMakerInternalMap.ReferenceEntry<K,V> next)
MapMakerInternalMap.Segment.newEntry(K, int, com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
directly.MapMakerInternalMap.ReferenceEntry<K,V> copyEntry(MapMakerInternalMap.ReferenceEntry<K,V> original, MapMakerInternalMap.ReferenceEntry<K,V> newNext)
MapMakerInternalMap.Segment.copyEntry(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>, com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
directly.MapMakerInternalMap.ValueReference<K,V> newValueReference(MapMakerInternalMap.ReferenceEntry<K,V> entry, V value)
MapMakerInternalMap.Segment.setValue(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>, V)
instead.int hash(java.lang.Object key)
void reclaimValue(MapMakerInternalMap.ValueReference<K,V> valueReference)
void reclaimKey(MapMakerInternalMap.ReferenceEntry<K,V> entry)
boolean isLive(MapMakerInternalMap.ReferenceEntry<K,V> entry)
MapMakerInternalMap.Segment.getLiveValue(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
instead.MapMakerInternalMap.Segment<K,V> segmentFor(int hash)
hash
- the hash code for the keyMapMakerInternalMap.Segment<K,V> createSegment(int initialCapacity, int maxSegmentSize)
V getLiveValue(MapMakerInternalMap.ReferenceEntry<K,V> entry)
null
if the entry is invalid,
partially-collected, computing, or expired. Unlike MapMakerInternalMap.Segment.getLiveValue(com.google.common.collect.MapMakerInternalMap.ReferenceEntry<K, V>)
this method
does not attempt to clean up stale entries.boolean isExpired(MapMakerInternalMap.ReferenceEntry<K,V> entry)
true
if the entry has expired.boolean isExpired(MapMakerInternalMap.ReferenceEntry<K,V> entry, long now)
true
if the entry has expired.static <K,V> void connectExpirables(MapMakerInternalMap.ReferenceEntry<K,V> previous, MapMakerInternalMap.ReferenceEntry<K,V> next)
static <K,V> void nullifyExpirable(MapMakerInternalMap.ReferenceEntry<K,V> nulled)
void processPendingNotifications()
static <K,V> void connectEvictables(MapMakerInternalMap.ReferenceEntry<K,V> previous, MapMakerInternalMap.ReferenceEntry<K,V> next)
static <K,V> void nullifyEvictable(MapMakerInternalMap.ReferenceEntry<K,V> nulled)
final MapMakerInternalMap.Segment<K,V>[] newSegmentArray(int ssize)
public boolean isEmpty()
public int size()
public V get(@Nullable java.lang.Object key)
MapMakerInternalMap.ReferenceEntry<K,V> getEntry(@Nullable java.lang.Object key)
public boolean containsKey(@Nullable java.lang.Object key)
public boolean containsValue(@Nullable java.lang.Object value)
public V remove(@Nullable java.lang.Object key)
public boolean remove(@Nullable java.lang.Object key, @Nullable java.lang.Object value)
public void clear()
public java.util.Set<K> keySet()
public java.util.Collection<V> values()
java.lang.Object writeReplace()