org.apache.ignite.internal.processors.cache

## Class GridCacheConcurrentMap<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap<K,V>

Direct Known Subclasses:
  GridNoStorageCacheMap

    public class GridCacheConcurrentMap<K,V>
    extends Object

Concurrent implementation of cache map.

### Field Summary

Fields
`protected GridCacheContext<K,V>` `ctx` Cache context.
`static IgnitePredicate[]` `NON_INTERNAL_ARR` Non-internal predicate array.

### Constructor Summary

Constructors
`` `GridCacheConcurrentMap(GridCacheContext<K,V> ctx, int initCap)` Creates a new, empty map with the specified initial capacity, and with default load factor (0.75) and concurrencyLevel (16).
`` `GridCacheConcurrentMap(GridCacheContext<K,V> ctx, int initCap, float loadFactor)` Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16).
`protected` `GridCacheConcurrentMap(GridCacheContext<K,V> ctx, int initCap, float loadFactor, int concurrencyLevel)` Creates a new, empty map with the specified initial capacity, load factor and concurrency level.

### Method Summary

Methods
`Set<GridCacheEntryEx<K,V>>` `allEntries0()` Gets all internal entry set, including `GridCacheInternal` entries.
`Collection<V>` `allValues(IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)` Collection of all (possibly `null`) values.
`void` `checkConsistency()`
`boolean` `containsKey(Object key)`
`void` `decrementSize(GridCacheMapEntry<K,V> e)`
`Set<javax.cache.Cache.Entry<K,V>>` `entries(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)`
`Set<GridCacheEntryEx<K,V>>` `entries0()` Internal entry set, excluding `GridCacheInternal` entries.
`Set<javax.cache.Cache.Entry<K,V>>` `entriesx(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)` Returns entry set containing internal entries.
`GridCacheMapEntry<K,V>` `getEntry(Object key)` Returns the entry associated with the specified key in the HashMap.
`protected static int` `hash(int h)` Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions.
`void` `incrementSize(GridCacheMapEntry<K,V> e)`
`boolean` `isEmpty()`
`Set<K>` `keySet(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)` Key set.
`int` `publicSize()`
`void` `putAll(Map<? extends K,? extends V> m, long ttl)` Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
`GridCacheMapEntry<K,V>` `putEntry(long topVer, K key, V val, long ttl)`
`GridTriple<GridCacheMapEntry<K,V>>` `putEntryIfObsoleteOrAbsent(long topVer, K key, V val, long ttl, boolean create)`
`GridCacheMapEntry<K,V>` `randomEntry()`
`boolean` `removeEntry(GridCacheEntryEx<K,V> e)` Removes passed in entry if it presents in the map.
`GridCacheMapEntry<K,V>` `removeEntryIfObsolete(K key)` Removes and returns the entry associated with the specified key in the HashMap if entry is obsolete.
`void` `setEntryFactory(GridCacheMapEntryFactory<K,V> factory)` Sets factory for entries.
`int` `size()` Returns the number of key-value mappings in this map.
`Iterator<GridCacheEntryEx<K,V>>` `stripedEntryIterator(int id, int totalCnt)` Get striped entry iterator.
`String` `toString()`
`Collection<V>` `values(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)` Collection of non-`null` values.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### ctx

    protected final GridCacheContext<K,V> ctx

Cache context.

#### NON_INTERNAL_ARR

    public static final IgnitePredicate[] NON_INTERNAL_ARR

Non-internal predicate array.

### Constructor Detail

#### GridCacheConcurrentMap

    protected GridCacheConcurrentMap(GridCacheContext<K,V> ctx,
                          int initCap,
                          float loadFactor,
                          int concurrencyLevel)

Creates a new, empty map with the specified initial capacity, load factor and concurrency level.

Parameters:
  `ctx` - Cache context.
  `initCap` - the initial capacity. The implementation performs internal sizing to accommodate this many elements.
  `loadFactor` - the load factor threshold, used to control resizing. Resizing may be performed when the average number of elements per bin exceeds this threshold.
  `concurrencyLevel` - the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.
Throws:
  `IllegalArgumentException` - if the initial capacity is negative or the load factor or concurrencyLevel are non-positive.

#### GridCacheConcurrentMap

    public GridCacheConcurrentMap(GridCacheContext<K,V> ctx,
                          int initCap,
                          float loadFactor)

Creates a new, empty map with the specified initial capacity and load factor and with the default concurrencyLevel (16).

Parameters:
  `ctx` - Cache context.
  `initCap` - The implementation performs internal sizing to accommodate this many elements.
  `loadFactor` - the load factor threshold, used to control resizing. Resizing may be performed when the average number of elements per bin exceeds this threshold.
Throws:
  `IllegalArgumentException` - if the initial capacity of elements is negative or the load factor is non-positive.

#### GridCacheConcurrentMap

    public GridCacheConcurrentMap(GridCacheContext<K,V> ctx,
                          int initCap)

Creates a new, empty map with the specified initial capacity, and with default load factor (0.75) and concurrencyLevel (16).

Parameters:
  `ctx` - Cache context.
  `initCap` - the initial capacity. The implementation performs internal sizing to accommodate this many elements.
Throws:
  `IllegalArgumentException` - if the initial capacity of elements is negative.

