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:
    1. Obtain a batch of work via getBatchOfWork(SchedulerSession, int, boolean).
    2. If the batch is empty, all work is done.
    3. Invoke processItem(SchedulerSession, Object) with each item in the non-empty batch of work.
    4. Persist the session and start over.
    5. If an exception occurs due to competition, start over. Heed the previousBatchPersisted parameter, as it may apply to your implementation.
    6. If any other exception occurs, abort and propagate the error.
    See Also:
    SchedulerSessionBatchedUnitOfWorkManager
    • Field Detail

      • VERSION_SSIBUOW

        static final com.redwood.scheduler.infrastructure.logging.Versions VERSION_SSIBUOW
    • 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.