Class AbstractBatchIdQueueLoader<ID extends Serializable,T extends BatchIdHolder<ID>>
java.lang.Object
com.broadleafcommerce.search.index.core.queue.AbstractQueueLoader<ID,T>
com.broadleafcommerce.search.index.core.queue.AbstractBatchIdQueueLoader<ID,T>
- Type Parameters:
ID
- This is the type of IDs that are being read from a data source in batchT
- This is the type that will be added to theReindexQueue
. It's an instance ofBatchIdHolder
.
- All Implemented Interfaces:
IndexableTypeAware
,QueueLoader<T>
public abstract class AbstractBatchIdQueueLoader<ID extends Serializable,T extends BatchIdHolder<ID>>
extends AbstractQueueLoader<ID,T>
Abstract component to handle reading ID ranges from a source and populating a Queue for further
retrieval. Instances are expected to be singletons.
- Author:
- Kelly Tisdell (ktisdell)
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractBatchIdQueueLoader
(@NonNull com.broadleafcommerce.search.api.type.IndexableType indexableType, long waitTime, int maxTries, int batchReadSize, int chunkSize) -
Method Summary
Modifier and TypeMethodDescriptionprotected final int
countIndexablesToProcess
(List<T> queueEntries) Determine how manyIndexable
s are being processed.final com.broadleafcommerce.search.api.type.IndexableType
Components that implement this method should return the same, non-null value on each invocation.protected final void
This will be called exactly once prior to a call to readPage.readPage()
readPage
(ProcessStateHolder processStateHolder) Reads paged data to, optionally, transform and put on aBlockingQueue
.readPagedIds
(ID startId, int batchSize) Reads pages of IDs.readPagedIds
(ID startId, int batchSize, Map<String, Object> additionalProperties) Reads pages of IDs.Breaks the provided list of IDs into chunks of appropriate size.Methods inherited from class com.broadleafcommerce.search.index.core.queue.AbstractQueueLoader
createExecutor, destroyExecutor, getMaxTries, getWaitTime, isRunning, populateQueue
-
Constructor Details
-
AbstractBatchIdQueueLoader
public AbstractBatchIdQueueLoader(@NonNull @NonNull com.broadleafcommerce.search.api.type.IndexableType indexableType, long waitTime, int maxTries, int batchReadSize, int chunkSize)
-
-
Method Details
-
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.- Returns:
- the associated indexable type
-
initialize
protected final void initialize()Description copied from class:AbstractQueueLoader
This will be called exactly once prior to a call to readPage. This method may do nothing, but implementors may use it to reset state such as a cursor. This method should set the state of this object so that the next call to readNextIds will begin reading batches of IDs at the beginning of the list.- Specified by:
initialize
in classAbstractQueueLoader<ID extends Serializable,
T extends BatchIdHolder<ID>>
-
readPage
- Specified by:
readPage
in classAbstractQueueLoader<ID extends Serializable,
T extends BatchIdHolder<ID>> - Throws:
com.broadleafcommerce.search.api.SearchIndexException
-
readPage
protected final List<ID> readPage(ProcessStateHolder processStateHolder) throws com.broadleafcommerce.search.api.SearchIndexException Description copied from class:AbstractQueueLoader
Reads paged data to, optionally, transform and put on aBlockingQueue
. This could be a list of IDs,Indexable
objects, or any number of things.Implementors MUST return an empty list when there is no more data to return. Implementors must also keep track of their own pagination state. The initialize method will be called prior to the first call to this method.
The results of this call will be passed to the transform method and then put on a queue for more intensive processing, transformation, persistence, etc.
Most typically, this will read a rather large List of IDs. Additionally this sends process state information for potential filters.
- Specified by:
readPage
in classAbstractQueueLoader<ID extends Serializable,
T extends BatchIdHolder<ID>> - Parameters:
processStateHolder
- the state holder process information for the index thread- Returns:
- a paged list of FROM items
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs reading paged data
-
readPagedIds
protected abstract List<ID> readPagedIds(@Nullable ID startId, int batchSize) throws com.broadleafcommerce.search.api.SearchIndexException Reads pages of IDs. The startId parameter begins empty. The batchSize parameter will be the same value each time. The startId parameter will be updated to the last read ID on each additional invocation.- Parameters:
startId
- (optional) the last ID of the previous page, or null if first pagebatchSize
- the size of the page to read- Returns:
- page of IDs read past the startId
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs while reading IDs
-
readPagedIds
protected abstract List<ID> readPagedIds(@Nullable ID startId, int batchSize, @Nullable Map<String, Object> additionalProperties) throws com.broadleafcommerce.search.api.SearchIndexExceptionReads pages of IDs. The startId parameter begins empty. The batchSize parameter will be the same value each time. The startId parameter will be updated to the last read ID on each additional invocation. Contains additional parameters to allow filtering of the indexed items.- Parameters:
startId
- (optional) the last ID of the previous page, or null if first pagebatchSize
- the size of the page to readadditionalProperties
- additional information that can be used to filter the items to be indexed- Returns:
- page of IDs read past the startId
- Throws:
com.broadleafcommerce.search.api.SearchIndexException
- if an error occurs while reading IDs
-
transform
Breaks the provided list of IDs into chunks of appropriate size.- Specified by:
transform
in classAbstractQueueLoader<ID extends Serializable,
T extends BatchIdHolder<ID>> - Parameters:
from
- a non-chunked list of IDs- Returns:
- IDs split into
BatchIdHolder
chunks
-
countIndexablesToProcess
Description copied from class:AbstractQueueLoader
Determine how manyIndexable
s are being processed. Since(queueEntry) is generic and could be a Collection
, aBatchIdHolder
, or some other type, we provide this method so that implementors can return a count of theIndexable
items that are expected to be processed by anAbstractWorker
at the other end of the Queue.Return 0 if there is no way to know the number of indexables (e.g. if the queueEntry is an ID range).
- Specified by:
countIndexablesToProcess
in classAbstractQueueLoader<ID extends Serializable,
T extends BatchIdHolder<ID>> - Parameters:
queueEntries
- the entries on the queue for which to count expected indexables- Returns:
- the number of expected indexables to index for the queueEntries
-