### Method Detail

#### hash

    protected static int hash(int h)

Applies a supplemental hash function to a given hashCode, which defends against poor quality hash functions. This is critical because ConcurrentHashMap uses power-of-two length hash tables, that otherwise encounter collisions for hashCodes that do not differ in lower or upper bits.

This function has been taken from Java 8 ConcurrentHashMap with slightly modifications.

Parameters:
  `h` - Value to hash.
Returns:
  Hash value.

#### setEntryFactory

    public void setEntryFactory(GridCacheMapEntryFactory<K,V> factory)

Sets factory for entries.

Parameters:
  `factory` - Entry factory.

#### isEmpty

    public boolean isEmpty()

Returns:
  `True` if this map is empty.

#### size

    public int size()

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

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

#### publicSize

    public int publicSize()

Returns:
  Public size.

#### decrementSize

    public void decrementSize(GridCacheMapEntry<K,V> e)

Parameters:
  `e` - Cache map entry.

#### incrementSize

    public void incrementSize(GridCacheMapEntry<K,V> e)

Parameters:
  `e` - Cache map entry.

#### containsKey

    public boolean containsKey(Object key)

Parameters:
  `key` - Key.
Returns:
  `True` if map contains mapping for provided key.

#### allValues

    public Collection<V> allValues(IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)

Collection of all (possibly `null`) values.

Parameters:
  `filter` - Filter.
Returns:
  a collection view of the values contained in this map.

#### randomEntry

    @Nullable
    public GridCacheMapEntry<K,V> randomEntry()

Returns:
  Random entry out of hash map.

#### getEntry

    @Nullable
    public GridCacheMapEntry<K,V> getEntry(Object key)

Returns the entry associated with the specified key in the HashMap. Returns null if the HashMap contains no mapping for this key.

Parameters:
  `key` - Key.
Returns:
  Entry.

#### putEntry

    public GridCacheMapEntry<K,V> putEntry(long topVer,
                                  K key,
                                  @Nullable
                                  V val,
                                  long ttl)

Parameters:
  `topVer` - Topology version.
  `key` - Key.
  `val` - Value.
  `ttl` - Time to live.
Returns:
  Cache entry for corresponding key-value pair.

#### putEntryIfObsoleteOrAbsent

    public GridTriple<GridCacheMapEntry<K,V>> putEntryIfObsoleteOrAbsent(long topVer,
                                                                K key,
                                                                @Nullable
                                                                V val,
                                                                long ttl,
                                                                boolean create)

Parameters:
  `topVer` - Topology version.
  `key` - Key.
  `val` - Value.
  `ttl` - Time to live.
  `create` - Create flag.
Returns:
  Triple where the first element is current entry associated with the key, the second is created entry and the third is doomed (all may be null).

#### putAll

    public void putAll(Map<? extends K,? extends V> m,
              long ttl)

Copies all of the mappings from the specified map to this map These mappings will replace any mappings that this map had for any of the keys currently in the specified map.

Parameters:
  `m` - mappings to be stored in this map.
  `ttl` - Time to live.
Throws:
  `NullPointerException` - If the specified map is null.

#### removeEntry

    public boolean removeEntry(GridCacheEntryEx<K,V> e)

Removes passed in entry if it presents in the map.

Parameters:
  `e` - Entry to remove.
Returns:
  `True` if remove happened.

#### removeEntryIfObsolete

    @Nullable
    public GridCacheMapEntry<K,V> removeEntryIfObsolete(K key)

Removes and returns the entry associated with the specified key in the HashMap if entry is obsolete. Returns null if the HashMap contains no mapping for this key.

Parameters:
  `key` - Key.
Returns:
  Removed entry, possibly `null`.

#### entries

    public Set<javax.cache.Cache.Entry<K,V>> entries(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)

Parameters:
  `filter` - Filter.
Returns:
  Set of the mappings contained in this map.

#### entriesx

    public Set<javax.cache.Cache.Entry<K,V>> entriesx(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)

Returns entry set containing internal entries.

Parameters:
  `filter` - Filter.
Returns:
  Set of the mappings contained in this map.

#### entries0

    public Set<GridCacheEntryEx<K,V>> entries0()

Internal entry set, excluding `GridCacheInternal` entries.

Returns:
  Set of the mappings contained in this map.

#### stripedEntryIterator

    public Iterator<GridCacheEntryEx<K,V>> stripedEntryIterator(int id,
                                                       int totalCnt)

Get striped entry iterator.

Parameters:
  `id` - Expected modulo.
  `totalCnt` - Maximum modulo.
Returns:
  Striped entry iterator.

#### allEntries0

    public Set<GridCacheEntryEx<K,V>> allEntries0()

Gets all internal entry set, including `GridCacheInternal` entries.

Returns:
  All internal entry set, including `GridCacheInternal` entries.

#### keySet

    public Set<K> keySet(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)

Key set.

Parameters:
  `filter` - Filter.
Returns:
  Set of the keys contained in this map.

#### values

    public Collection<V> values(IgnitePredicate<javax.cache.Cache.Entry<K,V>>... filter)

Collection of non-`null` values.

Parameters:
  `filter` - Filter.
Returns:
  Collection view of the values contained in this map.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### checkConsistency

    public void checkConsistency()

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015