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
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      Iterator<T> getBatchOfWork​(com.redwood.scheduler.api.model.SchedulerSession session, int batchSize, boolean previousBatchPersisted)
      Obtain a batch of work to perform.
      void processItem​(com.redwood.scheduler.api.model.SchedulerSession session, T item)
      Process an item in a batched unit of work.
    • Method Detail

      • getBatchOfWork

        Iterator<T> getBatchOfWork​(com.redwood.scheduler.api.model.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​(com.redwood.scheduler.api.model.SchedulerSession session,
                         T item)
        Process an item in a batched unit of work. This will be called for each item in a batch returned by getBatchOfWork(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 by getBatchOfWork(SchedulerSession, int, boolean).