ehcache

net.sf.ehcache.store.chm
Class SelectableConcurrentHashMap

java.lang.Object
  extended by net.sf.ehcache.store.chm.SelectableConcurrentHashMap

public class SelectableConcurrentHashMap
extends Object

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 Class Summary
static class SelectableConcurrentHashMap.HashEntry
           
 class SelectableConcurrentHashMap.Segment
           
 
Constructor Summary
SelectableConcurrentHashMap(PoolAccessor poolAccessor, int initialCapacity, float loadFactor, int concurrency, long maximumSize, RegisteredEventListeners cacheEventNotificationService)
           
SelectableConcurrentHashMap(PoolAccessor poolAccessor, int concurrency, long maximumSize, RegisteredEventListeners cacheEventNotificationService)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
protected  SelectableConcurrentHashMap.Segment createSegment(int initialCapacity, float lf)
           
 Set<Map.Entry<Object,Element>> entrySet()
           
 boolean evict()
           
 Element get(Object key)
           
 Element[] getRandomValues(int size, Object keyHint)
           
protected static int hash(int h)
           
 boolean isEmpty()
           
 Set<Object> keySet()
           
 ReentrantReadWriteLock lockFor(Object key)
           
 ReentrantReadWriteLock[] locks()
           
 Element put(Object key, Element element, long sizeOf)
           
 Element putIfAbsent(Object key, Element element, long sizeOf)
           
 int quickSize()
          Returns the number of key-value mappings in this map without locking anything.
 void recalculateSize(Object key)
           
 Element remove(Object key)
           
 boolean remove(Object key, Object value)
           
protected  SelectableConcurrentHashMap.Segment segmentFor(int hash)
          Returns the segment that should be used for key with given hash
protected  List<SelectableConcurrentHashMap.Segment> segments()
           
 void setMaxSize(long maxSize)
           
 int size()
           
 Object storedObject(Element e)
          Return an object of the kind which will be stored when the element is going to be inserted
 Collection<Element> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectableConcurrentHashMap

public SelectableConcurrentHashMap(PoolAccessor poolAccessor,
                                   int concurrency,
                                   long maximumSize,
                                   RegisteredEventListeners cacheEventNotificationService)

SelectableConcurrentHashMap

public SelectableConcurrentHashMap(PoolAccessor poolAccessor,
                                   int initialCapacity,
                                   float loadFactor,
                                   int concurrency,
                                   long maximumSize,
                                   RegisteredEventListeners cacheEventNotificationService)
Method Detail

setMaxSize

public void setMaxSize(long maxSize)

getRandomValues

public Element[] getRandomValues(int size,
                                 Object keyHint)

storedObject

public Object storedObject(Element e)
Return an object of the kind which will be stored when the element is going to be inserted

Parameters:
e - the element
Returns:
an object looking-alike the stored one

quickSize

public int quickSize()
Returns the number of key-value mappings in this map without locking anything. This may not give the exact element count as locking is avoided. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

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

isEmpty

public boolean isEmpty()

size

public int size()

lockFor

public ReentrantReadWriteLock lockFor(Object key)

locks

public ReentrantReadWriteLock[] locks()

get

public Element get(Object key)

containsKey

public boolean containsKey(Object key)

containsValue

public boolean containsValue(Object value)

put

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

putIfAbsent

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

remove

public Element remove(Object key)

remove

public boolean remove(Object key,
                      Object value)

clear

public void clear()

keySet

public Set<Object> keySet()

values

public Collection<Element> values()

entrySet

public Set<Map.Entry<Object,Element>> entrySet()

createSegment

protected SelectableConcurrentHashMap.Segment createSegment(int initialCapacity,
                                                            float lf)

evict

public boolean evict()

recalculateSize

public void recalculateSize(Object key)

segmentFor

protected final SelectableConcurrentHashMap.Segment segmentFor(int hash)
Returns the segment that should be used for key with given hash

Parameters:
hash - the hash code for the key
Returns:
the segment

segments

protected final List<SelectableConcurrentHashMap.Segment> segments()

hash

protected static int hash(int h)

ehcache

Copyright 2001-2017, Terracotta, Inc.