Groovy 1.7.10

## org.codehaus.groovy.runtime.metaclass
[Java] Class MemoryAwareConcurrentReadMap

    java.lang.Object
      org.codehaus.groovy.runtime.metaclass.MemoryAwareConcurrentReadMap

    public class MemoryAwareConcurrentReadMap
    extends Object

This Map is a stripped down version of ConcurrentReaderHashMap with small modifications here and there. It is no full Map, it does have put/get/remove, but no iterators. This map is intended to hold values and keys as SoftReference. If one of value or key are removed, so will be complete entry. This map will not use the equals method to compare keys, think of it as a IdentityHashMap with features of concurrency and memory aware caching. As ConcurrentReaderHashMap also does this implementation prefer read operations and tries not to lock if possible. SoftReferenced values are only removed from the map if the map goes into a synchronization block on this. This may affect reads, but only in rare cases.

Authors:
  Adapted from ConcurrentHashMap (Doug Lea)
  adapted by the Groovy community

Nested Class Summary
`protected static class` | `MemoryAwareConcurrentReadMap.BarrierLock` A Serializable class for barrier lock *

Field Summary
`static int` | `DEFAULT_INITIAL_CAPACITY` The default initial number of table slots for this table (32).
`static float` | `DEFAULT_LOAD_FACTOR` The default load factor for this table (1.0).
`protected MemoryAwareConcurrentReadMap.BarrierLock` | `barrierLock` Lock used only for its memory effects.
`protected int` | `count` The total number of mappings in the hash table.
`protected Object` | `lastWrite` field written to only to guarantee lock ordering.
`protected float` | `loadFactor` The load factor for the hash table.
`protected Entry[]` | `table` The hash table data.
`protected int` | `threshold` The table is rehashed when its size exceeds this threshold.

Method Summary
`def` | `MemoryAwareConcurrentReadMap(int initialCapacity, float loadFactor)` Constructs a new, empty map with the specified initial capacity and the specified load factor.
`def` | `MemoryAwareConcurrentReadMap(int initialCapacity)` Constructs a new, empty map with the specified initial capacity and default load factor.
`def` | `MemoryAwareConcurrentReadMap()` Constructs a new, empty map with a default initial capacity and load factor.
`void` | `clear()` Removes all mappings from this map.
`protected boolean` | `eq(Object x, Object y)` Check for referential equality, null allowed
`Object` | `get(Object key)` Returns the value to which the specified key is mapped in this table.
`protected Entry[]` | `getTableForReading()` Get ref to table; the reference and the cells it accesses will be at least as fresh as from last use of barrierLock
`boolean` | `isEmpty()` Returns `true` if this map contains no key-value mappings.
`Object` | `put(Object key, Object value)` Maps the specified `key` to the specified `value` in this table.
`protected void` | `recordModification(Object x)` Force a memory synchronization that will cause all readers to see table.
`protected void` | `rehash()` Rehashes the contents of this map into a new table with a larger capacity.
`Object` | `remove(Object key)` Removes the key (and its corresponding value) from this table.
`int` | `size()` Returns the number of key-value mappings in this map.
`protected Object` | `sput(Object key, Object value, int hash)` Continuation of put(), called only when synch lock is held and interference has been detected.
`protected Object` | `sremove(Object key, int hash)` Continuation of remove(), called only when synch lock is held and interference has been detected.

Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Field Detail

### DEFAULT_INITIAL_CAPACITY

    public static final int DEFAULT_INITIAL_CAPACITY

  The default initial number of table slots for this table (32). Used when not otherwise specified in constructor.

### DEFAULT_LOAD_FACTOR

    public static final float DEFAULT_LOAD_FACTOR

  The default load factor for this table (1.0). Used when not otherwise specified in constructor.

### barrierLock

    protected final MemoryAwareConcurrentReadMap.BarrierLock barrierLock

  Lock used only for its memory effects.

### count

    protected int count

  The total number of mappings in the hash table.

### lastWrite

    protected Object lastWrite

  field written to only to guarantee lock ordering.

### loadFactor

    protected float loadFactor

  The load factor for the hash table.
  serial:

### table

    protected Entry[] table

  The hash table data.

### threshold

    protected int threshold

  The table is rehashed when its size exceeds this threshold. (The value of this field is always (int)(capacity * loadFactor).)
  serial:

Method Detail

### MemoryAwareConcurrentReadMap

    public def MemoryAwareConcurrentReadMap(int initialCapacity, float loadFactor)

  Constructs a new, empty map with the specified initial capacity and the specified load factor.
  throws:
    IllegalArgumentException if the initial maximum number of elements is less than zero, or if the load factor is non-positive.
  Parameters:
    `initialCapacity` - the initial capacity The actual initial capacity is rounded to the nearest power of two.
    `loadFactor` - the load factor of the ConcurrentReaderHashMap

### MemoryAwareConcurrentReadMap

    public def MemoryAwareConcurrentReadMap(int initialCapacity)

  Constructs a new, empty map with the specified initial capacity and default load factor.
  throws:
    IllegalArgumentException if the initial maximum number of elements is less than zero.
  Parameters:
    `initialCapacity` - the initial capacity of the ConcurrentReaderHashMap.

### MemoryAwareConcurrentReadMap

    public def MemoryAwareConcurrentReadMap()

  Constructs a new, empty map with a default initial capacity and load factor.

### clear

    public void clear()

  Removes all mappings from this map.

### eq

    protected boolean eq(Object x, Object y)

  Check for referential equality, null allowed

### get

    public Object get(Object key)

  Returns the value to which the specified key is mapped in this table.
  Throws:
    NullPointerException if the key is `null`.
  Parameters:
    `key` - a key in the table.
  Returns:
    the value to which the key is mapped in this table; `null` if the key is not mapped to any value in this table.
  See Also:
    put(Object, Object)

### getTableForReading

    protected final Entry[] getTableForReading()

  Get ref to table; the reference and the cells it accesses will be at least as fresh as from last use of barrierLock

### isEmpty

    public boolean isEmpty()

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

### put

    public Object put(Object key, Object value)

  Maps the specified `key` to the specified `value` in this table. Neither the key nor the value can be `null`.

  The value can be retrieved by calling the `get` method with a key that is equal to the original key.

  Throws:
    NullPointerException if the key or value is `null`.
  Parameters:
    `key` - the table key.
    `value` - the value.
  Returns:
    the previous value of the specified key in this table, or `null` if it did not have one.
  See Also:
    get(Object)

### recordModification

    protected final void recordModification(Object x)

  Force a memory synchronization that will cause all readers to see table. Call only when already holding main synch lock.

### rehash

    protected void rehash()

  Rehashes the contents of this map into a new table with a larger capacity. This method is called automatically when the number of keys in this map exceeds its capacity and load factor.

### remove

    public Object remove(Object key)

  Removes the key (and its corresponding value) from this table. This method does nothing if the key is not in the table.
  Throws:
    NullPointerException if the key is `null`.
  Parameters:
    `key` - the key that needs to be removed.
  Returns:
    the value to which the key had been mapped in this table, or `null` if the key did not have a mapping.

### size

    public int size()

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

### sput

    protected Object sput(Object key, Object value, int hash)

  Continuation of put(), called only when synch lock is held and interference has been detected.

### sremove

    protected Object sremove(Object key, int hash)

  Continuation of remove(), called only when synch lock is held and interference has been detected.

Copyright © 2003-2010 The Codehaus. All rights reserved.