Class ConcurrentJob<T>

java.lang.Object
org.kuali.rice.ken.service.impl.ConcurrentJob<T>
Direct Known Subclasses:
NotificationMessageDeliveryAutoRemovalServiceImpl, NotificationMessageDeliveryResolverServiceImpl

public abstract class ConcurrentJob<T> extends Object
Base class for jobs that must obtain a set of work items atomically
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected ExecutorService
     
    protected final org.apache.logging.log4j.Logger
     
    protected org.springframework.transaction.PlatformTransactionManager
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConcurrentJob(org.springframework.transaction.PlatformTransactionManager txManager, ExecutorService executor)
    Constructs a ConcurrentJob instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.transaction.support.TransactionTemplate
    Helper method for creating a TransactionTemplate initialized to create a new transaction
    protected Collection<Collection<T>>
    Template method that subclasses should override to group work items into units of work
    protected abstract Collection<?>
    Template method that subclasses should override to process a given work item and mark it as untaken afterwards
    run()
    Main processing method which invokes subclass implementations of template methods to obtain available work items, and process them concurrently
    protected abstract Collection<T>
    Template method that subclasses should override to obtain a set of available work items and mark them as taken
    protected abstract void
    Template method that subclasses should override to unlock a given work item when procesing has failed.
    protected void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      protected final org.apache.logging.log4j.Logger LOG
    • executor

      protected ExecutorService executor
    • txManager

      protected org.springframework.transaction.PlatformTransactionManager txManager
  • Constructor Details

    • ConcurrentJob

      public ConcurrentJob(org.springframework.transaction.PlatformTransactionManager txManager, ExecutorService executor)
      Constructs a ConcurrentJob instance.
      Parameters:
      txManager - PlatformTransactionManager to use for transactions
      executor - the ExecutorService to use to process work items
  • Method Details

    • 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

      protected abstract Collection<T> 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 result)
      Template method that subclasses should override to group work items into units of work
      Parameters:
      workItems - list of work items to break into groups
      result - 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

      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
      Parameters:
      items - the work item
      Returns:
      a collection of success messages
    • unlockWorkItem

      protected abstract void unlockWorkItem(T item)
      Template method that subclasses should override to unlock a given work item when procesing has failed.
      Parameters:
      item - the work item to unlock
    • run

      public ProcessingResult 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
    • unlockWorkItemAtomically

      protected void unlockWorkItemAtomically(T workItem)