Groovy Documentation

gpars
Class GParsExecutorsPoolEnhancer

java.lang.Object
  gpars.GParsExecutorsPoolEnhancer

class GParsExecutorsPoolEnhancer

GParsExecutorsPoolEnhancer allows classes or instances to be enhanced with asynchronous variants of iterative methods, like eachParallel(), collectParallel(), findAllParallel() and others. These operations split processing into multiple concurrently executable tasks and perform them on the underlying instance of an ExecutorService. The pool itself is stored in a final property threadPool and can be managed through static methods on the GParsExecutorsPoolEnhancer class. All enhanced classes and instances will share the underlying pool.

author:
Vaclav Pech Date: Jun 15, 2009


Constructor Summary
GParsExecutorsPoolEnhancer()

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

static void enhanceClass(Class clazz)

Enhances a class and so all instances created in the future by mixing-in an instance of GParsExecutorsPoolEnhancer.

static void enhanceInstance(Object collection)

Enhances a single instance by mixing-in an instance of GParsExecutorsPoolEnhancer.

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

Pool getThreadPool()

Retrieves the underlying pool

def grepParallel(groovy.lang.Closure cl)

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.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

GParsExecutorsPoolEnhancer

GParsExecutorsPoolEnhancer()


 
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. 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


collectParallel

public 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


eachParallel

public 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. A CountDownLatch is used to make the calling thread wait for all the results. 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


eachWithIndexParallel

public 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. A CountDownLatch is used to make the calling thread wait for all the results. 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


enhanceClass

public static void enhanceClass(Class clazz)
Enhances a class and so all instances created in the future by mixing-in an instance of GParsExecutorsPoolEnhancer. Enhancing classes needs to be done with caution, since it may have impact in unrelated parts of the application.


enhanceInstance

public static void enhanceInstance(Object collection)
Enhances a single instance by mixing-in an instance of GParsExecutorsPoolEnhancer.


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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


findAllParallel

public 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


findParallel

public 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


getThreadPool

public Pool getThreadPool()
Retrieves the underlying pool


grepParallel

public def grepParallel(groovy.lang.Closure cl)
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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


groupByParallel

public 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.
throws:
AsyncException If any of the collection's elements causes the closure to throw an exception. The original exceptions will be stored in the AsyncException's concurrentExceptions field.


 

Groovy Documentation