public abstract class ConcurrentJob<T> extends Object
Modifier and Type | Field and Description |
---|---|
protected ExecutorService |
executor |
protected org.apache.log4j.Logger |
LOG |
protected org.springframework.transaction.PlatformTransactionManager |
txManager |
Constructor and Description |
---|
ConcurrentJob(org.springframework.transaction.PlatformTransactionManager txManager,
ExecutorService executor)
Constructs a ConcurrentJob instance.
|
Modifier and Type | Method and Description |
---|---|
protected org.springframework.transaction.support.TransactionTemplate |
createNewTransaction()
Helper method for creating a TransactionTemplate initialized to create
a new transaction
|
protected Collection<Collection<T>> |
groupWorkItems(Collection<T> workItems,
ProcessingResult result)
Template method that subclasses should override to group work items into units of work
|
protected abstract Collection<?> |
processWorkItems(Collection<T> items)
Template method that subclasses should override to process a given work item and mark it
as untaken afterwards
|
ProcessingResult |
run()
Main processing method which invokes subclass implementations of template methods
to obtain available work items, and process them concurrently
|
protected abstract Collection<T> |
takeAvailableWorkItems()
Template method that subclasses should override to obtain a set of available work items
and mark them as taken
|
protected abstract void |
unlockWorkItem(T item)
Template method that subclasses should override to unlock a given work item when procesing has failed.
|
protected void |
unlockWorkItemAtomically(T workItem) |
protected final org.apache.log4j.Logger LOG
protected ExecutorService executor
protected org.springframework.transaction.PlatformTransactionManager txManager
public ConcurrentJob(org.springframework.transaction.PlatformTransactionManager txManager, ExecutorService executor)
txManager
- PlatformTransactionManager to use for transactionsexecutor
- the ExecutorService to use to process work itemsprotected org.springframework.transaction.support.TransactionTemplate createNewTransaction()
protected abstract Collection<T> takeAvailableWorkItems()
protected Collection<Collection<T>> groupWorkItems(Collection<T> workItems, ProcessingResult result)
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 failureprotected abstract Collection<?> processWorkItems(Collection<T> items)
items
- the work itemprotected abstract void unlockWorkItem(T item)
item
- the work item to unlockpublic ProcessingResult run()
protected void unlockWorkItemAtomically(T workItem)
Copyright © 2005–2016 The Kuali Foundation. All rights reserved.