Class DefaultSolrIndexQueueProvider

java.lang.Object
org.broadleafcommerce.core.search.service.solr.indexer.DefaultSolrIndexQueueProvider
All Implemented Interfaces:
SolrIndexQueueProvider

public class DefaultSolrIndexQueueProvider extends Object implements SolrIndexQueueProvider
Default component to obtain a command Queue and a Lock to access the command queue. The queue should only be accessed by a single thread at a time, and so accessors must first obtain a lock. This is to prevent two threads, even across nodes, from issuing commands to Solr that might interfere with one another (e.g. re-aliasing or committing).

This default implementation evaluates the SolrClient to determine whether to use a local Queue and Lock, or whether to use a distributed Queue and Lock. If the SolrClient is an instance of CloudSolrClient then this will use the associated Zookeeper to manage the lock and the queue. Otherwise, it will use a local (non-distributed) lock and queue.

This can be extended to provide different queue and lock implementations. If you override them, then they both need to be distributed or local. Having a local lock and a distributed queue or vice versa will not work.

Author:
Kelly Tisdell
  • Field Details

  • Constructor Details

    • DefaultSolrIndexQueueProvider

      public DefaultSolrIndexQueueProvider()
    • DefaultSolrIndexQueueProvider

      public DefaultSolrIndexQueueProvider(org.apache.zookeeper.ZooKeeper zookeeper, org.springframework.core.env.Environment env)
  • Method Details

    • createOrRetrieveCommandQueue

      public BlockingQueue<? super SolrUpdateCommand> createOrRetrieveCommandQueue(String queueName)
      Specified by:
      createOrRetrieveCommandQueue in interface SolrIndexQueueProvider
    • createOrRetrieveCommandLock

      public Lock createOrRetrieveCommandLock(String lockName)
      Specified by:
      createOrRetrieveCommandLock in interface SolrIndexQueueProvider
    • isDistributed

      public boolean isDistributed()
      Indicates if this is a distributed environment (e.g. the Lock and Queue are distributed, e.g. backed by Zookeeper.)
      Specified by:
      isDistributed in interface SolrIndexQueueProvider
    • getEnvironment

      protected org.springframework.core.env.Environment getEnvironment()
      Returns the Environment object, which is used in a distributed situation to determine if the current node or application can obtain a lock. This may return null.
      Returns:
    • getZookeeper

      protected org.apache.zookeeper.ZooKeeper getZookeeper()
      Returns the ZooKeeper instance that distributes the Lock and the Queue. This may return null in non-distributed situation.
      Returns:
    • createLocalQueue

      protected BlockingQueue<? super SolrUpdateCommand> createLocalQueue(String queueName)
    • createDistributedQueue

      protected BlockingQueue<? super SolrUpdateCommand> createDistributedQueue(String queueName)
    • createLocalLock

      protected Lock createLocalLock(String lockName)
    • createDistributedLock

      protected Lock createDistributedLock(String lockName)