Top Description Inners Fields Constructors Methods
net.sf.ehcache.store.chm

public Class SelectableConcurrentHashMap

extends Object
Class Inheritance
Annotations
@SuppressWarnings:ForLoopReplaceableByForEach
Imports
java.util.AbstractCollection, .AbstractSet, .ArrayList, .Arrays, .Collection, .Collections, .Iterator, .List, .Map, .Map.Entry, .NoSuchElementException, .Random, .Set, java.util.concurrent.locks.ReentrantReadWriteLock, net.sf.ehcache.CacheOperationOutcomes.EvictionOutcome, .Element, net.sf.ehcache.event.RegisteredEventListeners, net.sf.ehcache.pool.PoolAccessor, org.terracotta.statistics.observer.OperationObserver

SelectableConcurrentHashMap subclasses a repackaged version of ConcurrentHashMap ito allow efficient random sampling of the map values.

The random sampling technique involves randomly selecting a map Segment, and then selecting a number of random entry chains from that segment.

Author
Chris Dennis

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv class
public static class
pack-priv abstract class
pack-priv abstract class
pack-priv class
pack-priv class
public class
pack-priv static class
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
private final RegisteredEventListeners
pack-priv static final int
DEFAULT_INITIAL_CAPACITY

The default initial capacity for this table, used when not otherwise specified in a constructor.

pack-priv static final float
DEFAULT_LOAD_FACTOR

The default load factor for this table, used when not otherwise specified in a constructor.

private Set<Map.Entry<Object, Element>>
private final OperationObserver<CacheOperationOutcomes.EvictionOutcome>
private Set<Object>
private static final int
MAX_SEGMENTS

The maximum number of segments to allow; used to bound constructor arguments.

private static final int
MAXIMUM_CAPACITY

The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments.

private volatile long
private final PoolAccessor<T extends PoolParticipant>
private static final int
RETRIES_BEFORE_LOCK

Number of unsynchronized retries in size and containsValue methods before resorting to locking.

private final Random
private final int
segmentMask

Mask value for indexing into segments.

private final SelectableConcurrentHashMap.Segment[]
segments

The segments, each of which is a specialized hash table

private final int
segmentShift

Shift value for indexing within segments.

private Collection<Element>

Constructor Summary

AccessConstructor and Description
public
SelectableConcurrentHashMap(PoolAccessor<T extends PoolParticipant> poolAccessor, int concurrency, final long maximumSize, final RegisteredEventListeners cacheEventNotificationService)

public
SelectableConcurrentHashMap(PoolAccessor<T extends PoolParticipant> poolAccessor, int initialCapacity, float loadFactor, int concurrency, final long maximumSize, final RegisteredEventListeners cacheEventNotificationService)

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
public boolean
protected SelectableConcurrentHashMap.Segment
createSegment(int initialCapacity, float lf)

public Set<Map.Entry<Object, Element>>
public boolean
public Element
get(Object key)

private SelectableConcurrentHashMap.Segment
public Element[]
getRandomValues(final int size, Object keyHint)

protected static int
hash(int h)

public boolean
public Set<Object>
public ReentrantReadWriteLock
public ReentrantReadWriteLock[]
public Element
put(Object key, Element element, long sizeOf)

public Element
putIfAbsent(Object key, Element element, long sizeOf)

public int

Returns:

the number of key-value mappings in this map
quickSize
()

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

public void
public Element
public boolean
remove(Object key, Object value)

protected final SelectableConcurrentHashMap.Segment

Returns:

the segment
segmentFor
(int
the hash code for the key
hash
)

Returns the segment that should be used for key with given hash

protected final List<SelectableConcurrentHashMap.Segment>
public void
setMaxSize(final long maxSize)

public int
size()

public Object

Returns:

an object looking-alike the stored one
storedObject
(Element
the element
e
)

Return an object of the kind which will be stored when the element is going to be inserted

public Collection<Element>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait