Class GenericSearchIndexMasterProcessLauncher<T>

java.lang.Object
com.broadleafcommerce.search.index.core.master.GenericSearchIndexMasterProcessLauncher<T>
Type Parameters:
T - The type that will be read by the QueueLoader and put on the ReindexQueue.
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 Details

  • Method Details

    • instance

      public static SearchIndexMasterProcessLauncher instance(com.broadleafcommerce.search.api.type.IndexableType type)
      Convenient way to access the SearchIndexMasterProcessLauncher 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 this GenericSearchIndexMasterProcessLauncher as the constructor registers the instance automatically.
      Parameters:
      launcher - the master process launcher to register for its IndexableType
    • rebuildIndex

      public final void rebuildIndex() throws com.broadleafcommerce.search.api.SearchIndexException
      Description 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 interface SearchIndexMasterProcessLauncher
      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.SearchIndexException
      The default behavior here is check whether this process is already running, and if not, delegate to a background thread.
      Specified by:
      rebuildIndex in interface SearchIndexMasterProcessLauncher
      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()
      Specified by:
      run in interface Runnable
    • isActive

      public boolean isActive()
      Description copied from interface: SearchIndexMasterProcessLauncher
      Indicates if this process is currently executing.
      Specified by:
      isActive in interface SearchIndexMasterProcessLauncher
      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 interface SearchIndexMasterProcessLauncher
      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 interface SearchIndexMasterProcessLauncher
    • 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 the context 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 the ReindexQueue 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 populate
      stateHolder - 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

      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