|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.threads.AtomicArray<T,V>
T
- the type which contains the target fieldV
- the array value typepublic final class AtomicArray<T,V>
Utility for snapshot/copy-on-write arrays. To use these methods, two things are required: an immutable array
stored on a volatile field, and an instance of
AtomicReferenceFieldUpdater
which corresponds to that field. Some of these methods perform multi-step operations; if the array field value is
changed in the middle of such an operation, the operation is retried. To avoid spinning, in some situations it
may be advisable to hold a write lock to prevent multiple concurrent updates.
Constructor Summary | |
---|---|
AtomicArray(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,V[]> updater,
java.lang.Class<V> componentType)
Construct an instance. |
Method Summary | ||
---|---|---|
void |
add(T instance,
V value)
Atomically replace the array with a new array which is one element longer, and which includes the given value. |
|
void |
add(T instance,
V value,
java.util.Comparator<? super V> comparator)
Add a value to a sorted array. |
|
boolean |
addIfAbsent(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which is one element longer, and which includes the given value, if the value is not already present within the array. |
|
boolean |
addIfAbsent(T instance,
V value,
java.util.Comparator<? super V> comparator)
Add a value to a sorted array if it is not already present. |
|
void |
clear(T instance)
Convenience method to set the field value to the empty array. |
|
static
|
create(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,V[]> updater,
java.lang.Class<V> componentType)
Convenience method to create an instance. |
|
V[] |
getAndSet(T instance,
V[] value)
Atomically get and update the value of this array. |
|
boolean |
remove(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which does not include the first occurrance of the given value, if the value is present in the array. |
|
boolean |
remove(T instance,
V value,
java.util.Comparator<? super V> comparator)
Remove a value to a sorted array. |
|
int |
removeAll(T instance,
V value,
boolean identity)
Atomically replace the array with a new array which does not include any occurrances of the given value, if the value is present in the array. |
|
void |
set(T instance,
V[] value)
Update the value of this array. |
|
void |
sort(T instance,
java.util.Comparator<? super V> comparator)
Sort an array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AtomicArray(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,V[]> updater, java.lang.Class<V> componentType)
updater
- the field updatercomponentType
- the component classMethod Detail |
---|
public static <T,V> AtomicArray<T,V> create(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,V[]> updater, java.lang.Class<V> componentType)
T
- the type which contains the target fieldV
- the array value typeupdater
- the field updatercomponentType
- the component class
public void clear(T instance)
instance
- the instance holding the fieldpublic void set(T instance, V[] value)
instance
- the instance holding the fieldvalue
- the new valuepublic V[] getAndSet(T instance, V[] value)
instance
- the instance holding the fieldvalue
- the new valuepublic void add(T instance, V value)
instance
- the instance holding the fieldvalue
- the updated valuepublic boolean addIfAbsent(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
method
true
if the value was added, or false
if it was already presentpublic boolean remove(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
method
true
if the value was removed, or false
if it was not presentpublic int removeAll(T instance, V value, boolean identity)
instance
- the instance holding the fieldvalue
- the updated valueidentity
- true
if comparisons should be done using reference identity, or false
to use the equals()
method
public void add(T instance, V value, java.util.Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to addcomparator
- a comparator, or null
to use natural orderingpublic boolean addIfAbsent(T instance, V value, java.util.Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to addcomparator
- a comparator, or null
to use natural orderingpublic boolean remove(T instance, V value, java.util.Comparator<? super V> comparator)
instance
- the instance holding the fieldvalue
- the value to removecomparator
- a comparator, or null
to use natural orderingpublic void sort(T instance, java.util.Comparator<? super V> comparator)
instance
- the instance holding the fieldcomparator
- a comparator, or null
to use natural ordering
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |