Groovy Documentation

gpars
[Groovy] Class Parallel

java.lang.Object
  gpars.Parallel

final class Parallel

The Parallel interface holds methods that ParallelEnhancer adds to classes or instances when they get enhanced.

Authors:
Vaclav Pech Date: Nov 1, 2009


Method Summary
boolean anyParallel(groovy.lang.Closure cl)

Performs the any() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def collectParallel(groovy.lang.Closure cl)

Iterates over a collection/object with the collect() method using an asynchronous variant of the supplied closure to evaluate each collection's element.

def countParallel(Object filter)

Performs the count() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def eachParallel(groovy.lang.Closure cl)

Iterates over a collection/object with the each() method using an asynchronous variant of the supplied closure to evaluate each collection's element.

def eachWithIndexParallel(groovy.lang.Closure cl)

Iterates over a collection/object with the eachWithIndex() method using an asynchronous variant of the supplied closure to evaluate each collection's element.

boolean everyParallel(groovy.lang.Closure cl)

Performs the all() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def findAllParallel(groovy.lang.Closure cl)

Performs the findAll() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def findAnyParallel(groovy.lang.Closure cl)

Performs the find() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def findParallel(groovy.lang.Closure cl)

Performs the find() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def foldParallel(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.

def foldParallel(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.

PAWrapper getParallel()

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

def grepParallel(Object filter)

Performs the grep() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def groupByParallel(groovy.lang.Closure cl)

Performs the groupBy() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

boolean isTransparent()

Indicates, whether the iterative methods like each() or collect() have been made parallel.

static Object makeTransparent(Object collection)

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

def maxParallel(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.

def maxParallel()

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

def minParallel(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.

def minParallel()

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

def splitParallel(groovy.lang.Closure cl)

Performs the split() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element.

def sumParallel()

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

boolean anyParallel(groovy.lang.Closure cl)
Performs the any() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. 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 this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


collectParallel

def collectParallel(groovy.lang.Closure cl)
Iterates over a collection/object with the collect() method using an asynchronous variant of the supplied closure to evaluate each collection's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


countParallel

def countParallel(Object filter)
Performs the count() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


eachParallel

def eachParallel(groovy.lang.Closure cl)
Iterates over a collection/object with the each() method using an asynchronous variant of the supplied closure to evaluate each collection's element. After this method returns, all the closures have been finished and all the potential shared resources have been updated by the threads. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


eachWithIndexParallel

def eachWithIndexParallel(groovy.lang.Closure cl)
Iterates over a collection/object with the eachWithIndex() method using an asynchronous variant of the supplied closure to evaluate each collection's element. After this method returns, all the closures have been finished and all the potential shared resources have been updated by the threads. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


everyParallel

boolean everyParallel(groovy.lang.Closure cl)
Performs the all() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


findAllParallel

def findAllParallel(groovy.lang.Closure cl)
Performs the findAll() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


findAnyParallel

def findAnyParallel(groovy.lang.Closure cl)
Performs the find() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. 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. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


findParallel

def findParallel(groovy.lang.Closure cl)
Performs the find() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


foldParallel

def foldParallel(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

def foldParallel(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

PAWrapper getParallel()
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

def grepParallel(Object filter)
Performs the grep() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


groupByParallel

def groupByParallel(groovy.lang.Closure cl)
Performs the groupBy() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


isTransparent

boolean isTransparent()
Indicates, whether the iterative methods like each() or collect() have been made parallel.


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. Delegates to GParsPoolUtil.makeTransparent().
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

def maxParallel(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

def maxParallel()
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

def minParallel(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

def minParallel()
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

def splitParallel(groovy.lang.Closure cl)
Performs the split() operation using an asynchronous variant of the supplied closure to evaluate each collection's/object's element. After this method returns, all the closures have been finished and the caller can safely use the result. It's important to protect any shared resources used by the supplied closure from race conditions caused by multi-threaded access. If any of the collection's elements causes the closure to throw an exception, the exception is re-thrown.


sumParallel

def sumParallel()
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