org.codehaus.gpars

groovyx.gpars
[Groovy] Class Parallel

java.lang.Object
  groovyx.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


Constructor Summary
Parallel()

 
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.

static void asConcurrent(java.lang.Object collection, groovy.lang.Closure code)

Makes the collection concurrent for the passed-in block of code.

java.lang.Object collectManyParallel(groovy.lang.Closure cl)

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

java.lang.Object 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.

java.lang.Object countParallel(java.lang.Object filter)

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

java.lang.Object 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.

java.lang.Object 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.

private static java.lang.Object enhance(java.lang.Object collection)

Enhances to resulting collection so that parallel methods can be chained.

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.

java.lang.Object 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.

java.lang.Object 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.

java.lang.Object 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.

java.lang.Object 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.

java.lang.Object foldParallel(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.

PAWrapper getParallel()

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

private java.lang.Object getRealSelf()

Retrieves the mixed it parent and potentially casts it dynamically to a Map.

java.lang.Object grepParallel(java.lang.Object filter)

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

java.lang.Object 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.

java.lang.Object injectParallel(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.

java.lang.Object injectParallel(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.

boolean isConcurrent()

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

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.

java.lang.Object 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.

java.lang.Object maxParallel()

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

java.lang.Object 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.

java.lang.Object minParallel()

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

java.lang.Object 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.

java.lang.Object 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 java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), 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()
 

Constructor Detail

Parallel

Parallel()


 
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.


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.
Parameters:
collection - The collection to enhance
code - The closure to run with the collection enhanced.


collectManyParallel

java.lang.Object collectManyParallel(groovy.lang.Closure cl)
Iterates over a collection/object with the collectMany() 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.


collectParallel

java.lang.Object 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

java.lang.Object countParallel(java.lang.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

java.lang.Object 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

java.lang.Object 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.


enhance

@java.lang.SuppressWarnings("GroovyMultipleReturnPointsPerMethod")
private static java.lang.Object enhance(java.lang.Object collection)
Enhances to resulting collection so that parallel methods can be chained.


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

java.lang.Object 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

java.lang.Object 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

java.lang.Object 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

@java.lang.Deprecated
java.lang.Object 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

@java.lang.Deprecated
java.lang.Object foldParallel(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

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.


getRealSelf

private java.lang.Object getRealSelf()
Retrieves the mixed it parent and potentially casts it dynamically to a Map. The cast to Map is needed since Maps additionally accept a two-argument closures in iterative methods.
Returns:
The mixin parent, optionally converted into a Map


grepParallel

java.lang.Object grepParallel(java.lang.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

java.lang.Object 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.


injectParallel

java.lang.Object injectParallel(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.


injectParallel

java.lang.Object injectParallel(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


isConcurrent

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


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


maxParallel

java.lang.Object 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

java.lang.Object 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

java.lang.Object 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

java.lang.Object 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

java.lang.Object 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

java.lang.Object 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.


 

Copyright © 2008–2013 Václav Pech. All Rights Reserved.