org.alfresco.repo.batch
Class BatchProcessor

java.lang.Object
  extended by org.alfresco.repo.batch.BatchProcessor
All Implemented Interfaces:
BatchMonitor

public class BatchProcessor
extends java.lang.Object
implements 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).


Nested Class Summary
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 Summary
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
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchProcessor

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)
Deprecated. Since 3.4, use the BatchProcessWorkProvider instead of the Collection

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(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.

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
Method Detail

getCurrentEntryId

public java.lang.String getCurrentEntryId()
Gets the ID of the entry being processed

Specified by:
getCurrentEntryId in interface BatchMonitor
Returns:
the current entry id

getLastError

public java.lang.String getLastError()
Gets the stack trace of the last error.

Specified by:
getLastError in interface BatchMonitor
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:
getLastErrorEntryId in interface BatchMonitor
Returns:
the last error entry id

getProcessName

public java.lang.String getProcessName()
Gets the process name.

Specified by:
getProcessName in interface BatchMonitor
Returns:
the process name

getSuccessfullyProcessedEntries

public int getSuccessfullyProcessedEntries()
Gets the number of successfully processed entries.

Specified by:
getSuccessfullyProcessedEntries in interface BatchMonitor
Returns:
the successfully processed entries

getPercentComplete

public java.lang.String getPercentComplete()
Gets the progress expressed as a percentage.

Specified by:
getPercentComplete in interface BatchMonitor
Returns:
the progress expressed as a percentage

getTotalErrors

public int getTotalErrors()
Gets the total number of errors.

Specified by:
getTotalErrors in interface BatchMonitor
Returns:
the total number of errors

getTotalResults

public int getTotalResults()
Gets the total number of results.

Specified by:
getTotalResults in interface BatchMonitor
Returns:
the total number of results

getEndTime

public java.util.Date getEndTime()
Gets the end time.

Specified by:
getEndTime in interface BatchMonitor
Returns:
the end time

getStartTime

public java.util.Date getStartTime()
Gets the start time.

Specified by:
getStartTime in interface BatchMonitor
Returns:
the start time

process

public int process(BatchProcessor.BatchProcessWorker 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


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.