Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.databind.util.internal

public final Class PrivateMaxEntriesMap<K, V>

extends AbstractMap<K, V>
implements ConcurrentMap<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.concurrent.ConcurrentMap, java.util.Map
Type Parameters
<K>
the type of keys maintained by this map
<V>
the type of mapped values
Static Imports
com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus.IDLE, .PrivateMaxEntriesMap.DrainStatus.PROCESSING, .PrivateMaxEntriesMap.DrainStatus.REQUIRED

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 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 java.util.concurrent.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 java.util.Hashtable but unlike HashMap, this class does not allow null to be used as a key or value. Unlike java.util.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.

Author
[email protected] (Ben Manes)
See Also
http://code.google.com/p/concurrentlinkedhashmap/

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
PrivateMaxEntriesMap.AddTask

Adds the node to the page replacement policy.

public static class
PrivateMaxEntriesMap.Builder<K, V>

A builder that creates PrivateMaxEntriesMap instances.

pack-priv static enum
PrivateMaxEntriesMap.DrainStatus

The draining status of the buffers.

pack-priv class
PrivateMaxEntriesMap.EntryIterator

An adapter to safely externalize the entry iterator.

pack-priv class
PrivateMaxEntriesMap.EntrySet

An adapter to safely externalize the entries.

pack-priv class
PrivateMaxEntriesMap.KeyIterator

An adapter to safely externalize the key iterator.

pack-priv class
PrivateMaxEntriesMap.KeySet

An adapter to safely externalize the keys.

pack-priv static class
PrivateMaxEntriesMap.Node<K, V>

A node contains the key, the weighted value, and the linkage pointers on the page-replacement algorithm's data structures.

pack-priv class
PrivateMaxEntriesMap.RemovalTask

Removes a node from the page replacement policy.

pack-priv static class
PrivateMaxEntriesMap.SerializationProxy<K, V>

A proxy that is serialized instead of the map.

pack-priv class
PrivateMaxEntriesMap.UpdateTask

Updates the weighted size and evicts an entry on overflow.

pack-priv class
PrivateMaxEntriesMap.ValueIterator

An adapter to safely externalize the value iterator.

pack-priv class
PrivateMaxEntriesMap.Values

An adapter to safely externalize the values.

pack-priv static class
PrivateMaxEntriesMap.WeightedValue<V>

A value, its weight, and the entry's status.

pack-priv class
PrivateMaxEntriesMap.WriteThroughEntry

An entry that allows updates to write through to the map.

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicLong
pack-priv final int
pack-priv final ConcurrentMap<K, PrivateMaxEntriesMap.Node<K, V>>
pack-priv final AtomicReference<PrivateMaxEntriesMap.DrainStatus>
pack-priv transient Set<Map.Entry<K, V>>
pack-priv final LinkedDeque<PrivateMaxEntriesMap.Node<K, V>>
pack-priv final Lock
pack-priv transient Set<K>
pack-priv static final long
MAXIMUM_CAPACITY

The maximum capacity of the map.

pack-priv static final int
NCPU

The number of CPUs

pack-priv static final int
NUMBER_OF_READ_BUFFERS

The number of read buffers to use.

pack-priv static final int
READ_BUFFER_DRAIN_THRESHOLD

The maximum number of read operations to perform per amortized drain.

pack-priv static final int
READ_BUFFER_INDEX_MASK

Mask value for indexing into the read buffer.

pack-priv static final int
READ_BUFFER_SIZE

The maximum number of pending reads per buffer.

pack-priv static final int
READ_BUFFER_THRESHOLD

The number of pending read operations before attempting to drain.

pack-priv static final int
READ_BUFFERS_MASK

Mask value for indexing into the read buffers.

pack-priv final AtomicLongArray
pack-priv final long[]
pack-priv final AtomicReferenceArray<PrivateMaxEntriesMap.Node<K, V>>
pack-priv final AtomicLongArray
pack-priv static final long
pack-priv transient Collection<V>
pack-priv final AtomicLong
pack-priv static final int
WRITE_BUFFER_DRAIN_THRESHOLD

The maximum number of write operations to perform per amortized drain.

pack-priv final Queue<Runnable>

Constructor Summary

AccessConstructor and Description
pack-priv
PrivateMaxEntriesMap(PrivateMaxEntriesMap.Builder<K, V> builder)

Creates an instance based on the builder's configuration.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
afterRead(PrivateMaxEntriesMap.Node<K, V>
the entry in the page replacement policy
node
)

Performs the post-processing work required after a read.

pack-priv void
afterWrite(Runnable
the pending operation to be applied
task
)

Performs the post-processing work required after a write.

pack-priv void
applyRead(PrivateMaxEntriesMap.Node<K, V> node)

