Class ReliableIndexerListener

  • All Implemented Interfaces:
    IndexerListener, Configurable, java.lang.Runnable
    Direct Known Subclasses:
    ExtentIndexerListener

    public class ReliableIndexerListener
    extends DefaultIndexerListener
    implements java.lang.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 Detail

      • LOGGER

        protected static final java.util.logging.Logger LOGGER
        Logger object
      • productIndex

        protected ProductIndex productIndex
        Product Index
    • Constructor Detail

      • ReliableIndexerListener

        public ReliableIndexerListener()
    • Method Detail

      • configure

        public void configure​(Config config)
                       throws java.lang.Exception
        Sets up an object on start
        Specified by:
        configure in interface Configurable
        Overrides:
        configure in class DefaultIndexerListener
        Parameters:
        config - configuration
        Throws:
        java.lang.Exception - if missing product index
      • 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 java.lang.Runnable
      • startup

        public void startup()
                     throws java.lang.Exception
        Starts thread Calls onBeforeProcessThreadStart() in case subclasses want to add functionality
        Specified by:
        startup in interface Configurable
        Overrides:
        startup in class DefaultConfigurable
        Throws:
        java.lang.Exception - if there's a thread issue
        java.lang.Exception - if thread start fails
      • 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 java.lang.Exception
        Run before thread start.
        Throws:
        java.lang.Exception - available for subclasses
      • onProductGetException

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

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

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

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