|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.groovy.runtime.metaclass.MemoryAwareConcurrentReadMap
public class MemoryAwareConcurrentReadMap
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 prefere 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.
Nested Class Summary | |
---|---|
protected static class |
MemoryAwareConcurrentReadMap.BarrierLock
A Serializable class for barrier lock |
private static class |
MemoryAwareConcurrentReadMap.DummyRef
A dummy to replace the SoftReference if needed |
private static class |
MemoryAwareConcurrentReadMap.Entry
ConcurrentReaderHashMap collision list entry. |
private static interface |
MemoryAwareConcurrentReadMap.Reference
Reference class used to support get() |
private static class |
MemoryAwareConcurrentReadMap.SoftRef
A SoftReference representing a key or value of the map. |
Field Summary | |
---|---|
protected MemoryAwareConcurrentReadMap.BarrierLock |
barrierLock
Lock used only for its memory effects. |
protected int |
count
The total number of mappings in the hash table. |
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). |
private static MemoryAwareConcurrentReadMap.Reference |
DUMMY_REF
|
protected java.lang.Object |
lastWrite
field written to only to guarantee lock ordering. |
protected float |
loadFactor
The load factor for the hash table. |
private static int |
MAXIMUM_CAPACITY
The maximum capacity, used if a higher value is implicitly specified by either of the constructors with arguments. |
private static int |
MINIMUM_CAPACITY
The minimum capacity, used if a lower value is implicitly specified by either of the constructors with arguments. |
private java.lang.ref.ReferenceQueue |
queue
|
protected MemoryAwareConcurrentReadMap.Entry[] |
table
The hash table data. |
protected int |
threshold
The table is rehashed when its size exceeds this threshold. |
Constructor Summary | |
---|---|
MemoryAwareConcurrentReadMap()
Constructs a new, empty map with a default initial capacity and load factor. |
|
MemoryAwareConcurrentReadMap(int initialCapacity)
Constructs a new, empty map with the specified initial capacity and default load factor. |
|
MemoryAwareConcurrentReadMap(int initialCapacity,
float loadFactor)
Constructs a new, empty map with the specified initial capacity and the specified load factor. |
Method Summary | |
---|---|
void |
clear()
Removes all mappings from this map. |
protected boolean |
eq(java.lang.Object x,
java.lang.Object y)
Check for referential equality, null allowed |
private void |
expungeStaleEntries()
Removes entries from the ReferenceQueue for keys and values of this map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this table. |
protected MemoryAwareConcurrentReadMap.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 |
private static int |
hash(java.lang.Object x)
Return hash code for Object x. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
private int |
p2capacity(int initialCapacity)
Returns the appropriate capacity (power of two) for the specified initial capacity argument. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Maps the specified key to the specified
value in this table. |
protected void |
recordModification(java.lang.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. |
java.lang.Object |
remove(java.lang.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 java.lang.Object |
sput(java.lang.Object key,
java.lang.Object value,
int hash)
Continuation of put(), called only when synch lock is held and interference has been detected. |
protected java.lang.Object |
sremove(java.lang.Object key,
int hash)
Continuation of remove(), called only when synch lock is held and interference has been detected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final MemoryAwareConcurrentReadMap.BarrierLock barrierLock
protected transient java.lang.Object lastWrite
public static final int DEFAULT_INITIAL_CAPACITY
private static final int MINIMUM_CAPACITY
private static final int MAXIMUM_CAPACITY
public static final float DEFAULT_LOAD_FACTOR
protected transient MemoryAwareConcurrentReadMap.Entry[] table
protected transient int count
protected int threshold
protected float loadFactor
private java.lang.ref.ReferenceQueue queue
private static final MemoryAwareConcurrentReadMap.Reference DUMMY_REF
Constructor Detail |
---|
public MemoryAwareConcurrentReadMap(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity
The actual initial capacity is rounded to the nearest power of two.loadFactor
- the load factor of the ConcurrentReaderHashMap
java.lang.IllegalArgumentException
- if the initial maximum number
of elements is less
than zero, or if the load factor is nonpositive.public MemoryAwareConcurrentReadMap(int initialCapacity)
initialCapacity
- the initial capacity of the
ConcurrentReaderHashMap.
java.lang.IllegalArgumentException
- if the initial maximum number
of elements is less
than zero.public MemoryAwareConcurrentReadMap()
Method Detail |
---|
protected final void recordModification(java.lang.Object x)
protected final MemoryAwareConcurrentReadMap.Entry[] getTableForReading()
private int p2capacity(int initialCapacity)
private static int hash(java.lang.Object x)
protected boolean eq(java.lang.Object x, java.lang.Object y)
public int size()
public boolean isEmpty()
public java.lang.Object get(java.lang.Object key)
key
- a key in the table.
null
if the key is not mapped to any value in
this table.
java.lang.NullPointerException
- if the key is
null
.put(Object, Object)
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
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.
key
- the table key.value
- the value.
null
if it did not have one.
java.lang.NullPointerException
- if the key or value is
null
.get(Object)
protected java.lang.Object sput(java.lang.Object key, java.lang.Object value, int hash)
protected void rehash()
public java.lang.Object remove(java.lang.Object key)
key
- the key that needs to be removed.
null
if the key did not have a mapping.
java.lang.NullPointerException
- if the key is
null
.protected java.lang.Object sremove(java.lang.Object key, int hash)
public void clear()
private void expungeStaleEntries()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |