gpars
[Groovy] Class GParsExecutorsPoolEnhancer
java.lang.Object
gpars.GParsExecutorsPoolEnhancer
final 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.
- Authors:
- Vaclav Pech
Date: Jun 15, 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
|
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.
|
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.
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
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
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
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
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
static void enhanceInstance(Object collection)
- Enhances a single instance by mixing-in an instance of GParsExecutorsPoolEnhancer.
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.
- 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
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
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
Pool getThreadPool()
- Retrieves the underlying pool
grepParallel
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
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