Class ReliableIndexerListener

All Implemented Interfaces:
IndexerListener, Configurable, Runnable
Direct Known Subclasses:
ExtentIndexerListener

public class ReliableIndexerListener extends DefaultIndexerListener implements Runnable
ReliableIndexerListener listens for product changes by the indexer, then handles the new products independently in a background thread. This class does little more than output logs for the products it has seen; it is designed to be extended. Several useful methods are availble to be overridden or otherwise used:
  • onBeforeProcessThreadStart
  • onProcessException
  • getNextProducts
  • processProducts
This class accepts an index for querying in config:
index
(Required) The index to use for product querying.
  • Field Details

    • LOGGER

      protected static final Logger LOGGER
      Logger object
    • productIndex

      protected ProductIndex productIndex
      Product Index
  • Constructor Details

    • ReliableIndexerListener

      public ReliableIndexerListener()
  • Method Details

    • configure

      public void configure(Config config) throws Exception
      Sets up an object on start
      Specified by:
      configure in interface Configurable
      Overrides:
      configure in class DefaultIndexerListener
      Parameters:
      config - configuration
      Throws:
      Exception - if missing product index
    • onIndexerEvent

      public void onIndexerEvent(IndexerEvent delta) throws Exception
      Wakes thread when indexer makes changes
      Specified by:
      onIndexerEvent in interface IndexerListener
      Overrides:
      onIndexerEvent in class DefaultIndexerListener
      Parameters:
      delta - Indexer Event - not used
      Throws:
      Exception - if something goes wrong
    • run

      public void run()
      Thread main body. Waits until notified, then tries to get the next products and process them.
      Specified by:
      run in interface Runnable
    • startup

      public void startup() throws Exception
      Starts thread Calls onBeforeProcessThreadStart() in case subclasses want to add functionality
      Specified by:
      startup in interface Configurable
      Overrides:
      startup in class DefaultConfigurable
      Throws:
      Exception - if there's a thread issue
      Exception - if thread start fails
    • shutdown

      public void shutdown() throws Exception
      Closes thread
      Specified by:
      shutdown in interface Configurable
      Overrides:
      shutdown in class DefaultConfigurable
      Throws:
      Exception - if there's a thread issue
    • getProductIndex

      public ProductIndex getProductIndex()
      Returns:
      ProductIndex
    • setProductIndex

      public void setProductIndex(ProductIndex productIndex)
      Parameters:
      productIndex - to set
    • getLastIndexId

      public long getLastIndexId()
      Gets index ID of last processed product
      Returns:
      lastIndexId
    • setLastIndexId

      public void setLastIndexId(long lastIndexId)
      Sets index ID of last processed product
      Parameters:
      lastIndexId - to set
    • onBeforeProcessThreadStart

      protected void onBeforeProcessThreadStart() throws Exception
      Run before thread start.
      Throws:
      Exception - available for subclasses
    • onProductGetException

      protected void onProductGetException(Exception e) throws Exception
      Exception handling for product fetch
      Parameters:
      e - the caught exception
      Throws:
      Exception - in case we can't handle the first exception
    • onProcessException

      protected void onProcessException(ProductSummary product, Exception e) throws Exception
      Exception handling for product processing.
      Parameters:
      product - the product that gave us the error
      e - the caught exception
      Throws:
      Exception - in case we can't handle the first exception.
    • getNextProducts

      public List<ProductSummary> getNextProducts() throws Exception
      Gets the next products using the index provided in Config
      Returns:
      List of product summaries
      Throws:
      Exception - if we have a database issue
    • processProduct

      public void processProduct(ProductSummary product) throws Exception
      Does a task with each product
      Parameters:
      product - ProductSummary to process
      Throws:
      Exception - available for subclasses