Class GenericSearchIndexMasterProcessLauncher<T>
java.lang.Object
com.broadleafcommerce.search.index.core.master.GenericSearchIndexMasterProcessLauncher<T>
- Type Parameters:
T
- The type that will be read by theQueueLoader
and put on theReindexQueue
.
- All Implemented Interfaces:
IndexableTypeAware
,SearchIndexMasterProcessLauncher
,Runnable
public abstract class GenericSearchIndexMasterProcessLauncher<T>
extends Object
implements SearchIndexMasterProcessLauncher, Runnable
This is an abstract component to allow for the full reindexing of a specific index. This
component only operates as a controller for a multi-threaded process. The purpose of this is to
obtain a process lock. It then runs a QueueLoader in another thread, which begins to populate a
Queue. It creates a Semaphore to block until all background threads are complete. It then raises
a process started event. Finally, it waits until the semaphore releases and completes the
process.
- Author:
- Kelly Tisdell (ktisdell)
-
Constructor Summary
ConstructorsConstructorDescriptionGenericSearchIndexMasterProcessLauncher
(ProcessStateService processStateService, LockService lockService, QueueProvider queueProvider, QueueLoader<T> batchIdReader, SemaphoreProvider semaphoreProvider, long completionPauseTime) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addStateHolderProperties
(ProcessStateHolder stateHolder) Adds properties set on thecontext
map to the ProcessStateHolder.protected void
destroyQueue
(ReindexQueue<T> queue) Attempts to destroy the queue.protected final void
Method in this class that does the heavy lifting.void
Method to forcibly stop a running index job.protected QueueLoader<T>
protected long
This is the time that the main control thread will pause on indexing process completion to allow other threads to finish what they are doing or catch up.long
Returns the elapsed time in millis, or -1 if the system is not running or if this is not the master instance.protected LockService
protected ProcessStateService
protected QueueProvider
protected SemaphoreProvider
instance
(com.broadleafcommerce.search.api.type.IndexableType type) Convenient way to access theSearchIndexMasterProcessLauncher
associated with a particular IndexableType.boolean
isActive()
Indicates if this process is currently executing.protected final void
pause()
Pause this thread for the determined completionPauseTime.protected long
process
(ReindexQueue<T> queue, ProcessStateHolder stateHolder) Method to populate theReindexQueue
with data.final void
Rebuilds an entire index.final void
rebuildIndex
(Map<String, Serializable> ctx) The default behavior here is check whether this process is already running, and if not, delegate to a background thread.static void
registerSearchIndexMasterProcessLauncher
(@NonNull SearchIndexMasterProcessLauncher launcher) This is a static method to register new SearchIndexMasterProcessLauncher objects.final void
run()
protected final void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.search.index.core.IndexableTypeAware
getIndexableType
-
Constructor Details
-
GenericSearchIndexMasterProcessLauncher
public GenericSearchIndexMasterProcessLauncher(ProcessStateService processStateService, LockService lockService, QueueProvider queueProvider, QueueLoader<T> batchIdReader, SemaphoreProvider semaphoreProvider, long completionPauseTime)
-
-
Method Details
-
instance
public static SearchIndexMasterProcessLauncher instance(com.broadleafcommerce.search.api.type.IndexableType type) Convenient way to access theSearchIndexMasterProcessLauncher
associated with a particular IndexableType. Returns null if none was registered for the specified type.- Parameters:
type
- the IndexableType for which to get the registered master launcher- Returns:
- the registered master launcher for the type, or null if none was registered
-
registerSearchIndexMasterProcessLauncher
public static void registerSearchIndexMasterProcessLauncher(@NonNull @NonNull SearchIndexMasterProcessLauncher launcher) This is a static method to register new SearchIndexMasterProcessLauncher objects. Note that you do not need to register your SearchIndexMasterProcessLauncher if it extends thisGenericSearchIndexMasterProcessLauncher
as the constructor registers the instance automatically.- Parameters:
launcher
- the master process launcher to register for itsIndexableType
-
rebuildIndex
public final void rebuildIndex() throws com.broadleafcommerce.search.api.SearchIndexExceptionDescription copied from interface:SearchIndexMasterProcessLauncher
Rebuilds an entire index. Index is typically Solr or ElasticSearch, but could be any type of search-able index. This is the entry point for rebuilding an index, and is often run in a background thread.- Specified by:
rebuildIndex
in interfaceSearchIndexMasterProcessLauncher
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs preventing indexing
-
rebuildIndex
public final void rebuildIndex(@Nullable Map<String, Serializable> ctx) throws com.broadleafcommerce.search.api.SearchIndexExceptionThe default behavior here is check whether this process is already running, and if not, delegate to a background thread.- Specified by:
rebuildIndex
in interfaceSearchIndexMasterProcessLauncher
- Parameters:
ctx
- arbitrary contextual information to be passed to the process launcher- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs preventing indexing
-
run
public final void run() -
isActive
public boolean isActive()Description copied from interface:SearchIndexMasterProcessLauncher
Indicates if this process is currently executing.- Specified by:
isActive
in interfaceSearchIndexMasterProcessLauncher
- Returns:
- whether this process is currently executing
-
getElapsedTime
public long getElapsedTime()Description copied from interface:SearchIndexMasterProcessLauncher
Returns the elapsed time in millis, or -1 if the system is not running or if this is not the master instance.- Specified by:
getElapsedTime
in interfaceSearchIndexMasterProcessLauncher
- Returns:
- the elapsed time in millis, or -1 if the system is not running or if this is not the master instance
-
forceStop
public void forceStop()Description copied from interface:SearchIndexMasterProcessLauncher
Method to forcibly stop a running index job. If the job is not running, this will have no affect.- Specified by:
forceStop
in interfaceSearchIndexMasterProcessLauncher
-
executeInternally
protected final void executeInternally()Method in this class that does the heavy lifting. However, for the most part, this delegates to the preProcess, process, and postProcess methods.This method is responsible for obtaining (and removing) necessary locks and for starting/ending the process state.
It is not recommended that you override this method. Instead, implement or override the preProcess, process, and postProcess methods.
-
destroyQueue
Attempts to destroy the queue. If failure occurs, an error is logged.- Parameters:
queue
- The queue to destroy.
-
addStateHolderProperties
Adds properties set on thecontext
map to the ProcessStateHolder. Any properties set on the context are subsequently cleared.- Parameters:
stateHolder
- The ProcessStateHolder to set properties on
-
process
protected long process(ReindexQueue<T> queue, ProcessStateHolder stateHolder) throws com.broadleafcommerce.search.api.SearchIndexException Method to populate theReindexQueue
with data. This should be a synchronous call (executing on the current thread) and should return the number of IDs (or records) that were put on the Queue for processing.- Parameters:
queue
- the queue to populatestateHolder
- the state holder tracking this process- Returns:
- the number of IDs that were read and put on the queue
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if the queue was unable to be populated
-
pause
protected final void pause()Pause this thread for the determined completionPauseTime. Allows other threads to complete their work if necessary. -
wrapUp
protected final void wrapUp(com.broadleafcommerce.search.api.type.IndexableType indexableType, Lock lock) -
getProcessStateService
-
getLockService
-
getQueueProvider
-
getBatchIdReader
-
getSemaphoreProvider
-
getCompletionPauseTime
protected long getCompletionPauseTime()This is the time that the main control thread will pause on indexing process completion to allow other threads to finish what they are doing or catch up.- Returns:
- time to wait on indexing completion for other threads finishing
-