Package com.redwood.scheduler.api.uow
Interface SchedulerSessionBatchedUnitOfWork<T>
-
- Type Parameters:
T
- The type of object that this unit of work operates on
public interface SchedulerSessionBatchedUnitOfWork<T>
Extending the unit of work pattern, this allows for work that can be broken up into batches to be processed. Each batch will automatically be retried in the face of competition. The pattern of work is:- Obtain a batch of work via
getBatchOfWork(SchedulerSession, int, boolean)
. - If the batch is empty, all work is done.
- Invoke
processItem(SchedulerSession, Object)
with each item in the non-empty batch of work. - Persist the session and start over.
- If an exception occurs due to competition, start over. Heed the previousBatchPersisted parameter, as it may apply to your implementation.
- If any other exception occurs, abort and propagate the error.
- See Also:
SchedulerSessionBatchedUnitOfWorkManager
-
-
Field Summary
Fields Modifier and Type Field Description static com.redwood.scheduler.infrastructure.logging.Versions
VERSION_SSIBUOW
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Iterator<T>
getBatchOfWork(SchedulerSession session, int batchSize, boolean previousBatchPersisted)
Obtain a batch of work to perform.void
processItem(SchedulerSession session, T item)
Process an item in a batched unit of work.
-
-
-
Method Detail
-
getBatchOfWork
Iterator<T> getBatchOfWork(SchedulerSession session, int batchSize, boolean previousBatchPersisted)
Obtain a batch of work to perform. This will be called repeatedly to obtain an iterator over the objects that need to be processed. If (and only if) the iterator is non-empty,processItem(SchedulerSession, Object)
will be invoked to actually process each item in the batch.- Parameters:
session
- A SchedulerSession that can be used to query the unit of work. The session is fresh, and must not be modified by this method.batchSize
- Suggested size of the batch of work.previousBatchPersisted
- If the previous batch was successfully persisted this parameter is set to true, which means the *next* batch should be returned. If false, it means the persist failed and the same batch as last time should be returned. Most implementations can ignore this parameter, but some that use a dynamic query or a List as basis must heed this parameter.Note: The first call to getBatchOfWork(..) will always pass false as no batch was processed yet.
- Returns:
- An iterator that contains items that should be processed as a single unit-of-work.
-
processItem
void processItem(SchedulerSession session, T item)
Process an item in a batched unit of work. This will be called for each item in a batch returned bygetBatchOfWork(SchedulerSession, int, boolean)
.- Parameters:
session
- A SchedulerSession that can be modified. The same session is passed as was used to obtain the batch of work.item
- The item from the batch returned bygetBatchOfWork(SchedulerSession, int, boolean)
.
-
-