Class DefaultSolrIndexQueueProvider
java.lang.Object
org.broadleafcommerce.core.search.service.solr.indexer.DefaultSolrIndexQueueProvider
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final Stringprotected static final Map<String,BlockingQueue<? super SolrUpdateCommand>> Fields inherited from interface org.broadleafcommerce.core.search.service.solr.indexer.SolrIndexQueueProvider
COMMAND_LOCK_NAME, COMMAND_QUEUE_NAME -
Constructor Summary
ConstructorsConstructorDescriptionDefaultSolrIndexQueueProvider(org.apache.zookeeper.ZooKeeper zookeeper, org.springframework.core.env.Environment env) -
Method Summary
Modifier and TypeMethodDescriptionprotected LockcreateDistributedLock(String lockName) protected BlockingQueue<? super SolrUpdateCommand>createDistributedQueue(String queueName) protected LockcreateLocalLock(String lockName) protected BlockingQueue<? super SolrUpdateCommand>createLocalQueue(String queueName) createOrRetrieveCommandLock(String lockName) BlockingQueue<? super SolrUpdateCommand>createOrRetrieveCommandQueue(String queueName) protected org.springframework.core.env.EnvironmentReturns theEnvironmentobject, which is used in a distributed situation to determine if the current node or application can obtain a lock.protected org.apache.zookeeper.ZooKeeperReturns theZooKeeperinstance that distributes the Lock and the Queue.booleanIndicates if this is a distributed environment (e.g. the Lock and Queue are distributed, e.g. backed by Zookeeper.)
-
Field Details
-
MAX_QUEUE_SIZE
public static final int MAX_QUEUE_SIZE- See Also:
-
LOCK_PATH
- See Also:
-
QUEUE_PATH
- See Also:
-
QUEUE_REGISTRY
-
LOCK_REGISTRY
-
-
Constructor Details
-
DefaultSolrIndexQueueProvider
public DefaultSolrIndexQueueProvider() -
DefaultSolrIndexQueueProvider
public DefaultSolrIndexQueueProvider(org.apache.zookeeper.ZooKeeper zookeeper, org.springframework.core.env.Environment env)
-
-
Method Details
-
createOrRetrieveCommandQueue
- Specified by:
createOrRetrieveCommandQueuein interfaceSolrIndexQueueProvider
-
createOrRetrieveCommandLock
- Specified by:
createOrRetrieveCommandLockin interfaceSolrIndexQueueProvider
-
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:
isDistributedin interfaceSolrIndexQueueProvider
-
getEnvironment
protected org.springframework.core.env.Environment getEnvironment()Returns theEnvironmentobject, 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 theZooKeeperinstance that distributes the Lock and the Queue. This may return null in non-distributed situation.- Returns:
-
createLocalQueue
-
createDistributedQueue
-
createLocalLock
-
createDistributedLock
-