|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractMap
org.norther.tammi.acorn.util.ConcurrentAbstractMap
org.norther.tammi.acorn.util.ConcurrentWriteMap
public class ConcurrentWriteMap
An implementation of the Map interface that supports both
thread-safe concurrent reading and concurrent writing. This makes it an
interesting choice for writer oriented tasks that require good performance in
a multithreaded context provided by minor synchronization.
There is NOT any support for locking the entire map to prevent
updates. This makes it impossible, for example, to add an element only if it
is not already present, since another thread may be in the process of doing
the same thing. If you need such capabilities, consider instead using the
ConcurrentReadMap class.
Iterators and Enumerations return elements reflecting the state of the map at some point at or since the creation of the iterator/enumeration. They do not throw ConcurrentModificationException.
This class allows null to be used as a key or value.
Based on Doug Lea's ConcurrentHashMap .
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap |
|---|
ConcurrentAbstractMap.Entry |
| Field Summary | |
|---|---|
protected static int |
DEFAULT_CAPACITY
The default capacity. |
protected static int |
MAXIMUM_CAPACITY
The maximum capacity. |
protected static int |
MINIMUM_CAPACITY
The minimum capacity. |
| Fields inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap |
|---|
DEFAULT_LOAD_FACTOR |
| Constructor Summary | |
|---|---|
ConcurrentWriteMap()
Constructs a new, empty map with a default capacity and load factor. |
|
ConcurrentWriteMap(int capacity)
Constructs a new, empty map with the specified initial capacity and default load factor. |
|
ConcurrentWriteMap(int capacity,
float factor)
Constructs a new, empty map with the specified initial capacity and the specified load factor. |
|
ConcurrentWriteMap(Map map)
Constructs a new map with the same mappings as the given map. |
|
| Method Summary | |
|---|---|
protected int |
capacity(int capacity)
Returns the appropriate capacity for the expected maximum capacity. |
void |
clear()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
protected ConcurrentAbstractMap.Entry |
getEntry(Object key)
Gets the internal entry mapped to the specified key. |
protected Object |
getInternal(Object key)
Gets the internal value mapped to the specified key. |
protected ConcurrentAbstractMap.Entry[] |
getReadTable()
Gets the internal read table. |
protected ConcurrentAbstractMap.Entry[] |
getWriteTable()
Gets the internal write table. |
boolean |
isEmpty()
|
void |
putAll(Map map)
|
protected Object |
putInternal(Object key,
Object value,
boolean r)
Puts the internal value mapped to the specified key. |
protected void |
rehash()
Rehashes the contents of this map into a new table with a larger capacity. |
protected Object |
removeInternal(Object key,
Object value)
Removes the internal mapping with the optional value. |
protected Object |
replaceInternal(Object key,
Object oldValue,
Object newValue)
Replaces the internal value mapped to the specified key with the optional value. |
protected void |
resize(int index,
ConcurrentAbstractMap.Entry[] assumedTab)
Gathers all locks in order to call rehash, by recursing within synch blocks for each segment index. |
protected void |
setWriteTable(ConcurrentAbstractMap.Entry[] tab)
Sets the internal write table. |
int |
size()
|
| Methods inherited from class org.norther.tammi.acorn.util.ConcurrentAbstractMap |
|---|
add, capacity, clone, contains, elements, entrySet, get, hash, keys, keySet, put, putIfAbsent, remove, remove, replace, replace, values |
| Methods inherited from class java.util.AbstractMap |
|---|
equals, hashCode, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode |
| Field Detail |
|---|
protected static final int MAXIMUM_CAPACITY
protected static final int MINIMUM_CAPACITY
protected static final int DEFAULT_CAPACITY
| Constructor Detail |
|---|
public ConcurrentWriteMap()
public ConcurrentWriteMap(int capacity)
Note that the initial capacity will be rounded to the nearest power of two.
capacity - the initial capacity.
IllegalArgumentException - for negative values.
public ConcurrentWriteMap(int capacity,
float factor)
Note that the initial capacity will be rounded to the nearest power of two.
The load factor is used in an approximate way. When at least a quarter of the segments of the table reach per-segment threshold, or one of the segments itself exceeds overall threshold, the table is doubled. This will on average cause resizing when the table-wide load factor is slightly less than the threshold. If you'd like to avoid resizing, you can set this to a ridiculously large value.
capacity - the initial capacity.factor - the load factor threshold, used to control resizing.
IllegalArgumentException - for negative values.public ConcurrentWriteMap(Map map)
map - the map to copy.| Method Detail |
|---|
public int size()
size in interface Mapsize in class AbstractMappublic boolean isEmpty()
isEmpty in interface MapisEmpty in class AbstractMappublic boolean containsKey(Object key)
containsKey in interface MapcontainsKey in class AbstractMappublic boolean containsValue(Object value)
containsValue in interface MapcontainsValue in class AbstractMappublic void putAll(Map map)
putAll in interface MapputAll in class AbstractMappublic void clear()
clear in interface Mapclear in class AbstractMapprotected int capacity(int capacity)
ConcurrentAbstractMap
capacity in class ConcurrentAbstractMapcapacity - the desired capacity.
protected final ConcurrentAbstractMap.Entry[] getReadTable()
ConcurrentAbstractMap
getReadTable in class ConcurrentAbstractMapprotected final ConcurrentAbstractMap.Entry[] getWriteTable()
ConcurrentAbstractMap
getWriteTable in class ConcurrentAbstractMapprotected final void setWriteTable(ConcurrentAbstractMap.Entry[] tab)
ConcurrentAbstractMap
setWriteTable in class ConcurrentAbstractMaptab - the write table.protected ConcurrentAbstractMap.Entry getEntry(Object key)
ConcurrentAbstractMap
getEntry in class ConcurrentAbstractMapkey - the key.
protected Object getInternal(Object key)
ConcurrentAbstractMap
getInternal in class ConcurrentAbstractMapkey - the key.
protected Object putInternal(Object key,
Object value,
boolean r)
ConcurrentAbstractMap
putInternal in class ConcurrentAbstractMapkey - the key.value - the value.r - if true, replace an existing mapping.
protected Object replaceInternal(Object key,
Object oldValue,
Object newValue)
ConcurrentAbstractMap
replaceInternal in class ConcurrentAbstractMapkey - the key.oldValue - the old value.newValue - the new value.
protected Object removeInternal(Object key,
Object value)
ConcurrentAbstractMap
removeInternal in class ConcurrentAbstractMapkey - the key.value - the value.
protected void rehash()
protected void resize(int index,
ConcurrentAbstractMap.Entry[] assumedTab)
index - the current segment, initially call value must be 0.assumedTab - the state of table on first call to resize; if this
changes on any call, the attempt is aborted because the table has
already been resized by another thread.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||