Package org.kuali.rice.kcb.quartz
Class ConcurrentJob<T>
java.lang.Object
org.kuali.rice.kcb.quartz.ConcurrentJob<T>
- Direct Known Subclasses:
MessageProcessingJob
Base class for jobs that must obtain a set of work items atomically
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorServiceprotected final org.apache.logging.log4j.Loggerprotected org.springframework.transaction.PlatformTransactionManager -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.transaction.support.TransactionTemplateHelper method for creating a TransactionTemplate initialized to create a new transactionprotected <X> XexecuteInTransaction(org.springframework.transaction.support.TransactionCallback callback) protected voidfinishProcessing(ProcessingResult<T> result) Template method called after processing of work items has completedprotected Collection<Collection<T>>groupWorkItems(Collection<T> workItems, ProcessingResult<T> result) Template method that subclasses should override to group work items into units of workprotected abstract Collection<T>processWorkItems(Collection<T> items) Template method that subclasses should override to process a given work item and mark it as untaken afterwardsrun()Main processing method which invokes subclass implementations of template methods to obtain available work items, and process them concurrentlyvoidsetExecutorService(ExecutorService executor) Sets theExecutorServiceto use to process work items.voidsetTransactionManager(org.springframework.transaction.PlatformTransactionManager txManager) Sets thePlatformTransactionManagerprotected abstract Collection<T>Template method that subclasses should override to obtain a set of available work items and mark them as takenprotected abstract voidunlockWorkItem(T item) Template method that subclasses should override to unlock a given work item when procesing has failed.protected voidunlockWorkItemAtomically(T workItem)
-
Field Details
-
LOG
protected final org.apache.logging.log4j.Logger LOG -
executor
-
txManager
protected org.springframework.transaction.PlatformTransactionManager txManager
-
-
Constructor Details
-
ConcurrentJob
public ConcurrentJob()
-
-
Method Details
-
setExecutorService
Sets theExecutorServiceto use to process work items. Default is single-threaded.- Parameters:
executor- theExecutorServiceto use to process work items. Default is single-threaded.
-
setTransactionManager
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager txManager) Sets thePlatformTransactionManager- Parameters:
txManager- thePlatformTransactionManager
-
createNewTransaction
protected org.springframework.transaction.support.TransactionTemplate createNewTransaction()Helper method for creating a TransactionTemplate initialized to create a new transaction- Returns:
- a TransactionTemplate initialized to create a new transaction
-
takeAvailableWorkItems
Template method that subclasses should override to obtain a set of available work items and mark them as taken- Returns:
- a collection of available work items that have been marked as taken
-
groupWorkItems
protected Collection<Collection<T>> groupWorkItems(Collection<T> workItems, ProcessingResult<T> result) Template method that subclasses should override to group work items into units of work- Parameters:
workItems- list of work items to break into groupsresult- ProcessingResult to modify if there are any failures...this is sort of a hack because previously failure to obtain a deliverer was considered a work item failure, and now this method has been factored out... but the tests still want to see the failure- Returns:
- a collection of collection of work items
-
processWorkItems
Template method that subclasses should override to process a given work item and mark it as untaken afterwards- Parameters:
item- the work item- Returns:
- a collection of success messages
-
unlockWorkItem
Template method that subclasses should override to unlock a given work item when procesing has failed.- Parameters:
item- the work item to unlock
-
run
Main processing method which invokes subclass implementations of template methods to obtain available work items, and process them concurrently- Returns:
- a ProcessingResult object containing the results of processing
-
finishProcessing
Template method called after processing of work items has completed -
unlockWorkItemAtomically
-
executeInTransaction
protected <X> X executeInTransaction(org.springframework.transaction.support.TransactionCallback callback)
-