Updates the node's location in the page replacement policy.

public long

Returns:

the maximum capacity
capacity
()

Retrieves the maximum capacity of the map.

pack-priv static int
pack-priv static void
checkArgument(boolean expression)

Ensures that the argument expression is true.

pack-priv static void
checkNotNull(Object o)

Ensures that the object is not null.

pack-priv static void
checkState(boolean expression)

Ensures that the state expression is true.

public void
clear()

Overrides java.util.AbstractMap.clear.

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Overrides java.util.AbstractMap.containsKey.

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Overrides java.util.AbstractMap.containsValue.

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

pack-priv void
drainBuffers()

Drains the read and write buffers up to an amortized threshold.

pack-priv void
drainOnReadIfNeeded(int
the index to the chosen read buffer
bufferIndex
,
long
the number of writes on the chosen read buffer
writeCount
)

Attempts to drain the buffers if it is determined to be needed when post-processing a read.

pack-priv void
drainReadBuffer(int bufferIndex)

Drains the read buffer up to an amortized threshold.

pack-priv void
drainReadBuffers()

Drains the read buffers, each up to an amortized threshold.

pack-priv void
drainWriteBuffer()

Drains the read buffer up to an amortized threshold.

public Set<Map.Entry<K, V>>
entrySet()

Implements abstract java.util.AbstractMap.entrySet.

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

pack-priv void
evict()

Evicts entries from the map while it exceeds the capacity and appends evicted entries to the notification queue for processing.

public V
get(Object
the key whose associated value is to be returned
key
)

Overrides java.util.AbstractMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

pack-priv boolean
hasOverflowed()

Determines whether the map has exceeded its capacity.

public boolean
isEmpty()

Overrides java.util.AbstractMap.isEmpty.

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public Set<K>
keySet()

Overrides java.util.AbstractMap.keySet.

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

pack-priv void
makeDead(PrivateMaxEntriesMap.Node<K, V>
the entry in the page replacement policy
node
)

Atomically transitions the node to the dead state and decrements the weightedSize.

pack-priv void
makeRetired(PrivateMaxEntriesMap.Node<K, V>
the entry in the page replacement policy
node
)

Atomically transitions the node from the alive state to the retired state, if a valid transition.

public V
put(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides java.util.AbstractMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

pack-priv V

Returns:

the prior value in the data store or null if no mapping was found
put
(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
,
boolean
a write is performed only if the key is not already associated with a value
onlyIfAbsent
)

Adds a node to the list and the data store.

public V
putIfAbsent(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.putIfAbsent.

Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

If the specified key is not already associated with a value, associates it with the given value.

private static int
readBufferIndex(int bufferIndex, int entryIndex)

pack-priv static int
readBufferIndex()

Returns the index to the read buffer to record into.

private void
pack-priv long

Returns:

the number of writes on the chosen read buffer
recordRead
(int
the index to the chosen read buffer
bufferIndex
,
PrivateMaxEntriesMap.Node<K, V>
the entry in the page replacement policy
node
)

Records a read in the buffer and return its write count.

public V
remove(Object
key whose mapping is to be removed from the map
key
)

Overrides java.util.AbstractMap.remove.

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public boolean
remove(Object
key with which the specified value is associated
key
,
Object
value expected to be associated with the specified key
value
)

Overrides default java.util.Map.remove.

Implements java.util.concurrent.ConcurrentMap.remove.

Removes the entry for a key only if currently mapped to a given value.

public V
replace(K
key with which the specified value is associated
key
,
V
value to be associated with the specified key
value
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to some value.

public boolean
replace(K
key with which the specified value is associated
key
,
V
value expected to be associated with the specified key
oldValue
,
V
value to be associated with the specified key
newValue
)

Overrides default java.util.Map.replace.

Implements java.util.concurrent.ConcurrentMap.replace.

Replaces the entry for a key only if currently mapped to a given value.

public void
setCapacity(long
the maximum capacity of the map
capacity
)

Sets the maximum capacity of the map and eagerly evicts entries until it shrinks to the appropriate size.

public int
size()

Overrides java.util.AbstractMap.size.

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

pack-priv void
tryToDrainBuffers()

Attempts to acquire the eviction lock and apply the pending operations, up to the amortized threshold, to the page replacement policy.

pack-priv boolean

Returns:

if successful
tryToRetire
(PrivateMaxEntriesMap.Node<K, V>
the entry in the page replacement policy
node
,
PrivateMaxEntriesMap.WeightedValue<V>
the expected weighted value
expect
)

Attempts to transition the node from the alive state to the retired state.

public Collection<V>
values()

Overrides java.util.AbstractMap.values.

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

pack-priv Object
Inherited from java.util.AbstractMap:
cloneequalshashCodeputAlltoString