Class AbstractSolrIndexUpdateServiceImpl

java.lang.Object
org.broadleafcommerce.core.search.service.solr.indexer.AbstractSolrIndexUpdateServiceImpl
All Implemented Interfaces:
SolrIndexUpdateService, org.springframework.beans.factory.DisposableBean
Direct Known Subclasses:
CatalogSolrIndexUpdateServiceImpl

public abstract class AbstractSolrIndexUpdateServiceImpl extends Object implements SolrIndexUpdateService, org.springframework.beans.factory.DisposableBean
This component is an abstract component that will be extended by more concrete implementations for updating or reindexing Solr. This makes use of a single background Thread, per command type (or command identifier - i.e. "catalog") that monitors a command queue, ensuring that all commands to update or reindex Solr happen serially for a given command identifier, but without blocking the calling thread that is issuing the command.

This component makes use of a Lock and a BlockingQueue. The providers for these components, SolrIndexQueueProvider and SolrIndexLockProvider provide an isDistributed() method. They must both return the same value. Note that if isDistributed() returns false, then care must be taken to ensure that 2 or more nodes (i.e. JVMs) cannot execute at the same time. This is typically done by ensuring that only a single node will receive calls/events to update a Solr index.

Author:
Kelly Tisdell
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.solr.common.SolrInputDocument
    Provides an interface for a caller to convert an Indexable into a SolrInputDocument.
    org.apache.solr.common.SolrInputDocument
    buildDocument(Indexable indexable, List<IndexField> fields, List<Locale> locales)
    Provides an interface for a caller to convert an Indexable into a SolrInputDocument.
    void
     
    final String
    This is any arbitrary name to identify or group commands, typically based on the Solr index (or indexes) being updated.
    protected long
    Amount of time that will be waited, assuming the queue is full, for space to become available in the queue.
    protected long
    Amount of time in millis that the queue will be polled before returning an item or null.
    static boolean
    isRunning(String commandIdentifier)
     
    void
    Default behavior is to truncate the background collection (offline index), populate it with documents, commit, and then swap (re-alias) so that it becomes the foreground collection and the foreground collection becomes the background.
    protected final <C extends SolrUpdateCommand>
    void
    scheduleCommand(C command)
     
    static void
    Stops all threads that are listening to various command queues.
    void
    updateIndex(List<org.apache.solr.common.SolrInputDocument> documents)
    This is for relatively small, autonomous, incremental updates to the main (customer-facing) foreground Solr collection / index.
    void
    updateIndex(List<org.apache.solr.common.SolrInputDocument> documents, List<String> deleteQueries)
    This is for relatively small, autonomous, incremental updates to the main (customer-facing) foreground Solr collection / index.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • shutdownAll

      public static void shutdownAll()
      Stops all threads that are listening to various command queues.
    • getCommandGroup

      public final String getCommandGroup()
      This is any arbitrary name to identify or group commands, typically based on the Solr index (or indexes) being updated. For example, "catalog" will likely be a command identifier. It could also be "product", but in less common cases where you want to index categories or other things with products and you want to serialize those commands, then this can assist.
      Returns:
    • scheduleCommand

      protected final <C extends SolrUpdateCommand> void scheduleCommand(C command)
    • isRunning

      public static boolean isRunning(String commandIdentifier)
    • rebuildIndex

      public void rebuildIndex() throws ServiceException
      Description copied from interface: SolrIndexUpdateService
      Default behavior is to truncate the background collection (offline index), populate it with documents, commit, and then swap (re-alias) so that it becomes the foreground collection and the foreground collection becomes the background.
      Specified by:
      rebuildIndex in interface SolrIndexUpdateService
      Throws:
      ServiceException
    • updateIndex

      public void updateIndex(List<org.apache.solr.common.SolrInputDocument> documents)
      Description copied from interface: SolrIndexUpdateService
      This is for relatively small, autonomous, incremental updates to the main (customer-facing) foreground Solr collection / index.

      Writes the documents to the foreground collection / index. Then issues a commit.

      This should not be used for incremental indexing in the context of a larger indexing scope or operation.

      Specified by:
      updateIndex in interface SolrIndexUpdateService
    • updateIndex

      public void updateIndex(List<org.apache.solr.common.SolrInputDocument> documents, List<String> deleteQueries)
      Description copied from interface: SolrIndexUpdateService
      This is for relatively small, autonomous, incremental updates to the main (customer-facing) foreground Solr collection / index.

      Executes the delete queries, if any, in the foreground index. Then writes the documents, if any, to the foreground index. Then commits if no errors occur.

      This should not be used for incremental indexing in the context of a larger indexing scope or operation.

      Specified by:
      updateIndex in interface SolrIndexUpdateService
    • buildDocument

      public org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable)
      Description copied from interface: SolrIndexUpdateService
      Provides an interface for a caller to convert an Indexable into a SolrInputDocument. This may return null if the implementor does not want the specified Indexable indexed.
      Specified by:
      buildDocument in interface SolrIndexUpdateService
      Returns:
    • buildDocument

      public org.apache.solr.common.SolrInputDocument buildDocument(Indexable indexable, List<IndexField> fields, List<Locale> locales)
      Description copied from interface: SolrIndexUpdateService
      Provides an interface for a caller to convert an Indexable into a SolrInputDocument. This may return null if the implementor does not want the specified Indexable indexed.
      Specified by:
      buildDocument in interface SolrIndexUpdateService
      Returns:
    • getQueuePollTime

      protected long getQueuePollTime()
      Amount of time in millis that the queue will be polled before returning an item or null. Default is 1 minute (60000 ms). If you override this method, it must return a positive long value, preferrably greater than 60000 to reduce the polling cycles.
      Returns:
    • getQueueOfferTime

      protected long getQueueOfferTime()
      Amount of time that will be waited, assuming the queue is full, for space to become available in the queue. Default is 1 second (1000 ms).
      Returns: