Groovy Documentation

gpars
[Groovy] Class GParsPoolUtil

java.lang.Object
  gpars.GParsPoolUtil

class GParsPoolUtil

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:
groovyx.gpars.GParsPool


Method Summary
static boolean anyParallel(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(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 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 Future callAsync(groovy.lang.Closure cl, Object... args)

Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value,

static Collection collectParallel(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 Collection collectParallel(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 int countParallel(Collection collection, def 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(Object collection, def 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 Collection createCollection(Object object)

static groovy.lang.Closure createComparator(groovy.lang.Closure handler)

Builds a comparator depending on the number of arguments accepted by the supplied closure.

static Collection eachParallel(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 Object eachParallel(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 Collection eachWithIndexParallel(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 Object eachWithIndexParallel(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 boolean everyParallel(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(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 Collection findAllParallel(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 Collection findAllParallel(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 Object findAnyParallel(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 Object findAnyParallel(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 Object findParallel(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 Object findParallel(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 Object foldParallel(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 Object foldParallel(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 Object foldParallel(Collection collection, def 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 Object foldParallel(Object collection, def 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(Collection collection)

Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection.

static Object getParallel(Object collection)

Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection.

static Collection grepParallel(Collection collection, def 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 Object grepParallel(Object collection, def 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 Map groupByParallel(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 Map groupByParallel(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.

static boolean isTransparent(Object collection)

Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.

static Future leftShift(jsr166y.forkjoin.ForkJoinPool pool, groovy.lang.Closure task)

Submits the task for asynchronous processing returning the Future received from the executor service.

static Object makeTransparent(Object collection)

Creates a TransparentParallel class instance and mixes it in the object it is invoked on.

static Object maxParallel(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 Object maxParallel(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 Object maxParallel(Collection collection)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.

static Object maxParallel(Object collection)

Creates a Parallel Array out of the supplied collection/object and invokes its max() method using the default comparator.

static Object minParallel(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 Object minParallel(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 Object minParallel(Collection collection)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.

static Object minParallel(Object collection)

Creates a Parallel Array out of the supplied collection/object and invokes its min() method using the default comparator.

static Collection splitParallel(Collection collection, def 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 Object splitParallel(Object collection, def 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 Object sumParallel(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 Object sumParallel(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 Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

anyParallel

static boolean anyParallel(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(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}*}


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


callAsync

static Future callAsync(groovy.lang.Closure cl, Object... args)
Calls a closure in a separate thread supplying the given arguments, returning a future for the potential return value,


collectParallel

static Collection collectParallel(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 Collection collectParallel(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) }


countParallel

static int countParallel(Collection collection, def 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(Object collection, def 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) }


createCollection

static Collection createCollection(Object object)


createComparator

@SuppressWarnings("GroovyMultipleReturnPointsPerMethod")
static groovy.lang.Closure createComparator(groovy.lang.Closure handler)
Builds a comparator depending on the number of arguments accepted by the supplied closure.


eachParallel

static Collection eachParallel(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 Object eachParallel(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.


eachWithIndexParallel

static Collection eachWithIndexParallel(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 Object eachWithIndexParallel(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.


everyParallel

static boolean everyParallel(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(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}*}


findAllParallel

static Collection findAllParallel(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 Collection findAllParallel(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) }


findAnyParallel

static Object findAnyParallel(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 Object findAnyParallel(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].findParallel {Number number -> number > 3}* assert (result in [4, 5]) }


findParallel

static Object findParallel(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 Object findParallel(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]) }


foldParallel

static Object foldParallel(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 Object foldParallel(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

static Object foldParallel(Collection collection, def 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 Object foldParallel(Object collection, def 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(Collection collection)
Creates a PAWrapper around a ParallelArray wrapping te 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 Object getParallel(Object collection)
Creates a PAWrapper around a ParallelArray wrapping te elements of the original collection. This allows further parallel processing operations on the collection to chain and so effectively leverage the underlying ParallelArray implementation.


grepParallel

static Collection grepParallel(Collection collection, def 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 Object grepParallel(Object collection, def 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) }


groupByParallel

static Map groupByParallel(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 list 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 Map groupByParallel(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 list 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 }


isTransparent

static boolean isTransparent(Object collection)
Indicates whether the iterative methods like each() or collect() work have been altered to work concurrently.


leftShift

static Future leftShift(jsr166y.forkjoin.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'}* 


makeTransparent

static Object makeTransparent(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 isTransparent() method will return true.
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

static Object maxParallel(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 Object maxParallel(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

static Object maxParallel(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 Object maxParallel(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

static Object minParallel(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 Object minParallel(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

static Object minParallel(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 Object minParallel(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.


splitParallel

static Collection splitParallel(Collection collection, def 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(it > 3) assert [3, 4, 5] as Set == result[0] as Set assert [1, 2] as Set == result[1] as Set }


splitParallel

static Object splitParallel(Object collection, def 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 Object sumParallel(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 Object sumParallel(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.


 

Groovy Documentation