org.codehaus.gpars

groovyx.gpars
[Groovy] Class GParsExecutorsPoolEnhancer

java.lang.Object
  groovyx.gpars.GParsExecutorsPoolEnhancer

final class GParsExecutorsPoolEnhancer
extends java.lang.Object

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


Field Summary
private static DefaultPool threadPool

Holds the internal ExecutorService instance wrapped into a DefaultPool

 
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.

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

static void enhanceClass(java.lang.Class clazz)

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

static void enhanceInstance(java.lang.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.

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

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

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.

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

Field Detail

threadPool

@SuppressWarnings("GroovyConstantNamingConvention")
private static final DefaultPool threadPool
Holds the internal ExecutorService instance wrapped into a DefaultPool


 
Constructor Detail

GParsExecutorsPoolEnhancer

GParsExecutorsPoolEnhancer()


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

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

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

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

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

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

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

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


 

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