GridGain™ 4.3.1e
Enterprise "Big Data" Edition

org.gridgain.grid.lang.utils
Class GridBoundedConcurrentOrderedMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.concurrent.ConcurrentSkipListMap<K,V>
          extended by org.gridgain.grid.lang.utils.GridBoundedConcurrentOrderedMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, ConcurrentMap<K,V>, ConcurrentNavigableMap<K,V>, Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

public class GridBoundedConcurrentOrderedMap<K,V>
extends ConcurrentSkipListMap<K,V>

Concurrent ordered map that automatically manages its maximum size. Once it exceeds its maximum, it will start removing smallest elements until the maximum is reached again. If optional listener is set via GridBoundedConcurrentOrderedMap.evictionListener(GridInClosure2) method, then listener will be notified for every eviction.

Note that due to concurrent nature of this map, it may grow slightly larger than its maximum allowed size, but in this case it will quickly readjust back to allowed size.

Note that GridBoundedConcurrentOrderedMap.remove(Object) and GridBoundedConcurrentOrderedMap.remove(Object, Object) methods are not supported for this kind of map.

See Also:
Serialized Form
 

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
GridBoundedConcurrentOrderedMap(int max)
          Constructs a new, empty map that orders its elements according to their natural ordering.
GridBoundedConcurrentOrderedMap(int max, Comparator<? super K> comparator)
          Constructs a new, empty set that orders its elements according to the specified comparator.
GridBoundedConcurrentOrderedMap(int max, Map<? extends K,? extends V> map)
          Constructs a new map containing the elements in the specified map, that orders its elements according to their natural ordering.
GridBoundedConcurrentOrderedMap(int max, SortedMap<K,V> map)
          Constructs a new map containing the same elements and using the same ordering as the specified sorted map.
 
Method Summary
 GridBoundedConcurrentOrderedMap<K,V> clone()
          
 GridInClosure2<K,V> evictionListener()
          Gets closure listener to be called for every eviction event.
 void evictionListener(GridInClosure2<K,V> lsnr)
          Sets closure listener to be called for every eviction event.
 V put(K k, V v)
          
 V putIfAbsent(K k, V v)
          
 V remove(Object o)
          This method is not supported and always throws UnsupportedOperationException.
 boolean remove(Object key, Object val)
          This method is not supported and always throws UnsupportedOperationException.
 int size()
          Approximate size at this point of time.
 
Methods inherited from class java.util.concurrent.ConcurrentSkipListMap
ceilingEntry, ceilingKey, clear, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, equals, firstEntry, firstKey, floorEntry, floorKey, get, headMap, headMap, higherEntry, higherKey, isEmpty, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, replace, replace, subMap, subMap, tailMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
hashCode, putAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode, putAll
 

Constructor Detail

GridBoundedConcurrentOrderedMap

public GridBoundedConcurrentOrderedMap(int max)
Constructs a new, empty map that orders its elements according to their natural ordering.

Parameters:
max - Upper bound of this map.

GridBoundedConcurrentOrderedMap

public GridBoundedConcurrentOrderedMap(int max,
                                       Comparator<? super K> comparator)
Constructs a new, empty set that orders its elements according to the specified comparator.

Parameters:
max - Upper bound of this map.
comparator - The comparator that will be used to order this map. If null, the natural ordering of the elements will be used.

GridBoundedConcurrentOrderedMap

public GridBoundedConcurrentOrderedMap(int max,
                                       Map<? extends K,? extends V> map)
Constructs a new map containing the elements in the specified map, that orders its elements according to their natural ordering.

Throws:
ClassCastException - if the elements in map are not Comparable, or are not mutually comparable.
NullPointerException - if the specified map or any of its elements are null.
Parameters:
max - Upper bound of this map.
map - The elements that will comprise the new map.

GridBoundedConcurrentOrderedMap

public GridBoundedConcurrentOrderedMap(int max,
                                       SortedMap<K,V> map)
Constructs a new map containing the same elements and using the same ordering as the specified sorted map.

Throws:
NullPointerException - if the specified sorted map or any of its elements are null.
Parameters:
max - Upper bound of this map.
map - Sorted map whose elements will comprise the new map.
Method Detail

evictionListener

public void evictionListener(GridInClosure2<K,V> lsnr)
Sets closure listener to be called for every eviction event.

Parameters:
lsnr - Closure to be called for every eviction event.

evictionListener

public GridInClosure2<K,V> evictionListener()
Gets closure listener to be called for every eviction event.

Returns:
Closure to be called for every eviction event.

put

@Nullable
public V put(K k,
                      V v)

Specified by:
put in interface Map<K,V>
Overrides:
put in class ConcurrentSkipListMap<K,V>

putIfAbsent

@Nullable
public V putIfAbsent(K k,
                              V v)

Specified by:
putIfAbsent in interface ConcurrentMap<K,V>
Overrides:
putIfAbsent in class ConcurrentSkipListMap<K,V>

size

public int size()
Approximate size at this point of time. Note, that unlike size methods on other concurrent collections, this method executes in constant time without traversal of the elements.

Specified by:
size in interface Map<K,V>
Overrides:
size in class ConcurrentSkipListMap<K,V>
Returns:
Approximate set size at this point of time.

clone

public GridBoundedConcurrentOrderedMap<K,V> clone()

Overrides:
clone in class ConcurrentSkipListMap<K,V>

remove

public V remove(Object o)
This method is not supported and always throws UnsupportedOperationException.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class ConcurrentSkipListMap<K,V>
Parameters:
o -
Returns:

remove

public boolean remove(Object key,
                      Object val)
This method is not supported and always throws UnsupportedOperationException.

Specified by:
remove in interface ConcurrentMap<K,V>
Overrides:
remove in class ConcurrentSkipListMap<K,V>
Parameters:
key -
val -
Returns:

GridGain™ 4.3.1e
Enterprise "Big Data" Edition

GridGain - In-Memory Big Data
Enterprise "Big Data" Edition, ver. 4.3.1e.10112012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Join GridGain User Group Follow GridGain on Twitter Follow GridGain on Vimeo