Class ReindexJobEventListener
- java.lang.Object
-
- com.broadleafcommerce.search.index.reindex.event.listener.ReindexJobEventListener
-
public class ReindexJobEventListener extends Object
Listens for events fired by an in-progress reindex and updates the reindex job in real time.This implementation only updates the job status on the master node. The listeners in this class generally execute with the lowest precedence so any necessary processing can be done before the job is updated in the DB.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
UNKNOWN_ERROR
-
Constructor Summary
Constructors Constructor Description ReindexJobEventListener(com.broadleafcommerce.search.index.core.ProcessStateService processStateService, com.broadleafcommerce.search.index.core.service.ReindexJobService<com.broadleafcommerce.search.index.core.domain.ReindexJob> reindexJobService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createReindexJob(com.broadleafcommerce.search.index.core.event.ProcessStartedEvent event)
Creates and persists a new ReindexJob.protected void
finalizeJobStatus(com.broadleafcommerce.search.index.core.event.ProcessCompletedEvent event)
Called upon job completion.protected com.broadleafcommerce.search.index.core.ProcessStateHolder
getProcessStateHolder(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
protected com.broadleafcommerce.search.index.core.ProcessStateService
getProcessStateService()
protected com.broadleafcommerce.search.index.core.service.ReindexJobService<com.broadleafcommerce.search.index.core.domain.ReindexJob>
getReindexJobService()
void
handleBatchCompleted(com.broadleafcommerce.search.index.core.event.BatchCompletedEvent event)
Updates job statistics on the completion of each batch.void
handleProcessCompleted(com.broadleafcommerce.search.index.core.event.ProcessCompletedEvent event)
Marks a job as completed.void
handleProcessStartedEvent(com.broadleafcommerce.search.index.core.event.ProcessStartedEvent event)
Initializes the reindex job and persists to data store.void
handleProcessSuccess(com.broadleafcommerce.search.index.core.event.ProcessSuccessEvent event)
Updates the job's status to success.void
handleQueueLoaded(com.broadleafcommerce.search.index.core.event.QueueLoadedEvent event)
Updates the job's expected number of items to process.protected boolean
isMasterNode(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
Is this the master node?protected com.broadleafcommerce.search.index.core.domain.ReindexJob
readJob(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
protected com.broadleafcommerce.search.index.core.domain.ReindexJob
saveJob(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob)
protected void
updateBatchCompleted(com.broadleafcommerce.search.index.core.event.BatchCompletedEvent event)
Updates the number of items processed during reindexing.protected void
updateJobFailure(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob, com.broadleafcommerce.search.index.core.ProcessStateHolder.ProcessFailure processFailure)
When a failure occurs, adds the failure to the reindex job for further investigation.protected com.broadleafcommerce.search.index.core.domain.ReindexJob
updateJobStats(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob, com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
Updates common statistics on the ReindexJob, such as processed count, last updated, node, and thread count.protected void
updateJobSuccess(com.broadleafcommerce.search.index.core.event.ProcessSuccessEvent event)
Sets the job status toReindexStatus.SUCCESS
andReindexJob.finishedProcessingQueueTime
to the current time.protected void
updateWithExpectedProcessCount(com.broadleafcommerce.search.index.core.event.QueueLoadedEvent event)
-
-
-
Field Detail
-
UNKNOWN_ERROR
protected static final String UNKNOWN_ERROR
- See Also:
- Constant Field Values
-
-
Method Detail
-
handleProcessStartedEvent
@EventListener @Order public void handleProcessStartedEvent(com.broadleafcommerce.search.index.core.event.ProcessStartedEvent event)
Initializes the reindex job and persists to data store.- Parameters:
event
- A ProcessStartedEVent
-
handleProcessCompleted
@EventListener @Order(0) public void handleProcessCompleted(com.broadleafcommerce.search.index.core.event.ProcessCompletedEvent event)
Marks a job as completed. This should execute before, theProcessCompleteEventListener
as that listener ends the Reindex process and the data is no longer available.- Parameters:
event
- A ProcessCompletedEvent
-
handleBatchCompleted
@EventListener @Order public void handleBatchCompleted(com.broadleafcommerce.search.index.core.event.BatchCompletedEvent event)
Updates job statistics on the completion of each batch.- Parameters:
event
- A BatchCompletedEvent
-
handleProcessSuccess
@EventListener @Order public void handleProcessSuccess(com.broadleafcommerce.search.index.core.event.ProcessSuccessEvent event)
Updates the job's status to success.- Parameters:
event
- A ProcessSuccessEvent
-
handleQueueLoaded
@EventListener @Order public void handleQueueLoaded(com.broadleafcommerce.search.index.core.event.QueueLoadedEvent event)
Updates the job's expected number of items to process.- Parameters:
event
- A QueueLoadedEvent
-
updateWithExpectedProcessCount
protected void updateWithExpectedProcessCount(com.broadleafcommerce.search.index.core.event.QueueLoadedEvent event)
-
updateJobSuccess
protected void updateJobSuccess(com.broadleafcommerce.search.index.core.event.ProcessSuccessEvent event)
Sets the job status toReindexStatus.SUCCESS
andReindexJob.finishedProcessingQueueTime
to the current time.- Parameters:
event
- TheProcessSuccessEvent
-
updateBatchCompleted
protected void updateBatchCompleted(com.broadleafcommerce.search.index.core.event.BatchCompletedEvent event)
Updates the number of items processed during reindexing.- Parameters:
event
- A batch completed event.
-
updateJobFailure
protected void updateJobFailure(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob, com.broadleafcommerce.search.index.core.ProcessStateHolder.ProcessFailure processFailure)
When a failure occurs, adds the failure to the reindex job for further investigation.- Parameters:
reindexJob
- The reindex job.processFailure
- The failure that occurred.
-
finalizeJobStatus
protected void finalizeJobStatus(com.broadleafcommerce.search.index.core.event.ProcessCompletedEvent event)
Called upon job completion. This is called regardless of job success or failure.- Parameters:
event
- TheProcessCompletedEvent
-
createReindexJob
protected void createReindexJob(com.broadleafcommerce.search.index.core.event.ProcessStartedEvent event)
Creates and persists a new ReindexJob. This includes various- Parameters:
event
- TheProcessStartedEvent
-
readJob
protected com.broadleafcommerce.search.index.core.domain.ReindexJob readJob(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
-
getProcessStateHolder
protected com.broadleafcommerce.search.index.core.ProcessStateHolder getProcessStateHolder(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
-
updateJobStats
protected com.broadleafcommerce.search.index.core.domain.ReindexJob updateJobStats(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob, com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
Updates common statistics on the ReindexJob, such as processed count, last updated, node, and thread count.- Parameters:
reindexJob
-event
-- Returns:
-
isMasterNode
protected boolean isMasterNode(com.broadleafcommerce.search.index.core.event.SearchIndexProcessEvent event)
Is this the master node?- Parameters:
event
- A Process Event- Returns:
- true if master node, else false.
-
saveJob
protected com.broadleafcommerce.search.index.core.domain.ReindexJob saveJob(com.broadleafcommerce.search.index.core.domain.ReindexJob reindexJob)
-
getProcessStateService
protected com.broadleafcommerce.search.index.core.ProcessStateService getProcessStateService()
-
getReindexJobService
protected com.broadleafcommerce.search.index.core.service.ReindexJobService<com.broadleafcommerce.search.index.core.domain.ReindexJob> getReindexJobService()
-
-