org.alfresco.repo.batch
Class BatchProcessor<T>
org.alfresco.repo.batch.BatchProcessor<T> All Implemented Interfaces:
-
org.alfresco.repo.batch.BatchMonitor
@org.alfresco.api.AlfrescoPublicApi
public class BatchProcessor<T>
implements org.alfresco.repo.batch.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 Summary |
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) |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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) -
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
getCurrentEntryId
public String getCurrentEntryId() -
Specified by:
-
getCurrentEntryId in interface org.alfresco.repo.batch.BatchMonitor
getLastError
-
Specified by:
-
getLastError in interface org.alfresco.repo.batch.BatchMonitor
getLastErrorEntryId
public String getLastErrorEntryId() -
Specified by:
-
getLastErrorEntryId in interface org.alfresco.repo.batch.BatchMonitor
getProcessName
public String getProcessName() -
Specified by:
-
getProcessName in interface org.alfresco.repo.batch.BatchMonitor
getSuccessfullyProcessedEntries
public int getSuccessfullyProcessedEntries()
-
Specified by:
-
getSuccessfullyProcessedEntries in interface org.alfresco.repo.batch.BatchMonitor
getPercentComplete
public String getPercentComplete() -
Specified by:
-
getPercentComplete in interface org.alfresco.repo.batch.BatchMonitor
getTotalErrors
public int getTotalErrors()
-
Specified by:
-
getTotalErrors in interface org.alfresco.repo.batch.BatchMonitor
getTotalResults
public int getTotalResults()
-
Specified by:
-
getTotalResults in interface org.alfresco.repo.batch.BatchMonitor
getEndTime
-
Specified by:
-
getEndTime in interface org.alfresco.repo.batch.BatchMonitor
getStartTime
public Date getStartTime() -
Specified by:
-
getStartTime in interface org.alfresco.repo.batch.BatchMonitor
process
public int process(org.alfresco.repo.batch.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