Class AbstractWorker<T>

  • Type Parameters:
    T - The type that will be processed via the ReindexQueue.
    All Implemented Interfaces:
    IndexableTypeAware, Runnable

    public abstract class AbstractWorker<T>
    extends Object
    implements Runnable, IndexableTypeAware
    Represents an abstract Runnable object for data off of a ReindexQueue and processing the data. The data coming out of the Queue depends on what is putting data onto the queue. But typically the data coming off of the queue will be a paginated Collection of IDs or BatchIdHolders. This component would be responsible, in that case, for taking the IDs and querying for their full data, transforming and decorating that data, and finally writing that data, presumably to a search appliance.

    This is Runnable and will be executed in an Executor.

    Author:
    Kelly Tisdell (ktisdell)
    • Constructor Detail

      • AbstractWorker

        protected AbstractWorker​(@NonNull
                                 @NonNull ProcessStateService processStateService,
                                 @NonNull
                                 @NonNull Semaphore semaphore,
                                 @NonNull
                                 @NonNull com.broadleafcommerce.search.api.type.IndexableType type,
                                 @NonNull
                                 @NonNull ReindexQueue<T> queue,
                                 long waitTime,
                                 int maxTries)
    • Method Detail

      • getIndexableType

        public final com.broadleafcommerce.search.api.type.IndexableType getIndexableType()
        Description copied from interface: IndexableTypeAware
        Components that implement this method should return the same, non-null value on each invocation. This should basically return a constant value.
        Specified by:
        getIndexableType in interface IndexableTypeAware
        Returns:
        the associated indexable type
      • run

        public final void run()
        Specified by:
        run in interface Runnable
      • executeInternal

        protected abstract int executeInternal​(T queueEntry)
                                        throws com.broadleafcommerce.search.api.SearchIndexException
        Arbitrarily allows the processing of a queue entry. This is typically a BatchIdHolder or list of IDs, but it could also be an Indexable or a list of Indexables.

        Implementors of this method will typically take the data and process it. For example, if this is a list of IDs, the intent is that this Runnable is running in a background thread, one of many, and is reading additional data - e.g. Indexables based on ID -, transforming the Indexable to a SolrInputDocument or other search-able record, decorating that data will pricing and internationalization data, and then writing the final document to the index.

        It's very generic, and implementors can do anything they want here.

        This should return the number of Indexables processed since can be a list or holder of additional data.

        Parameters:
        queueEntry - the queue entry to process
        Returns:
        the number of Indexables processed
        Throws:
        com.broadleafcommerce.search.api.SearchIndexException - if an error occurs processing the items
      • getSemaphore

        protected Semaphore getSemaphore()
      • getType

        protected com.broadleafcommerce.search.api.type.IndexableType getType()
      • getWaitTime

        protected long getWaitTime()
        Time in milliseconds to wait for something to arrive in the Queue. Keep this rather small.
        Returns:
        time to wait for something to arrive in the queue
      • getMaxTries

        protected int getMaxTries()
        Defines the number of times that we'll try to retrieve something from a queue with the given wait time before giving up. Either nothing is putting data on the queue, or the cluster size is too big and we're just not receiving data because other threads are consuming the data fast enough that we never receive any.
        Returns:
        number of times to try to retrieve something from the queue