groovyx.gpars
[Groovy] Class GParsPoolUtil
java.lang.Object
groovyx.gpars.GParsPoolUtil
class GParsPoolUtil
extends java.lang.Object
This class forms the core of the DSL initialized by GParsPool. The static methods of GParsPoolUtil
get attached to their first arguments (the Groovy Category mechanism) and can be then invoked as if they were part of
the argument classes.
- Authors:
- Vaclav Pech
- Robert Fischer
Date: Mar 10, 2010
- See Also:
- GParsPool
Field Summary |
private static java.util.Timer |
timer
Allows timeouts for async operations
|
Method Summary |
static boolean
|
anyParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static boolean
|
anyParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static boolean
|
anyParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static void
|
asConcurrent(java.lang.Object collection, groovy.lang.Closure code)
Makes the collection concurrent for the passed-in block of code.
|
static groovy.lang.Closure
|
async(groovy.lang.Closure cl)
Creates an asynchronous variant of the supplied closure, which, when invoked returns a future for the potential return value
|
static groovy.lang.Closure
|
asyncFun(groovy.lang.Closure original, boolean blocking = false)
Creates an asynchronous and composable variant of the supplied closure, which, when invoked returns a DataflowVariable for the potential return value
|
private static java.lang.Object
|
buildMemoizeFunction(java.lang.Object cache, groovy.lang.Closure cl)
|
private static java.lang.Object
|
buildSoftReferenceMemoizeFunction(int protectedCacheSize, java.lang.Object cache, groovy.lang.Closure cl)
|
static java.util.concurrent.Future
|
callAsync(groovy.lang.Closure cl, java.lang.Object args)
Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
|
private static java.util.concurrent.Future
|
callParallel(groovy.lang.Closure task)
schedules the supplied closure for processing in the underlying thread pool.
|
static java.util.concurrent.Future
|
callTimeoutAsync(groovy.lang.Closure cl, long timeout, java.lang.Object args)
Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
|
static java.util.concurrent.Future
|
callTimeoutAsync(groovy.lang.Closure cl, groovy.time.Duration timeout, java.lang.Object args)
Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
|
private static void
|
cleanUpNullReferences(java.lang.Object cache, java.lang.Object queue)
|
static java.util.Collection
|
collectParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.util.Collection
|
collectParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.util.Collection
|
collectParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static int
|
countParallel(java.util.Collection collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
static int
|
countParallel(java.lang.Object collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
private static extra166y.ParallelArray
|
createPA(java.lang.Object collection, jsr166y.ForkJoinPool pool)
|
private static extra166y.ParallelArray
|
createPAFromArray(T[] array, jsr166y.ForkJoinPool pool)
|
private static extra166y.ParallelArray
|
createPAFromCollection(java.lang.Object collection, jsr166y.ForkJoinPool pool)
|
static java.util.Collection
|
eachParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.lang.Object
|
eachParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.lang.Object
|
eachParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
private static void
|
eachParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
|
static java.util.Collection
|
eachWithIndexParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.lang.Object
|
eachWithIndexParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
|
static java.lang.Object
|
eachWithIndexParallel(java.util.Map collection, groovy.lang.Closure cl)
Does parallel eachWithIndex on maps
|
static boolean
|
everyParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static boolean
|
everyParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static boolean
|
everyParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.util.Collection
|
findAllParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.util.Collection
|
findAllParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.util.Map
|
findAllParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
private static java.util.Collection
|
findAllParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
|
static java.lang.Object
|
findAnyParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.lang.Object
|
findAnyParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.lang.Object
|
findAnyParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
private static T
|
findAnyParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
|
static T
|
findParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.lang.Object
|
findParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
static java.lang.Object
|
findParallel(java.util.Map collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
|
private static T
|
findParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
|
static T
|
foldParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
|
static java.lang.Object
|
foldParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
|
static T
|
foldParallel(java.util.Collection collection, java.lang.Object seed, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
|
static java.lang.Object
|
foldParallel(java.lang.Object collection, java.lang.Object seed, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
|
static PAWrapper
|
getParallel(java.util.Collection collection)
Creates a PAWrapper around a ParallelArray wrapping the elements of the original collection.
|
static PAWrapper
|
getParallel(java.lang.Object collection)
Creates a PAWrapper around a ParallelArray wrapping the elements of the original collection.
|
static extra166y.ParallelArray
|
getParallelArray(java.util.Collection collection)
Creates a ParallelArray wrapping the elements of the original collection.
|
static extra166y.ParallelArray
|
getParallelArray(java.lang.Object collection)
Creates a ParallelArray wrapping the elements of the original collection.
|
static groovy.lang.Closure
|
gmemoize(groovy.lang.Closure cl)
Creates a caching variant of the supplied closure.
|
static groovy.lang.Closure
|
gmemoizeAtLeast(groovy.lang.Closure cl, int protectedCacheSize)
Creates a caching variant of the supplied closure with automatic cache size adjustment and lower limit
on the cache size.
|
static groovy.lang.Closure
|
gmemoizeAtMost(groovy.lang.Closure cl, int maxCacheSize)
Creates a caching variant of the supplied closure with upper limit on the cache size.
|
static groovy.lang.Closure
|
gmemoizeBetween(groovy.lang.Closure cl, int protectedCacheSize, int maxCacheSize)
Creates a caching variant of the supplied closure with automatic cache size adjustment and lower and upper limits
on the cache size.
|
static java.util.Collection
|
grepParallel(java.util.Collection collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
static java.lang.Object
|
grepParallel(java.lang.Object collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
static java.util.Map
|
grepParallel(java.util.Map collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
private static java.util.Collection
|
grepParallelPA(extra166y.ParallelArray pa, java.lang.Object filter)
|
static java.util.Map
|
groupByParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the mapping predicate.
|
static java.util.Map
|
groupByParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the mapping predicate.
|
private static java.util.Map
|
groupByParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
|
static boolean
|
isConcurrent(java.lang.Object collection)
Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.
|
static java.util.concurrent.Future
|
leftShift(jsr166y.ForkJoinPool pool, groovy.lang.Closure task)
Submits the task for asynchronous processing returning the Future received from the executor service.
|
static java.lang.Object
|
makeConcurrent(java.lang.Object collection)
Overrides the iterative methods like each(), collect() and such, so that they call their parallel variants from the GParsPoolUtil class
like eachParallel(), collectParallel() and such.
|
static java.lang.Object
|
makeSequential(java.lang.Object collection)
Gives the iterative methods like each() or find() the original sequential semantics.
|
static java.lang.Object
|
makeTransparent(java.lang.Object collection)
Creates a TransparentParallel class instance and mixes it in the object it is invoked on.
|
static T
|
maxParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied
closure as the comparator.
|
static java.lang.Object
|
maxParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied
closure as the comparator.
|
static T
|
maxParallel(java.util.Collection collection)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.
|
static java.lang.Object
|
maxParallel(java.lang.Object collection)
Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.
|
static T
|
minParallel(java.util.Collection collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied
closure as the comparator.
|
static java.lang.Object
|
minParallel(java.lang.Object collection, groovy.lang.Closure cl)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied
closure as the comparator.
|
static T
|
minParallel(java.util.Collection collection)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.
|
static java.lang.Object
|
minParallel(java.lang.Object collection)
Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.
|
private static jsr166y.ForkJoinPool
|
retrievePool()
|
static java.util.Collection
|
splitParallel(java.util.Collection collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
static java.lang.Object
|
splitParallel(java.lang.Object collection, java.lang.Object filter)
Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
|
static T
|
sumParallel(java.util.Collection collection)
Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel()
method with the + operator and the reduction operation.
|
static java.lang.Object
|
sumParallel(java.lang.Object collection)
Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel()
method with the + operator and the reduction operation.
|
Methods inherited from class java.lang.Object
|
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
timer
private static final java.util.Timer timer
- Allows timeouts for async operations
MEMOIZE_NULL
static final java.lang.Object MEMOIZE_NULL
-
GParsPoolUtil
GParsPoolUtil()
-
anyParallel
static boolean anyParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
The anyParallel() method is lazy and once a positive answer has been given by at least one element, it avoids running
the supplied closure on subsequent elements.
After all the elements have been processed, the method returns a boolean value indicating, whether at least
one element of the collection meets the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new anyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* assert [1, 2, 3, 4, 5].anyParallel {Number number -> number > 3}* assert ![1, 2, 3].anyParallel {Number number -> number > 3}*}
anyParallel
static boolean anyParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
The anyParallel() method is lazy and once a positive answer has been given by at least one element, it avoids running
the supplied closure on subsequent elements.
After all the elements have been processed, the method returns a boolean value indicating, whether at least
one element of the collection meets the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new anyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* assert [1, 2, 3, 4, 5].anyParallel {Number number -> number > 3}* assert ![1, 2, 3].anyParallel {Number number -> number > 3}*}
anyParallel
static boolean anyParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
The anyParallel() method is lazy and once a positive answer has been given by at least one element, it avoids running
the supplied closure on subsequent elements.
After all the elements have been processed, the method returns a boolean value indicating, whether at least
one element of the collection meets the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new anyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* assert [1, 2, 3, 4, 5].anyParallel {Number number -> number > 3}* assert ![1, 2, 3].anyParallel {Number number -> number > 3}*}
asConcurrent
static void asConcurrent(java.lang.Object collection, groovy.lang.Closure code)
- Makes the collection concurrent for the passed-in block of code.
The iterative methods like each or collect are given concurrent semantics inside the passed-in closure.
Once the closure finishes, the original sequential semantics of the methods is restored.
Must be invoked inside a withPool block.
- Parameters:
collection
- The collection to enhancecode
- The closure to run with the collection enhanced.
async
static groovy.lang.Closure async(groovy.lang.Closure cl)
- Creates an asynchronous variant of the supplied closure, which, when invoked returns a future for the potential return value
asyncFun
static groovy.lang.Closure asyncFun(groovy.lang.Closure original, boolean blocking = false)
- Creates an asynchronous and composable variant of the supplied closure, which, when invoked returns a DataflowVariable for the potential return value
buildMemoizeFunction
private static java.lang.Object buildMemoizeFunction(java.lang.Object cache, groovy.lang.Closure cl)
-
buildSoftReferenceMemoizeFunction
private static java.lang.Object buildSoftReferenceMemoizeFunction(int protectedCacheSize, java.lang.Object cache, groovy.lang.Closure cl)
-
callAsync
static java.util.concurrent.Future callAsync(groovy.lang.Closure cl, java.lang.Object args)
- Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
callParallel
private static java.util.concurrent.Future callParallel(groovy.lang.Closure task)
- schedules the supplied closure for processing in the underlying thread pool.
callTimeoutAsync
static java.util.concurrent.Future callTimeoutAsync(groovy.lang.Closure cl, long timeout, java.lang.Object args)
- Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
Also allows the asynchronous calculation to be cancelled after a given timeout.
In order to allow cancellation, the asynchronously running code must keep checking the _interrupted_ flag of its
own thread and cease the calculation once the flag is set to true.
- Parameters:
timeout
- The timeout in milliseconds to wait before the calculation gets cancelled.
callTimeoutAsync
static java.util.concurrent.Future callTimeoutAsync(groovy.lang.Closure cl, groovy.time.Duration timeout, java.lang.Object args)
- Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value.
Also allows the asynchronous calculation to be cancelled after a given timeout.
In order to allow cancellation, the asynchronously running code must keep checking the _interrupted_ flag of its
own thread and cease the calculation once the flag is set to true.
- Parameters:
timeout
- The timeout to wait before the calculation gets cancelled.
cleanUpNullReferences
private static void cleanUpNullReferences(java.lang.Object cache, java.lang.Object queue)
-
collectParallel
static java.util.Collection collectParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new collectParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].collectParallel {Number number -> number * 10}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}
collectParallel
static java.util.Collection collectParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new collectParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].collectParallel {Number number -> number * 10}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}
collectParallel
static java.util.Collection collectParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new collectParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].collectParallel {Number number -> number * 10}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}
countParallel
static int countParallel(java.util.Collection collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].countParallel(4)
assertEquals(1, result)
}
countParallel
static int countParallel(java.lang.Object collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].countParallel(4)
assertEquals(1, result)
}
createPA
@SuppressWarnings("GroovyMultipleReturnPointsPerMethod")
private static extra166y.ParallelArray createPA(java.lang.Object collection, jsr166y.ForkJoinPool pool)
-
createPAFromArray
private static extra166y.ParallelArray createPAFromArray(T[] array, jsr166y.ForkJoinPool pool)
-
createPAFromCollection
private static extra166y.ParallelArray createPAFromCollection(java.lang.Object collection, jsr166y.ForkJoinPool pool)
-
eachParallel
static java.util.Collection eachParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new eachParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = new ConcurrentSkipListSet()
[1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}* Note that the result variable is synchronized to prevent race conditions between multiple threads.
eachParallel
static java.lang.Object eachParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new eachParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = new ConcurrentSkipListSet()
[1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}* Note that the result variable is synchronized to prevent race conditions between multiple threads.
eachParallel
static java.lang.Object eachParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new eachParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = new ConcurrentSkipListSet()
[1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}* Note that the result variable is synchronized to prevent race conditions between multiple threads.
eachParallelPA
private static void eachParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
-
eachWithIndexParallel
static java.util.Collection eachWithIndexParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new eachWithIndexParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = new ConcurrentSkipListSet()
[1, 2, 3, 4, 5].eachWithIndexParallel {Number number, int index -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}* Note that the result variable is synchronized to prevent race conditions between multiple threads.
eachWithIndexParallel
static java.lang.Object eachWithIndexParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the transformation operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new eachWithIndexParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = new ConcurrentSkipListSet()
[1, 2, 3, 4, 5].eachWithIndexParallel {Number number, int index -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result)
}* Note that the result variable is synchronized to prevent race conditions between multiple threads.
eachWithIndexParallel
static java.lang.Object eachWithIndexParallel(java.util.Map collection, groovy.lang.Closure cl)
- Does parallel eachWithIndex on maps
everyParallel
static boolean everyParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a boolean value indicating, whether all the elements
of the collection meet the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new everyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool(5) {* assert ![1, 2, 3, 4, 5].everyParallel {Number number -> number > 3}* assert [1, 2, 3].everyParallel() {Number number -> number <= 3}*}
everyParallel
static boolean everyParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a boolean value indicating, whether all the elements
of the collection meet the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new everyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool(5) {* assert ![1, 2, 3, 4, 5].everyParallel {Number number -> number > 3}* assert [1, 2, 3].everyParallel() {Number number -> number <= 3}*}
everyParallel
static boolean everyParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a boolean value indicating, whether all the elements
of the collection meet the predicate.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new everyParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool(5) {* assert ![1, 2, 3, 4, 5].everyParallel {Number number -> number > 3}* assert [1, 2, 3].everyParallel() {Number number -> number <= 3}*}
findAllParallel
static java.util.Collection findAllParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findAllParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAllParallel {Number number -> number > 3}* assertEquals(new HashSet([4, 5]), result)
}
findAllParallel
static java.util.Collection findAllParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findAllParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAllParallel {Number number -> number > 3}* assertEquals(new HashSet([4, 5]), result)
}
findAllParallel
static java.util.Map findAllParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findAllParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAllParallel {Number number -> number > 3}* assertEquals(new HashSet([4, 5]), result)
}
findAllParallelPA
private static java.util.Collection findAllParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
-
findAnyParallel
static java.lang.Object findAnyParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
Unlike with the find method, findAnyParallel() does not guarantee
that the a matching element with the lowest index is returned.
The findAnyParallel() method evaluates elements lazily and stops processing further elements of the collection once a match has been found.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a random value from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findAnyParallel
static java.lang.Object findAnyParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
Unlike with the find method, findAnyParallel() does not guarantee
that the a matching element with the lowest index is returned.
The findAnyParallel() method evaluates elements lazily and stops processing further elements of the collection once a match has been found.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a random value from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAnyParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findAnyParallel
static java.lang.Object findAnyParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
Unlike with the find method, findAnyParallel() does not guarantee
that the a matching element with the lowest index is returned.
The findAnyParallel() method evaluates elements lazily and stops processing further elements of the collection once a match has been found.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a random value from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findAnyParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findAnyParallelPA
private static T findAnyParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
-
findParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T findParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a value from the resulting Parallel Array with the minimum index.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findParallel
static java.lang.Object findParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a value from the resulting Parallel Array with the minimum index.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findParallel
static java.lang.Object findParallel(java.util.Map collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
closure as the filter predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a value from the resulting Parallel Array with the minimum index.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new findParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].findParallel {Number number -> number > 3}* assert (result in [4, 5])
}
findParallelPA
private static T findParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
-
foldParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T foldParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the reduction result of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
foldParallel
static java.lang.Object foldParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the reduction result of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
foldParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T foldParallel(java.util.Collection collection, java.lang.Object seed, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the reduction result of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
- Parameters:
seed
- A seed value to initialize the operation
foldParallel
static java.lang.Object foldParallel(java.lang.Object collection, java.lang.Object seed, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its reduce() method using the supplied
closure as the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the reduction result of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
- Parameters:
seed
- A seed value to initialize the operation
getParallel
static PAWrapper getParallel(java.util.Collection collection)
- Creates a PAWrapper around a ParallelArray wrapping the elements of the original collection.
This allows further parallel processing operations on the collection to chain and so effectively leverage the underlying
ParallelArray implementation.
getParallel
static PAWrapper getParallel(java.lang.Object collection)
- Creates a PAWrapper around a ParallelArray wrapping the elements of the original collection.
This allows further parallel processing operations on the collection to chain and so effectively leverage the underlying
ParallelArray implementation.
getParallelArray
@SuppressWarnings("GroovyAssignabilityCheck")
static extra166y.ParallelArray getParallelArray(java.util.Collection collection)
- Creates a ParallelArray wrapping the elements of the original collection.
getParallelArray
static extra166y.ParallelArray getParallelArray(java.lang.Object collection)
- Creates a ParallelArray wrapping the elements of the original collection.
gmemoize
static groovy.lang.Closure gmemoize(groovy.lang.Closure cl)
- Creates a caching variant of the supplied closure.
Whenever the closure is called, the mapping between the parameters and the return value is preserved in cache
making subsequent calls with the same arguments fast.
This variant will keep all values forever, i.e. till the closure gets garbage-collected.
The returned function can be safely used concurrently from multiple threads, however, the implementation
values high average-scenario performance and so concurrent calls on the memoized function with identical argument values
may not necessarily be able to benefit from each other's cached return value. With this having been mentioned,
the performance trade-off still makes concurrent use of memoized functions safe and highly recommended.
The cache gets garbage-collected together with the memoized closure.
- Returns:
- A new function forwarding to the original one while caching the results
gmemoizeAtLeast
static groovy.lang.Closure gmemoizeAtLeast(groovy.lang.Closure cl, int protectedCacheSize)
- Creates a caching variant of the supplied closure with automatic cache size adjustment and lower limit
on the cache size.
Whenever the closure is called, the mapping between the parameters and the return value is preserved in cache
making subsequent calls with the same arguments fast.
This variant allows the garbage collector to release entries from the cache and at the same time allows
the user to specify how many entries should be protected from the eventual gc-initiated eviction.
Cached entries exceeding the specified preservation threshold are made available for eviction based on
the LRU (Last Recently Used) strategy.
Given the non-deterministic nature of garbage collector, the actual cache size may grow well beyond the limits
set by the user if memory is plentiful.
The returned function can be safely used concurrently from multiple threads, however, the implementation
values high average-scenario performance and so concurrent calls on the memoized function with identical argument values
may not necessarily be able to benefit from each other's cached return value. Also the protectedCacheSize parameter
might not be respected accurately in such scenarios for some periods of time. With this having been mentioned,
the performance trade-off still makes concurrent use of memoized functions safe and highly recommended.
The cache gets garbage-collected together with the memoized closure.
gmemoizeAtMost
static groovy.lang.Closure gmemoizeAtMost(groovy.lang.Closure cl, int maxCacheSize)
- Creates a caching variant of the supplied closure with upper limit on the cache size.
Whenever the closure is called, the mapping between the parameters and the return value is preserved in cache
making subsequent calls with the same arguments fast.
This variant will keep all values until the upper size limit is reached. Then the values in the cache start rotating
using the LRU (Last Recently Used) strategy.
The returned function can be safely used concurrently from multiple threads, however, the implementation
values high average-scenario performance and so concurrent calls on the memoized function with identical argument values
may not necessarily be able to benefit from each other's cached return value. With this having been mentioned,
the performance trade-off still makes concurrent use of memoized functions safe and highly recommended.
The cache gets garbage-collected together with the memoized closure.
- Parameters:
maxCacheSize
- The maximum size the cache can grow to
- Returns:
- A new function forwarding to the original one while caching the results
gmemoizeBetween
static groovy.lang.Closure gmemoizeBetween(groovy.lang.Closure cl, int protectedCacheSize, int maxCacheSize)
- Creates a caching variant of the supplied closure with automatic cache size adjustment and lower and upper limits
on the cache size.
Whenever the closure is called, the mapping between the parameters and the return value is preserved in cache
making subsequent calls with the same arguments fast.
This variant allows the garbage collector to release entries from the cache and at the same time allows
the user to specify how many entries should be protected from the eventual gc-initiated eviction.
Cached entries exceeding the specified preservation threshold are made available for eviction based on
the LRU (Last Recently Used) strategy.
Given the non-deterministic nature of garbage collector, the actual cache size may grow well beyond the protected
size limits set by the user, if memory is plentiful.
Also, this variant will never exceed in size the upper size limit. Once the upper size limit has been reached,
the values in the cache start rotating using the LRU (Last Recently Used) strategy.
The returned function can be safely used concurrently from multiple threads, however, the implementation
values high average-scenario performance and so concurrent calls on the memoized function with identical argument values
may not necessarily be able to benefit from each other's cached return value. Also the protectedCacheSize parameter
might not be respected accurately in such scenarios for some periods of time. With this having been mentioned,
the performance trade-off still makes concurrent use of memoized functions safe and highly recommended.
The cache gets garbage-collected together with the memoized closure.
grepParallel
static java.util.Collection grepParallel(java.util.Collection collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].grepParallel(4..6)
assertEquals(new HashSet([4, 5]), result)
}
grepParallel
static java.lang.Object grepParallel(java.lang.Object collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].grepParallel(4..6)
assertEquals(new HashSet([4, 5]), result)
}
grepParallel
static java.util.Map grepParallel(java.util.Map collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied map and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].grepParallel(4..6)
assertEquals(new HashSet([4, 5]), result)
}
grepParallelPA
private static java.util.Collection grepParallelPA(extra166y.ParallelArray pa, java.lang.Object filter)
-
groupByParallel
static java.util.Map groupByParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the mapping predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a map of groups of the original elements.
Elements in the same group gave identical results when the supplied closure was invoked on them.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new groupByParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* assert ([1, 2, 3, 4, 5].groupByParallel {Number number -> number % 2}).size() == 2
}
groupByParallel
static java.util.Map groupByParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes the withMapping() method using the supplied
closure as the mapping predicate.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns a map of groups of the original elements.
Elements in the same group gave identical results when the supplied closure was invoked on them.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new groupByParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* assert ([1, 2, 3, 4, 5].groupByParallel {Number number -> number % 2}).size() == 2
}
groupByParallelPA
private static java.util.Map groupByParallelPA(extra166y.ParallelArray pa, groovy.lang.Closure cl)
-
isConcurrent
static boolean isConcurrent(java.lang.Object collection)
- Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.
leftShift
static java.util.concurrent.Future leftShift(jsr166y.ForkJoinPool pool, groovy.lang.Closure task)
- Submits the task for asynchronous processing returning the Future received from the executor service.
Allows for the following syntax:
executorService << {println 'Inside parallel task'}*
makeConcurrent
static java.lang.Object makeConcurrent(java.lang.Object collection)
- Overrides the iterative methods like each(), collect() and such, so that they call their parallel variants from the GParsPoolUtil class
like eachParallel(), collectParallel() and such.
The first time it is invoked on a collection the method creates a TransparentParallel class instance and mixes it
in the object it is invoked on. After mixing-in, the isConcurrent() method will return true.
Delegates to GParsPoolUtil.makeConcurrent().
- Parameters:
collection
- The object to make transparent
- Returns:
- The instance of the TransparentParallel class wrapping the original object and overriding the iterative methods with new parallel behavior
makeSequential
static java.lang.Object makeSequential(java.lang.Object collection)
- Gives the iterative methods like each() or find() the original sequential semantics.
- Parameters:
collection
- The collection to apply the change to
- Returns:
- The collection itself
makeTransparent
@Deprecated
static java.lang.Object makeTransparent(java.lang.Object collection)
- Creates a TransparentParallel class instance and mixes it in the object it is invoked on. The TransparentParallel class
overrides the iterative methods like each(), collect() and such, so that they call their parallel variants from the GParsPoolUtil class
like eachParallel(), collectParallel() and such.
After mixing-in, the isConcurrent() method will return true.
- deprecated:
- Use makeConcurrent() instead
- Parameters:
collection
- The object to make transparent
- Returns:
- The instance of the TransparentParallel class wrapping the original object and overriding the iterative methods with new parallel behavior
maxParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T maxParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied
closure as the comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the maximum of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
If the supplied closure takes two arguments it is used directly as a comparator.
If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
- Parameters:
cl
- A one or two-argument closure
maxParallel
static java.lang.Object maxParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the supplied
closure as the comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the maximum of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
If the supplied closure takes two arguments it is used directly as a comparator.
If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
- Parameters:
cl
- A one or two-argument closure
maxParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T maxParallel(java.util.Collection collection)
- Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the maximum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
maxParallel
static java.lang.Object maxParallel(java.lang.Object collection)
- Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the maximum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
minParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T minParallel(java.util.Collection collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied
closure as the comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the minimum of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
If the supplied closure takes two arguments it is used directly as a comparator.
If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
- Parameters:
cl
- A one or two-argument closure
minParallel
static java.lang.Object minParallel(java.lang.Object collection, groovy.lang.Closure cl)
- Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the supplied
closure as the comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the minimum of the elements in the collection.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
If the supplied closure takes two arguments it is used directly as a comparator.
If the supplied closure takes one argument, the values returned by the supplied closure for individual elements are used for comparison by the implicit comparator.
- Parameters:
cl
- A one or two-argument closure
minParallel
@SuppressWarnings("GroovyAssignabilityCheck")
static T minParallel(java.util.Collection collection)
- Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the minimum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
minParallel
static java.lang.Object minParallel(java.lang.Object collection)
- Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the minimum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
retrievePool
private static jsr166y.ForkJoinPool retrievePool()
-
splitParallel
static java.util.Collection splitParallel(java.util.Collection collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
splitParallel
static java.lang.Object splitParallel(java.lang.Object collection, java.lang.Object filter)
- Creates a Parallel Array out of the supplied collection/object and invokes the withFilter() method using the supplied
rule as the filter predicate.
The filter will be effectively used concurrently on the elements of the collection.
After all the elements have been processed, the method returns a collection of values from the resulting Parallel Array.
It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new grepParallel(Closure cl) method, which delegates to the GParsPoolUtil class.
Example:
GParsPool.withPool {* def result = [1, 2, 3, 4, 5].splitParallel(4..6)
assert [3, 4, 5] as Set == result[0] as Set
assert [1, 2] as Set == result[1] as Set
}
sumParallel
static T sumParallel(java.util.Collection collection)
- Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel()
method with the + operator and the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the sum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
sumParallel
static java.lang.Object sumParallel(java.lang.Object collection)
- Creates a Parallel Array out of the supplied collection/object and summarizes its elements using the foldParallel()
method with the + operator and the reduction operation.
The closure will be effectively invoked concurrently on the elements of the collection.
After all the elements have been processed, the method returns the sum of the elements in the collection.
Alternatively a DSL can be used to simplify the code. All collections/objects within the withPool block
have a new min(Closure cl) method, which delegates to the GParsPoolUtil class.
Copyright © 2008–2010 Václav Pech. All Rights Reserved.