Class GenericSearchIndexMasterProcessLauncher<T>
- java.lang.Object
-
- com.broadleafcommerce.search.index.core.master.GenericSearchIndexMasterProcessLauncher<T>
-
- Type Parameters:
T- The type that will be read by theQueueLoaderand 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
Constructors Constructor Description GenericSearchIndexMasterProcessLauncher(ProcessStateService processStateService, LockService lockService, QueueProvider queueProvider, QueueLoader<T> batchIdReader, SemaphoreProvider semaphoreProvider, long completionPauseTime)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddStateHolderProperties(ProcessStateHolder stateHolder)Adds properties set on thecontextmap to the ProcessStateHolder.protected voiddestroyQueue(ReindexQueue<T> queue)Attempts to destroy the queue.protected voidexecuteInternally()Method in this class that does the heavy lifting.voidforceStop()Method to forcibly stop a running index job.protected QueueLoader<T>getBatchIdReader()protected longgetCompletionPauseTime()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.longgetElapsedTime()Returns the elapsed time in millis, or -1 if the system is not running or if this is not the master instance.protected LockServicegetLockService()protected ProcessStateServicegetProcessStateService()protected QueueProvidergetQueueProvider()protected SemaphoreProvidergetSemaphoreProvider()static SearchIndexMasterProcessLauncherinstance(com.broadleafcommerce.search.api.type.IndexableType type)Convenient way to access theSearchIndexMasterProcessLauncherassociated with a particular IndexableType.booleanisActive()Indicates if this process is currently executing.protected voidpause()Pause this thread for the determined completionPauseTime.protected longprocess(ReindexQueue<T> queue, ProcessStateHolder stateHolder)Method to populate theReindexQueuewith data.voidrebuildIndex()Rebuilds an entire index.voidrebuildIndex(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 voidregisterSearchIndexMasterProcessLauncher(@NonNull SearchIndexMasterProcessLauncher launcher)This is a static method to register new SearchIndexMasterProcessLauncher objects.voidrun()-
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 Detail
-
GenericSearchIndexMasterProcessLauncher
public GenericSearchIndexMasterProcessLauncher(ProcessStateService processStateService, LockService lockService, QueueProvider queueProvider, QueueLoader<T> batchIdReader, SemaphoreProvider semaphoreProvider, long completionPauseTime)
-
-
Method Detail
-
instance
public static SearchIndexMasterProcessLauncher instance(com.broadleafcommerce.search.api.type.IndexableType type)
Convenient way to access theSearchIndexMasterProcessLauncherassociated 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 thisGenericSearchIndexMasterProcessLauncheras 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:SearchIndexMasterProcessLauncherRebuilds 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:
rebuildIndexin 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:
rebuildIndexin 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
-
isActive
public boolean isActive()
Description copied from interface:SearchIndexMasterProcessLauncherIndicates if this process is currently executing.- Specified by:
isActivein interfaceSearchIndexMasterProcessLauncher- Returns:
- whether this process is currently executing
-
getElapsedTime
public long getElapsedTime()
Description copied from interface:SearchIndexMasterProcessLauncherReturns the elapsed time in millis, or -1 if the system is not running or if this is not the master instance.- Specified by:
getElapsedTimein 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:SearchIndexMasterProcessLauncherMethod to forcibly stop a running index job. If the job is not running, this will have no affect.- Specified by:
forceStopin 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
protected void destroyQueue(@Nullable ReindexQueue<T> queue)Attempts to destroy the queue. If failure occurs, an error is logged.- Parameters:
queue- The queue to destroy.
-
addStateHolderProperties
protected void addStateHolderProperties(ProcessStateHolder stateHolder)
Adds properties set on thecontextmap 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 theReindexQueuewith 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 void pause()
Pause this thread for the determined completionPauseTime. Allows other threads to complete their work if necessary.
-
getProcessStateService
protected ProcessStateService getProcessStateService()
-
getLockService
protected LockService getLockService()
-
getQueueProvider
protected QueueProvider getQueueProvider()
-
getBatchIdReader
protected QueueLoader<T> getBatchIdReader()
-
getSemaphoreProvider
protected SemaphoreProvider 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
-
-