@CompileStatic @SuppressWarnings('CatchException') trait AsyncSupport
a trait to be used for colating/slicing a list into "batches" to then asynchronously with Transactions insert or update for maximum performance.
Type | Name and description |
---|---|
static org.slf4j.Logger |
LOG |
int |
batchSize The list size to send to the collate that slices. |
PersistenceContextInterceptor |
persistenceInterceptor |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
batchTrx(Map args, List items, Closure itemClosure) runs {@link #doBatch ) in a Transaction and flush and clear is called after doBatch but before commit. |
|
List<List> |
collate(List items, Integer batchSize = null) Uses collate to break or slice the list into sub-lists of batches. |
|
void |
doBatch(Map args, List items, Closure itemClosure) calls closure for each item in list. |
<T> |
Collection<T> |
eachParallel(Map args = [:], Collection<T> collection, Closure itemClosure) Iterates over the lists and calls the closure passing in the list item and the args asynchronously. |
|
void |
parallel(Map args = [:], List<List> batches, Closure batchClosure) Iterates over the batchList of lists and calls the closure passing in the list and the args asynchronously. |
|
void |
parallelBatch(Map args = [:], List<List> batches, Closure itemClosure) calls parallel with the args, batches list calling doBatch for each batch in batches passes itemClosure down through to the doBatch |
|
void |
parallelCollate(Map args = [:], List list, Closure itemClosure) Uses collate to break or slice the list into batches and then calls parallelBatch |
<T> |
Closure<T> |
withSession(Closure<T> wrapped) |
The list size to send to the collate that slices.
Uses collate to break or slice the list into sub-lists of batches. Uses the batchSize unless batchSize is sent in
items
- the list to slice up into batchesbatchSize
- _optional_ the length of each batch sub-list in the returned list. override the batchSizecalls closure for each item in list.
args
- optional args to pass to the closure. coming from parallelClosureitems
- the list or items to iterate over and run the closureitemClosure
- the closure to execute for each item. will get passed the item and args as it itereates over the listIterates over the lists and calls the closure passing in the list item and the args asynchronously. see GParsPoolUtil.eachParallel Must be overriden by the concrete implementation as this is where the meat is.
args
- _optional_ arg map to be passed to the async engine such as gpars.
can also add any other value and they will be passed down through the closure as well batches
- a collated list of lists. each batch list in the batches will be asynchronously passed to the provided closureitemClosure
- the closure to call for each item in listIterates over the batchList of lists and calls the closure passing in the list and the args asynchronously. parallelClosure it self is not asynchronous and will return once all the items in the batchList are processed. If you want this method itself to be run asynchronous then it can be done in a Promise as outlined in the Grails async docs Must be overriden by the concrete implementation as this is where the meat is.
args
- _optional_ arg map to be passed to the async engine such as gpars.
can also add any other value and they will be passed down through the closure as well batches
- a collated list of lists. each batch list in the batches will be asynchronously passed to the provided closurebatchClosure
- the closure to call for each batch(sub-list of items) in the batches(list of batch sub-lists)calls parallel with the args, batches list calling doBatch for each batch in batches passes itemClosure down through to the doBatch
args
- _optional_ arg map to be passed to the async engine such as gpars.
can also add any other value and they will be passed down through the closure as well batches
- a collated list(batches) of sub-lists(a batch or items). each item in the batch(sub-list)
will be asynchronously passed to the provided itemClosure. You should first collate the list with collateitemClosure
- the closure to call for each item lowest list.Uses collate to break or slice the list into batches and then calls parallelBatch
args
- optional arg map to be passed on through to eachParallel and the async engine such as gpars. list
- the list to process that will get sliced into batches via collateitemClosure
- the closure to pass to eachParallel which is then passed to withTransaction