org.codehaus.gpars

groovyx.gpars
Class Parallel

java.lang.Object
  groovyx.gpars.Parallel

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.

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.

boolean isTransparent()

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

static java.lang.Object makeTransparent(java.lang.Object collection)

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

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), 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()
 

Constructor Detail

Parallel

Parallel()


 
Method Detail

anyParallel

public 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

public 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

public 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

public 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

public 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

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


everyParallel

public 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

public 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

public 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

public 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

public 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

public 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

public 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

public 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

public 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.


isTransparent

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


makeTransparent

public 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 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

public 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

public 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

public 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

public 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

public 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

public 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–2010 Václav Pech. All Rights Reserved.