Package org.alfresco.repo.batch
Class BatchProcessor<T>
- java.lang.Object
-
- org.alfresco.repo.batch.BatchProcessor<T>
-
- All Implemented Interfaces:
BatchMonitor
@AlfrescoPublicApi public class BatchProcessor<T> extends java.lang.Object implements BatchMonitor
ABatchProcessormanages 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 theBatchMonitorinterface, it also supports the real-time monitoring of batch metrics (e.g. over JMX in the Enterprise Edition).- Author:
- dward
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceBatchProcessor.BatchProcessWorker<T>An interface for workers to be invoked by theBatchProcessor.static classBatchProcessor.BatchProcessWorkerAdaptor<TT>Adaptor that allows implementations to only implementBatchProcessor.BatchProcessWorker.process(Object)
-
Constructor Summary
Constructors Constructor Description BatchProcessor(java.lang.String processName, RetryingTransactionHelper retryingTransactionHelper, java.util.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 theBatchProcessWorkProviderinstead of the CollectionBatchProcessor(java.lang.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetCurrentEntryId()Gets the ID of the entry being processedjava.util.DategetEndTime()Gets the end time.java.lang.StringgetLastError()Gets the stack trace of the last error.java.lang.StringgetLastErrorEntryId()Gets the entry id that caused the last error.java.lang.StringgetPercentComplete()Gets the progress expressed as a percentage.java.lang.StringgetProcessName()Gets the process name.java.util.DategetStartTime()Gets the start time.intgetSuccessfullyProcessedEntries()Gets the number of successfully processed entries.intgetTotalErrors()Gets the total number of errors.intgetTotalResults()Gets the total number of results.intprocess(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns)Invokes the worker for each entry in the collection, managing transactions and collating success / failure information.
-
-
-
Constructor Detail
-
BatchProcessor
public BatchProcessor(java.lang.String processName, RetryingTransactionHelper retryingTransactionHelper, java.util.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 theBatchProcessWorkProviderinstead of the CollectionInstantiates a new batch processor.- Parameters:
processName- the process nameretryingTransactionHelper- the retrying transaction helpercollection- the collectionworkerThreads- the number of worker threadsbatchSize- the number of entries we process at a time in a transactionapplicationEventPublisher- 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(java.lang.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 nameretryingTransactionHelper- the retrying transaction helperworkProvider- the object providing the work packetsworkerThreads- the number of worker threadsbatchSize- the number of entries we process at a time in a transactionapplicationEventPublisher- 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 Detail
-
getCurrentEntryId
public java.lang.String getCurrentEntryId()
Gets the ID of the entry being processed- Specified by:
getCurrentEntryIdin interfaceBatchMonitor- Returns:
- the current entry id
-
getLastError
public java.lang.String getLastError()
Gets the stack trace of the last error.- Specified by:
getLastErrorin interfaceBatchMonitor- Returns:
- the stack trace of the last error
-
getLastErrorEntryId
public java.lang.String getLastErrorEntryId()
Gets the entry id that caused the last error.- Specified by:
getLastErrorEntryIdin interfaceBatchMonitor- Returns:
- the last error entry id
-
getProcessName
public java.lang.String getProcessName()
Gets the process name.- Specified by:
getProcessNamein interfaceBatchMonitor- Returns:
- the process name
-
getSuccessfullyProcessedEntries
public int getSuccessfullyProcessedEntries()
Gets the number of successfully processed entries.- Specified by:
getSuccessfullyProcessedEntriesin interfaceBatchMonitor- Returns:
- the successfully processed entries
-
getPercentComplete
public java.lang.String getPercentComplete()
Gets the progress expressed as a percentage.- Specified by:
getPercentCompletein interfaceBatchMonitor- Returns:
- the progress expressed as a percentage
-
getTotalErrors
public int getTotalErrors()
Gets the total number of errors.- Specified by:
getTotalErrorsin interfaceBatchMonitor- Returns:
- the total number of errors
-
getTotalResults
public int getTotalResults()
Gets the total number of results.- Specified by:
getTotalResultsin interfaceBatchMonitor- Returns:
- the total number of results
-
getEndTime
public java.util.Date getEndTime()
Gets the end time.- Specified by:
getEndTimein interfaceBatchMonitor- Returns:
- the end time
-
getStartTime
public java.util.Date getStartTime()
Gets the start time.- Specified by:
getStartTimein interfaceBatchMonitor- Returns:
- the start time
-
process
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 workersplitTxns- Can the modifications to Alfresco be split across multiple transactions for maximum performance? Iftrue, worker invocations are isolated in separate transactions in batches for increased performance. Iffalse, 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
-
-