public class BatchProcessor<T> extends Object implements BatchMonitor
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).Modifier and Type | Class and Description |
---|---|
static interface |
BatchProcessor.BatchProcessWorker<T>
An interface for workers to be invoked by the
BatchProcessor . |
static class |
BatchProcessor.BatchProcessWorkerAdaptor<TT>
Adaptor that allows implementations to only implement
BatchProcessor.BatchProcessWorker.process(Object) |
Constructor and Description |
---|
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.
|
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 |
Modifier and Type | Method and Description |
---|---|
String |
getCurrentEntryId()
Gets the ID of the entry being processed
|
Date |
getEndTime()
Gets the end time.
|
String |
getLastError()
Gets the stack trace of the last error.
|
String |
getLastErrorEntryId()
Gets the entry id that caused the last error.
|
String |
getPercentComplete()
Gets the progress expressed as a percentage.
|
String |
getProcessName()
Gets the process name.
|
Date |
getStartTime()
Gets the start time.
|
int |
getSuccessfullyProcessedEntries()
Gets the number of successfully processed entries.
|
int |
getTotalErrors()
Gets the total number of errors.
|
int |
getTotalResults()
Gets the total number of results.
|
int |
process(BatchProcessor.BatchProcessWorker<T> worker,
boolean splitTxns)
Invokes the worker for each entry in the collection, managing transactions and collating success / failure
information.
|
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)
BatchProcessWorkProvider
instead of the CollectionprocessName
- 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 progresspublic 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)
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 progresspublic String getCurrentEntryId()
getCurrentEntryId
in interface BatchMonitor
public String getLastError()
getLastError
in interface BatchMonitor
public String getLastErrorEntryId()
getLastErrorEntryId
in interface BatchMonitor
public String getProcessName()
getProcessName
in interface BatchMonitor
public int getSuccessfullyProcessedEntries()
getSuccessfullyProcessedEntries
in interface BatchMonitor
public String getPercentComplete()
getPercentComplete
in interface BatchMonitor
public int getTotalErrors()
getTotalErrors
in interface BatchMonitor
public int getTotalResults()
getTotalResults
in interface BatchMonitor
public Date getEndTime()
getEndTime
in interface BatchMonitor
public Date getStartTime()
getStartTime
in interface BatchMonitor
public int process(BatchProcessor.BatchProcessWorker<T> worker, boolean splitTxns)
worker
- the workersplitTxns
- 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).Copyright © 2005–2017 Alfresco Software. All rights reserved.