Class AbstractWorker<T>
- java.lang.Object
-
- com.broadleafcommerce.search.index.core.worker.AbstractWorker<T>
-
- Type Parameters:
T
- The type that will be processed via theReindexQueue
.
- All Implemented Interfaces:
IndexableTypeAware
,Runnable
public abstract class AbstractWorker<T> extends Object implements Runnable, IndexableTypeAware
Represents an abstractRunnable
object for data off of aReindexQueue
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 paginatedCollection
of IDs orBatchIdHolder
s. 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.- Author:
- Kelly Tisdell (ktisdell)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractWorker(@NonNull ProcessStateService processStateService, @NonNull Semaphore semaphore, @NonNull com.broadleafcommerce.search.api.type.IndexableType type, @NonNull ReindexQueue<T> queue, long waitTime, int maxTries)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
executeInternal(T queueEntry)
Arbitrarily allows the processing of a queue entry.com.broadleafcommerce.search.api.type.IndexableType
getIndexableType()
Components that implement this method should return the same, non-null value on each invocation.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.protected ProcessStateService
getProcessStateService()
protected ReindexQueue<T>
getQueue()
protected Semaphore
getSemaphore()
protected com.broadleafcommerce.search.api.type.IndexableType
getType()
protected long
getWaitTime()
Time in milliseconds to wait for something to arrive in the Queue.void
run()
-
-
-
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 interfaceIndexableTypeAware
- Returns:
- the associated indexable type
-
executeInternal
protected abstract int executeInternal(T queueEntry) throws com.broadleafcommerce.search.api.SearchIndexException
Arbitrarily allows the processing of a queue entry. This is typically aBatchIdHolder
or list of IDs, but it could also be anIndexable
or a list ofIndexable
s.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.Indexable
s based on ID -, transforming theIndexable
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()
-
getQueue
protected ReindexQueue<T> getQueue()
-
getProcessStateService
protected ProcessStateService getProcessStateService()
-
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
-
-