com.atlassian.plugin.util.concurrent
Class CopyOnWriteMap<K,V>

java.lang.Object
  extended by com.atlassian.util.concurrent.CopyOnWriteMap<K,V>
      extended by com.atlassian.plugin.util.concurrent.CopyOnWriteMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.ConcurrentMap<K,V>, java.util.Map<K,V>

Deprecated. since 2.5.0 please use the CopyOnWriteMap instead as it has some important features and some bug fixes. This version is no longer maintained.

@Deprecated
public abstract class CopyOnWriteMap<K,V>
extends com.atlassian.util.concurrent.CopyOnWriteMap<K,V>

A thread-safe variant of Map in which all mutative operations (the "destructive" operations described by Map put, remove and so on) are implemented by making a fresh copy of the underlying map.

This is ordinarily too costly, but may be more efficient than alternatives when traversal operations vastly out-number mutations, and is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads. The "snapshot" style iterators on the collections returned by entrySet(), keySet() and values() use a reference to the internal map at the point that the iterator was created. This map never changes during the lifetime of the iterator, so interference is impossible and the iterator is guaranteed not to throw ConcurrentModificationException. The iterators will not reflect additions, removals, or changes to the list since the iterator was created. Removing elements via these iterators is not supported. The mutable operations on these collections (remove, retain etc.) are supported but as with the Map interface, add and addAll are not and throw UnsupportedOperationException.

The actual copy is performed by an abstract CopyOnWriteMap.copy(Map) method. The method is responsible for the underlying Map implementation (for instance a HashMap, TreeMap, LinkedHashMap etc.) and therefore the semantics of what this map will cope with as far as null keys and values, iteration ordering etc. See the note below about suitable candidates for underlying Map implementations

There are supplied implementations for the common Collections Map implementations via the CopyOnWriteMaps static factory methods.

Collection views of the keys, values and entries are modifiable and will cause a copy.

Please note that the thread-safety guarantees are limited to the thread-safety of the non-mutative (non-destructive) operations of the underlying map implementation. For instance some implementations such as WeakHashMap and LinkedHashMap with access ordering are actually structurally modified by the get(Object) method and are therefore not suitable candidates as delegates for this class.

See Also:
Serialized Form

Nested Class Summary
protected static class com.atlassian.util.concurrent.AbstractCopyOnWriteMap.CollectionView<E>
           
static class com.atlassian.util.concurrent.AbstractCopyOnWriteMap.View<K,V>
           
 
Nested classes/interfaces inherited from class com.atlassian.util.concurrent.CopyOnWriteMap
com.atlassian.util.concurrent.CopyOnWriteMap.Builder<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
CopyOnWriteMap()
          Deprecated. Create a new empty CopyOnWriteMap.
CopyOnWriteMap(java.util.Map<? extends K,? extends V> map)
          Deprecated. Create a new CopyOnWriteMap with the supplied Map to initialize the values.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object arg0)
           
 boolean containsValue(java.lang.Object arg0)
           
protected  M copy()
           
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 boolean equals(java.lang.Object arg0)
           
 V get(java.lang.Object arg0)
           
protected  M getDelegate()
           
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
           
static
<K,V> CopyOnWriteMap<K,V>
newHashMap()
          Deprecated. Creates a new CopyOnWriteMap with an underlying HashMap.
static
<K,V> CopyOnWriteMap<K,V>
newHashMap(java.util.Map<? extends K,? extends V> map)
          Deprecated. Creates a new CopyOnWriteMap with an underlying HashMap using the supplied map as the initial values.
static
<K,V> CopyOnWriteMap<K,V>
newLinkedMap()
          Deprecated. Creates a new CopyOnWriteMap with an underlying LinkedHashMap.
static
<K,V> CopyOnWriteMap<K,V>
newLinkedMap(java.util.Map<? extends K,? extends V> map)
          Deprecated. Creates a new CopyOnWriteMap with an underlying LinkedHashMap using the supplied map as the initial values.
 V put(K arg0, V arg1)
           
 void putAll(java.util.Map<? extends K,? extends V> arg0)
           
 V remove(java.lang.Object arg0)
           
protected  void set(M arg0)
           
 int size()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class com.atlassian.util.concurrent.CopyOnWriteMap
builder, copy
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CopyOnWriteMap

public CopyOnWriteMap(java.util.Map<? extends K,? extends V> map)
Deprecated. 
Create a new CopyOnWriteMap with the supplied Map to initialize the values.

Parameters:
map - the initial map to initialize with

CopyOnWriteMap

public CopyOnWriteMap()
Deprecated. 
Create a new empty CopyOnWriteMap.

Method Detail

newHashMap

public static <K,V> CopyOnWriteMap<K,V> newHashMap()
Deprecated. 
Creates a new CopyOnWriteMap with an underlying HashMap.


newHashMap

public static <K,V> CopyOnWriteMap<K,V> newHashMap(java.util.Map<? extends K,? extends V> map)
Deprecated. 
Creates a new CopyOnWriteMap with an underlying HashMap using the supplied map as the initial values.


newLinkedMap

public static <K,V> CopyOnWriteMap<K,V> newLinkedMap()
Deprecated. 
Creates a new CopyOnWriteMap with an underlying LinkedHashMap. Iterators for this map will be return elements in insertion order.


newLinkedMap

public static <K,V> CopyOnWriteMap<K,V> newLinkedMap(java.util.Map<? extends K,? extends V> map)
Deprecated. 
Creates a new CopyOnWriteMap with an underlying LinkedHashMap using the supplied map as the initial values. Iterators for this map will be return elements in insertion order.


clear

public final void clear()
Specified by:
clear in interface java.util.Map<K,V>

remove

public final V remove(java.lang.Object arg0)
Specified by:
remove in interface java.util.Map<K,V>

put

public final V put(K arg0,
                   V arg1)
Specified by:
put in interface java.util.Map<K,V>

putAll

public final void putAll(java.util.Map<? extends K,? extends V> arg0)
Specified by:
putAll in interface java.util.Map<K,V>

copy

protected M copy()

set

protected void set(M arg0)

entrySet

public final java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>

keySet

public final java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,V>

values

public final java.util.Collection<V> values()
Specified by:
values in interface java.util.Map<K,V>

containsKey

public final boolean containsKey(java.lang.Object arg0)
Specified by:
containsKey in interface java.util.Map<K,V>

containsValue

public final boolean containsValue(java.lang.Object arg0)
Specified by:
containsValue in interface java.util.Map<K,V>

get

public final V get(java.lang.Object arg0)
Specified by:
get in interface java.util.Map<K,V>

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,V>

size

public final int size()
Specified by:
size in interface java.util.Map<K,V>

equals

public final boolean equals(java.lang.Object arg0)
Specified by:
equals in interface java.util.Map<K,V>
Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()
Specified by:
hashCode in interface java.util.Map<K,V>
Overrides:
hashCode in class java.lang.Object

getDelegate

protected final M getDelegate()


Copyright © 2010 Atlassian. All Rights Reserved.