org.infinispan.util.concurrent.jdk8backported
Class ConcurrentHashMapV8.Parallel
java.lang.Object
org.infinispan.util.concurrent.jdk8backported.ConcurrentHashMapV8.Parallel
- Enclosing class:
- ConcurrentHashMapV8<K,V>
public class ConcurrentHashMapV8.Parallel
- extends Object
An extended view of a ConcurrentHashMap supporting bulk
parallel operations. These operations are designed to be
safely, and often sensibly, applied even with maps that are
being concurrently updated by other threads; for example, when
computing a snapshot summary of the values in a shared
registry. There are three kinds of operation, each with four
forms, accepting functions with Keys, Values, Entries, and
(Key, Value) arguments and/or return values. Because the
elements of a ConcurrentHashMap are not ordered in any
particular way, and may be processed in different orders in
different parallel executions, the correctness of supplied
functions should not depend on any ordering, or on any other
objects or values that may transiently change while computation
is in progress; and except for forEach actions, should ideally
be side-effect-free.
- forEach: Perform a given action on each element.
A variant form applies a given transformation on each element
before performing the action.
- search: Return the first available non-null result of
applying a given function on each element; skipping further
search when a result is found.
- reduce: Accumulate each element. The supplied reduction
function cannot rely on ordering (more formally, it should be
both associative and commutative). There are five variants:
- Plain reductions. (There is not a form of this method for
(key, value) function arguments since there is no corresponding
return type.)
- Mapped reductions that accumulate the results of a given
function applied to each element.
- Reductions to scalar doubles, longs, and ints, using a
given basis value.
The concurrency properties of the bulk operations follow
from those of ConcurrentHashMap: Any non-null result returned
from get(key)
and related access methods bears a
happens-before relation with the associated insertion or
update. The result of any bulk operation reflects the
composition of these per-element relations (but is not
necessarily atomic with respect to the map as a whole unless it
is somehow known to be quiescent). Conversely, because keys
and values in the map are never null, null serves as a reliable
atomic indicator of the current lack of any result. To
maintain this property, null serves as an implicit basis for
all non-scalar reduction operations. For the double, long, and
int versions, the basis should be one that, when combined with
any other value, returns that other value (more formally, it
should be the identity element for the reduction). Most common
reductions have these properties; for example, computing a sum
with basis 0 or a minimum with basis MAX_VALUE.
Search and transformation functions provided as arguments
should similarly return null to indicate the lack of any result
(in which case it is not used). In the case of mapped
reductions, this also enables transformations to serve as
filters, returning null (or, in the case of primitive
specializations, the identity basis) if the element should not
be combined. You can create compound transformations and
filterings by composing them yourself under this "null means
there is nothing there now" rule before using them in search or
reduce operations.
Methods accepting and/or returning Entry arguments maintain
key-value associations. They may be useful for example when
finding the key for the greatest value. Note that "plain" Entry
arguments can be supplied using new
AbstractMap.SimpleEntry(k,v)
.
Bulk operations may complete abruptly, throwing an
exception encountered in the application of a supplied
function. Bear in mind when handling such exceptions that other
concurrently executing functions could also have thrown
exceptions, or would have done so if the first exception had
not occurred.
Parallel speedups compared to sequential processing are
common but not guaranteed. Operations involving brief
functions on small maps may execute more slowly than sequential
loops if the underlying work to parallelize the computation is
more expensive than the computation itself. Similarly,
parallelization may not lead to much actual parallelism if all
processors are busy performing unrelated tasks.
All arguments to all task methods must be non-null.
jsr166e note: During transition, this class
uses nested functional interfaces with different names but the
same forms as those expected for JDK8.
Method Summary |
void |
forEach(ConcurrentHashMapV8.BiAction<K,V> action)
Performs the given action for each (key, value). |
|
forEach(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
Performs the given action for each non-null transformation
of each (key, value). |
void |
forEachEntry(ConcurrentHashMapV8.Action<Map.Entry<K,V>> action)
Performs the given action for each entry. |
|
forEachEntry(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
Performs the given action for each non-null transformation
of each entry. |
void |
forEachKey(ConcurrentHashMapV8.Action<K> action)
Performs the given action for each key. |
|
forEachKey(ConcurrentHashMapV8.Fun<? super K,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
Performs the given action for each non-null transformation
of each key. |
void |
forEachValue(ConcurrentHashMapV8.Action<V> action)
Performs the given action for each value. |
|
forEachValue(ConcurrentHashMapV8.Fun<? super V,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
Performs the given action for each non-null transformation
of each value. |
|
reduce(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, or null if none. |
Map.Entry<K,V> |
reduceEntries(ConcurrentHashMapV8.BiFun<Map.Entry<K,V>,Map.Entry<K,V>,? extends Map.Entry<K,V>> reducer)
Returns the result of accumulating all entries using the
given reducer to combine values, or null if none. |
|
reduceEntries(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
or null if none. |
double |
reduceEntriesToDouble(ConcurrentHashMapV8.ObjectToDouble<Map.Entry<K,V>> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value. |
int |
reduceEntriesToInt(ConcurrentHashMapV8.ObjectToInt<Map.Entry<K,V>> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value. |
long |
reduceEntriesToLong(ConcurrentHashMapV8.ObjectToLong<Map.Entry<K,V>> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value. |
K |
reduceKeys(ConcurrentHashMapV8.BiFun<? super K,? super K,? extends K> reducer)
Returns the result of accumulating all keys using the given
reducer to combine values, or null if none. |
|
reduceKeys(ConcurrentHashMapV8.Fun<? super K,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, or
null if none. |
double |
reduceKeysToDouble(ConcurrentHashMapV8.ObjectToDouble<? super K> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value. |
int |
reduceKeysToInt(ConcurrentHashMapV8.ObjectToInt<? super K> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value. |
long |
reduceKeysToLong(ConcurrentHashMapV8.ObjectToLong<? super K> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value. |
double |
reduceToDouble(ConcurrentHashMapV8.ObjectByObjectToDouble<? super K,? super V> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value. |
int |
reduceToInt(ConcurrentHashMapV8.ObjectByObjectToInt<? super K,? super V> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value. |
long |
reduceToLong(ConcurrentHashMapV8.ObjectByObjectToLong<? super K,? super V> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value. |
V |
reduceValues(ConcurrentHashMapV8.BiFun<? super V,? super V,? extends V> reducer)
Returns the result of accumulating all values using the
given reducer to combine values, or null if none. |
|
reduceValues(ConcurrentHashMapV8.Fun<? super V,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
Returns the result of accumulating the given transformation
of all values using the given reducer to combine values, or
null if none. |
double |
reduceValuesToDouble(ConcurrentHashMapV8.ObjectToDouble<? super V> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value. |
int |
reduceValuesToInt(ConcurrentHashMapV8.ObjectToInt<? super V> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value. |
long |
reduceValuesToLong(ConcurrentHashMapV8.ObjectToLong<? super V> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value. |
|
search(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> searchFunction)
Returns a non-null result from applying the given search
function on each (key, value), or null if none. |
|
searchEntries(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> searchFunction)
Returns a non-null result from applying the given search
function on each entry, or null if none. |
|
searchKeys(ConcurrentHashMapV8.Fun<? super K,? extends U> searchFunction)
Returns a non-null result from applying the given search
function on each key, or null if none. |
|
searchValues(ConcurrentHashMapV8.Fun<? super V,? extends U> searchFunction)
Returns a non-null result from applying the given search
function on each value, or null if none. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConcurrentHashMapV8.Parallel
public ConcurrentHashMapV8.Parallel(ForkJoinPool executor)
- Returns an extended view of this map using the given
executor for bulk parallel operations.
- Parameters:
executor
- the executor
forEach
public void forEach(ConcurrentHashMapV8.BiAction<K,V> action)
- Performs the given action for each (key, value).
- Parameters:
action
- the action
forEach
public <U> void forEach(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
- Performs the given action for each non-null transformation
of each (key, value).
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case the action is not applied).action
- the action
search
public <U> U search(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> searchFunction)
- Returns a non-null result from applying the given search
function on each (key, value), or null if none. Upon
success, further element processing is suppressed and the
results of any other parallel invocations of the search
function are ignored.
- Parameters:
searchFunction
- a function returning a non-null
result on success, else null
- Returns:
- a non-null result from applying the given search
function on each (key, value), or null if none
reduce
public <U> U reduce(ConcurrentHashMapV8.BiFun<? super K,? super V,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
- Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, or null if none.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case it is not combined).reducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all (key, value) pairs
reduceToDouble
public double reduceToDouble(ConcurrentHashMapV8.ObjectByObjectToDouble<? super K,? super V> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
- Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all (key, value) pairs
reduceToLong
public long reduceToLong(ConcurrentHashMapV8.ObjectByObjectToLong<? super K,? super V> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
- Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all (key, value) pairs
reduceToInt
public int reduceToInt(ConcurrentHashMapV8.ObjectByObjectToInt<? super K,? super V> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
- Returns the result of accumulating the given transformation
of all (key, value) pairs using the given reducer to
combine values, and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all (key, value) pairs
forEachKey
public void forEachKey(ConcurrentHashMapV8.Action<K> action)
- Performs the given action for each key.
- Parameters:
action
- the action
forEachKey
public <U> void forEachKey(ConcurrentHashMapV8.Fun<? super K,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
- Performs the given action for each non-null transformation
of each key.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case the action is not applied).action
- the action
searchKeys
public <U> U searchKeys(ConcurrentHashMapV8.Fun<? super K,? extends U> searchFunction)
- Returns a non-null result from applying the given search
function on each key, or null if none. Upon success,
further element processing is suppressed and the results of
any other parallel invocations of the search function are
ignored.
- Parameters:
searchFunction
- a function returning a non-null
result on success, else null
- Returns:
- a non-null result from applying the given search
function on each key, or null if none
reduceKeys
public K reduceKeys(ConcurrentHashMapV8.BiFun<? super K,? super K,? extends K> reducer)
- Returns the result of accumulating all keys using the given
reducer to combine values, or null if none.
- Parameters:
reducer
- a commutative associative combining function
- Returns:
- the result of accumulating all keys using the given
reducer to combine values, or null if none
reduceKeys
public <U> U reduceKeys(ConcurrentHashMapV8.Fun<? super K,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
- Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, or
null if none.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case it is not combined).reducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all keys
reduceKeysToDouble
public double reduceKeysToDouble(ConcurrentHashMapV8.ObjectToDouble<? super K> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
- Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all keys
reduceKeysToLong
public long reduceKeysToLong(ConcurrentHashMapV8.ObjectToLong<? super K> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
- Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all keys
reduceKeysToInt
public int reduceKeysToInt(ConcurrentHashMapV8.ObjectToInt<? super K> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
- Returns the result of accumulating the given transformation
of all keys using the given reducer to combine values, and
the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all keys
forEachValue
public void forEachValue(ConcurrentHashMapV8.Action<V> action)
- Performs the given action for each value.
- Parameters:
action
- the action
forEachValue
public <U> void forEachValue(ConcurrentHashMapV8.Fun<? super V,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
- Performs the given action for each non-null transformation
of each value.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case the action is not applied).
searchValues
public <U> U searchValues(ConcurrentHashMapV8.Fun<? super V,? extends U> searchFunction)
- Returns a non-null result from applying the given search
function on each value, or null if none. Upon success,
further element processing is suppressed and the results of
any other parallel invocations of the search function are
ignored.
- Parameters:
searchFunction
- a function returning a non-null
result on success, else null
- Returns:
- a non-null result from applying the given search
function on each value, or null if none
reduceValues
public V reduceValues(ConcurrentHashMapV8.BiFun<? super V,? super V,? extends V> reducer)
- Returns the result of accumulating all values using the
given reducer to combine values, or null if none.
- Parameters:
reducer
- a commutative associative combining function
- Returns:
- the result of accumulating all values
reduceValues
public <U> U reduceValues(ConcurrentHashMapV8.Fun<? super V,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
- Returns the result of accumulating the given transformation
of all values using the given reducer to combine values, or
null if none.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case it is not combined).reducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all values
reduceValuesToDouble
public double reduceValuesToDouble(ConcurrentHashMapV8.ObjectToDouble<? super V> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
- Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all values
reduceValuesToLong
public long reduceValuesToLong(ConcurrentHashMapV8.ObjectToLong<? super V> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
- Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all values
reduceValuesToInt
public int reduceValuesToInt(ConcurrentHashMapV8.ObjectToInt<? super V> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
- Returns the result of accumulating the given transformation
of all values using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all values
forEachEntry
public void forEachEntry(ConcurrentHashMapV8.Action<Map.Entry<K,V>> action)
- Performs the given action for each entry.
- Parameters:
action
- the action
forEachEntry
public <U> void forEachEntry(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> transformer,
ConcurrentHashMapV8.Action<U> action)
- Performs the given action for each non-null transformation
of each entry.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case the action is not applied).action
- the action
searchEntries
public <U> U searchEntries(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> searchFunction)
- Returns a non-null result from applying the given search
function on each entry, or null if none. Upon success,
further element processing is suppressed and the results of
any other parallel invocations of the search function are
ignored.
- Parameters:
searchFunction
- a function returning a non-null
result on success, else null
- Returns:
- a non-null result from applying the given search
function on each entry, or null if none
reduceEntries
public Map.Entry<K,V> reduceEntries(ConcurrentHashMapV8.BiFun<Map.Entry<K,V>,Map.Entry<K,V>,? extends Map.Entry<K,V>> reducer)
- Returns the result of accumulating all entries using the
given reducer to combine values, or null if none.
- Parameters:
reducer
- a commutative associative combining function
- Returns:
- the result of accumulating all entries
reduceEntries
public <U> U reduceEntries(ConcurrentHashMapV8.Fun<Map.Entry<K,V>,? extends U> transformer,
ConcurrentHashMapV8.BiFun<? super U,? super U,? extends U> reducer)
- Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
or null if none.
- Parameters:
transformer
- a function returning the transformation
for an element, or null of there is no transformation (in
which case it is not combined).reducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all entries
reduceEntriesToDouble
public double reduceEntriesToDouble(ConcurrentHashMapV8.ObjectToDouble<Map.Entry<K,V>> transformer,
double basis,
ConcurrentHashMapV8.DoubleByDoubleToDouble reducer)
- Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all entries
reduceEntriesToLong
public long reduceEntriesToLong(ConcurrentHashMapV8.ObjectToLong<Map.Entry<K,V>> transformer,
long basis,
ConcurrentHashMapV8.LongByLongToLong reducer)
- Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all entries
reduceEntriesToInt
public int reduceEntriesToInt(ConcurrentHashMapV8.ObjectToInt<Map.Entry<K,V>> transformer,
int basis,
ConcurrentHashMapV8.IntByIntToInt reducer)
- Returns the result of accumulating the given transformation
of all entries using the given reducer to combine values,
and the given basis as an identity value.
- Parameters:
transformer
- a function returning the transformation
for an elementbasis
- the identity (initial default value) for the reductionreducer
- a commutative associative combining function
- Returns:
- the result of accumulating the given transformation
of all entries
Copyright © 2013 JBoss, a division of Red Hat. All Rights Reserved.