Package org.alfresco.repo.batch
Class BatchProcessor<T>
java.lang.Object
org.alfresco.repo.batch.BatchProcessor<T>
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn interface for workers to be invoked by theBatchProcessor.static classAdaptor that allows implementations to only implementBatchProcessor.BatchProcessWorker.process(Object) -
Constructor Summary
ConstructorsConstructorDescriptionBatchProcessor(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.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. -
Method Summary
Modifier and TypeMethodDescriptionGets the ID of the entry being processedGets the end time.Gets the stack trace of the last error.Gets the entry id that caused the last error.Gets the progress expressed as a percentage.Gets the process name.Gets the start time.intDeprecated.longGets the number of successfully processed entries.intDeprecated.longGets the total number of errors.intDeprecated.longGets the total number of results.intprocess(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns) Deprecated.useprocessLong(BatchProcessWorker, boolean)insteadlongprocessLong(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns) Invokes the worker for each entry in the collection, managing transactions and collating success / failure information.
-
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 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(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 Details
-
getCurrentEntryId
Gets the ID of the entry being processed- Specified by:
getCurrentEntryIdin interfaceBatchMonitor- Returns:
- the current entry id
-
getLastError
Gets the stack trace of the last error.- Specified by:
getLastErrorin interfaceBatchMonitor- Returns:
- the stack trace of the last error
-
getLastErrorEntryId
Gets the entry id that caused the last error.- Specified by:
getLastErrorEntryIdin interfaceBatchMonitor- Returns:
- the last error entry id
-
getProcessName
Gets the process name.- Specified by:
getProcessNamein interfaceBatchMonitor- Returns:
- the process name
-
getSuccessfullyProcessedEntries
Deprecated.Gets the number of successfully processed entries.- Specified by:
getSuccessfullyProcessedEntriesin interfaceBatchMonitor- Returns:
- the successfully processed entries
-
getSuccessfullyProcessedEntriesLong
public long getSuccessfullyProcessedEntriesLong()Gets the number of successfully processed entries.- Specified by:
getSuccessfullyProcessedEntriesLongin interfaceBatchMonitor- Returns:
- the successfully processed entries
-
getPercentComplete
Gets the progress expressed as a percentage.- Specified by:
getPercentCompletein interfaceBatchMonitor- Returns:
- the progress expressed as a percentage
-
getTotalErrors
Deprecated.Gets the total number of errors.- Specified by:
getTotalErrorsin interfaceBatchMonitor- Returns:
- the total number of errors
-
getTotalResults
Deprecated.Gets the total number of results.- Specified by:
getTotalResultsin interfaceBatchMonitor- Returns:
- the total number of results
-
getTotalErrorsLong
public long getTotalErrorsLong()Gets the total number of errors.- Specified by:
getTotalErrorsLongin interfaceBatchMonitor- Returns:
- the total number of errors
-
getTotalResultsLong
public long getTotalResultsLong()Gets the total number of results.- Specified by:
getTotalResultsLongin interfaceBatchMonitor- Returns:
- the total number of results
-
getEndTime
Gets the end time.- Specified by:
getEndTimein interfaceBatchMonitor- Returns:
- the end time
-
getStartTime
Gets the start time.- Specified by:
getStartTimein interfaceBatchMonitor- Returns:
- the start time
-
process
Deprecated.useprocessLong(BatchProcessWorker, boolean)insteadInvokes 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
-
processLong
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
-
BatchProcessWorkProviderinstead of the Collection