public class BatchProcessor extends java.lang.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
An interface for workers to be invoked by the
BatchProcessor. |
static class |
BatchProcessor.BatchProcessWorkerAdaptor
Adaptor that allows implementations to only implement
BatchProcessor.BatchProcessWorker.process(Object) |
| Constructor and Description |
|---|
BatchProcessor(java.lang.String processName,
RetryingTransactionHelper retryingTransactionHelper,
BatchProcessWorkProvider workProvider,
int workerThreads,
int batchSize,
org.springframework.context.ApplicationEventPublisher applicationEventPublisher,
org.apache.commons.logging.Log logger,
int loggingInterval)
Instantiates a new batch processor.
|
BatchProcessor(java.lang.String processName,
RetryingTransactionHelper retryingTransactionHelper,
java.util.Collection 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 |
|---|---|
java.lang.String |
getCurrentEntryId()
Gets the ID of the entry being processed
|
java.util.Date |
getEndTime()
Gets the end time.
|
java.lang.String |
getLastError()
Gets the stack trace of the last error.
|
java.lang.String |
getLastErrorEntryId()
Gets the entry id that caused the last error.
|
java.lang.String |
getPercentComplete()
Gets the progress expressed as a percentage.
|
java.lang.String |
getProcessName()
Gets the process name.
|
java.util.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 worker,
boolean splitTxns)
Invokes the worker for each entry in the collection, managing transactions and collating success / failure
information.
|
public BatchProcessor(java.lang.String processName,
RetryingTransactionHelper retryingTransactionHelper,
java.util.Collection 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(java.lang.String processName,
RetryingTransactionHelper retryingTransactionHelper,
BatchProcessWorkProvider 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 java.lang.String getCurrentEntryId()
getCurrentEntryId in interface BatchMonitorpublic java.lang.String getLastError()
getLastError in interface BatchMonitorpublic java.lang.String getLastErrorEntryId()
getLastErrorEntryId in interface BatchMonitorpublic java.lang.String getProcessName()
getProcessName in interface BatchMonitorpublic int getSuccessfullyProcessedEntries()
getSuccessfullyProcessedEntries in interface BatchMonitorpublic java.lang.String getPercentComplete()
getPercentComplete in interface BatchMonitorpublic int getTotalErrors()
getTotalErrors in interface BatchMonitorpublic int getTotalResults()
getTotalResults in interface BatchMonitorpublic java.util.Date getEndTime()
getEndTime in interface BatchMonitorpublic java.util.Date getStartTime()
getStartTime in interface BatchMonitorpublic int process(BatchProcessor.BatchProcessWorker 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 - 2010 Alfresco Software, Inc. All Rights Reserved.