Class BatchProcessor<T>

java.lang.Object
org.alfresco.repo.batch.BatchProcessor<T>
All Implemented Interfaces:
BatchMonitor

@AlfrescoPublicApi public class BatchProcessor<T> extends Object implements BatchMonitor
A BatchProcessor manages the running and monitoring of a potentially long-running transactional batch process. It iterates over a collection, and queues jobs that fire a worker on a batch of members. The queued jobs handle progress / error reporting, transaction delineation and retrying. They are processed in parallel by a pool of threads of a configurable size. The job processing is designed to be fault tolerant and will continue in the event of errors. When the batch is complete a summary of the number of errors and the last error stack trace will be logged at ERROR level. Each individual error is logged at WARN level and progress information is logged at INFO level. Through the BatchMonitor interface, it also supports the real-time monitoring of batch metrics (e.g. over JMX in the Enterprise Edition).
Author:
dward
  • Constructor Details

    • BatchProcessor

      public BatchProcessor(String processName, RetryingTransactionHelper retryingTransactionHelper, Collection<T> collection, int workerThreads, int batchSize, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.apache.commons.logging.Log logger, int loggingInterval)
      Deprecated.
      Since 3.4, use the BatchProcessWorkProvider instead of the Collection
      Instantiates a new batch processor.
      Parameters:
      processName - the process name
      retryingTransactionHelper - the retrying transaction helper
      collection - the collection
      workerThreads - the number of worker threads
      batchSize - the number of entries we process at a time in a transaction
      applicationEventPublisher - the application event publisher (may be null)
      logger - the logger to use (may be null)
      loggingInterval - the number of entries to process before reporting progress
    • BatchProcessor

      public BatchProcessor(String processName, RetryingTransactionHelper retryingTransactionHelper, BatchProcessWorkProvider<T> workProvider, int workerThreads, int batchSize, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.apache.commons.logging.Log logger, int loggingInterval)
      Instantiates a new batch processor.
      Parameters:
      processName - the process name
      retryingTransactionHelper - the retrying transaction helper
      workProvider - the object providing the work packets
      workerThreads - the number of worker threads
      batchSize - the number of entries we process at a time in a transaction
      applicationEventPublisher - the application event publisher (may be null)
      logger - the logger to use (may be null)
      loggingInterval - the number of entries to process before reporting progress
      Since:
      3.4
  • Method Details

    • getCurrentEntryId

      public String getCurrentEntryId()
      Gets the ID of the entry being processed
      Specified by:
      getCurrentEntryId in interface BatchMonitor
      Returns:
      the current entry id
    • getLastError

      public String getLastError()
      Gets the stack trace of the last error.
      Specified by:
      getLastError in interface BatchMonitor
      Returns:
      the stack trace of the last error
    • getLastErrorEntryId

      public String getLastErrorEntryId()
      Gets the entry id that caused the last error.
      Specified by:
      getLastErrorEntryId in interface BatchMonitor
      Returns:
      the last error entry id
    • getProcessName

      public String getProcessName()
      Gets the process name.
      Specified by:
      getProcessName in interface BatchMonitor
      Returns:
      the process name
    • getSuccessfullyProcessedEntries

      @Deprecated public int getSuccessfullyProcessedEntries()
      Deprecated.
      Gets the number of successfully processed entries.
      Specified by:
      getSuccessfullyProcessedEntries in interface BatchMonitor
      Returns:
      the successfully processed entries
    • getSuccessfullyProcessedEntriesLong

      public long getSuccessfullyProcessedEntriesLong()
      Gets the number of successfully processed entries.
      Specified by:
      getSuccessfullyProcessedEntriesLong in interface BatchMonitor
      Returns:
      the successfully processed entries
    • getPercentComplete

      public String getPercentComplete()
      Gets the progress expressed as a percentage.
      Specified by:
      getPercentComplete in interface BatchMonitor
      Returns:
      the progress expressed as a percentage
    • getTotalErrors

      @Deprecated public int getTotalErrors()
      Deprecated.
      Gets the total number of errors.
      Specified by:
      getTotalErrors in interface BatchMonitor
      Returns:
      the total number of errors
    • getTotalResults

      @Deprecated public int getTotalResults()
      Deprecated.
      Gets the total number of results.
      Specified by:
      getTotalResults in interface BatchMonitor
      Returns:
      the total number of results
    • getTotalErrorsLong

      public long getTotalErrorsLong()
      Gets the total number of errors.
      Specified by:
      getTotalErrorsLong in interface BatchMonitor
      Returns:
      the total number of errors
    • getTotalResultsLong

      public long getTotalResultsLong()
      Gets the total number of results.
      Specified by:
      getTotalResultsLong in interface BatchMonitor
      Returns:
      the total number of results
    • getEndTime

      public Date getEndTime()
      Gets the end time.
      Specified by:
      getEndTime in interface BatchMonitor
      Returns:
      the end time
    • getStartTime

      public Date getStartTime()
      Gets the start time.
      Specified by:
      getStartTime in interface BatchMonitor
      Returns:
      the start time
    • process

      @Deprecated public int process(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns)
      Invokes the worker for each entry in the collection, managing transactions and collating success / failure information.
      Parameters:
      worker - the worker
      splitTxns - Can the modifications to Alfresco be split across multiple transactions for maximum performance? If true, worker invocations are isolated in separate transactions in batches for increased performance. If false, all invocations are performed in the current transaction. This is required if calling synchronously (e.g. in response to an authentication event in the same transaction).
      Returns:
      the number of invocations
    • processLong

      public long processLong(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns)
      Invokes the worker for each entry in the collection, managing transactions and collating success / failure information.
      Parameters:
      worker - the worker
      splitTxns - Can the modifications to Alfresco be split across multiple transactions for maximum performance? If true, worker invocations are isolated in separate transactions in batches for increased performance. If false, all invocations are performed in the current transaction. This is required if calling synchronously (e.g. in response to an authentication event in the same transaction).
      Returns:
      the number of invocations