Class AbstractProcessStateService
- java.lang.Object
-
- com.broadleafcommerce.search.index.core.AbstractProcessStateService
-
- All Implemented Interfaces:
Distributable
,EventPublisher
,ProcessStateService
- Direct Known Subclasses:
DefaultProcessStateService
public abstract class AbstractProcessStateService extends Object implements ProcessStateService
Mechanism to safely access or update process state across threads within a single JVM.- Author:
- Kelly Tisdell (ktisdell)
-
-
Constructor Summary
Constructors Constructor Description AbstractProcessStateService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
endProcessState(com.broadleafcommerce.search.api.type.IndexableType indexableType)
End's a process for a given IndexableType.void
failFast(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Notifies that the process has failed and does not require a Throwable to be provided.void
failFast(com.broadleafcommerce.search.api.type.IndexableType indexableType, Throwable th)
Notifies that the process has failed and keeps track of the Throwables passed in.String
getCorrelationId(com.broadleafcommerce.search.api.type.IndexableType indexableType)
This returns the unique correlation.Optional<ProcessStateHolder>
getCurrentProcessStateHolder(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Method to retrieve the current ProcessStateHolder for the currently executing process of reindexing a particular IndexableType.protected ProcessStateHolder
getInstance(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Get the process state holder for the given indexable type.boolean
isFailed(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Indicates if the process has been notified as failing by one or more threads.boolean
isMaster(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Indicates if this JVM kicked off the process for this IndexableType.boolean
isProcessStateEnabled(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Indicates if any thread has started a process state associated with this IndexableType, and not stopped it.ProcessStateHolder
startProcessState(com.broadleafcommerce.search.api.type.IndexableType indexableType, boolean master)
Initiates an instance of ReindexStateHolder that will be used across multiple threads, typically for full reindexing.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.search.index.core.Distributable
isDistributed
-
Methods inherited from interface com.broadleafcommerce.search.index.core.EventPublisher
publishEvent
-
Methods inherited from interface com.broadleafcommerce.search.index.core.ProcessStateService
getClusterMemberCount
-
-
-
-
Method Detail
-
startProcessState
public ProcessStateHolder startProcessState(com.broadleafcommerce.search.api.type.IndexableType indexableType, boolean master)
Description copied from interface:ProcessStateService
Initiates an instance of ReindexStateHolder that will be used across multiple threads, typically for full reindexing. The IndexableType allows for multiple reindexing to happen at the same time (e.g. catalog and customer).One approach is to use an enumeration value to start the process state for the reindexing of a particular entity. For example, you might use
org.broadleafcommerce.search.api.type.IndexableType.PRODUCT
to create a global ReindexStateHolder for reindexing a particular type of entity. For individual processes that may be reindexing individual documents, you might choose to use a unique ID, such as a UUID.You must use the same IndexableType to call endProcessState.
- Specified by:
startProcessState
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to start the process statemaster
- whether this process state is the master- Returns:
- the started process state holder
-
endProcessState
public void endProcessState(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
End's a process for a given IndexableType. This MUST be called, typically in a finally block of a control thread after a full re-index has been completed.- Specified by:
endProcessState
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to end the process state
-
isProcessStateEnabled
public boolean isProcessStateEnabled(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
Indicates if any thread has started a process state associated with this IndexableType, and not stopped it.- Specified by:
isProcessStateEnabled
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to check the process state
-
failFast
public void failFast(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
Notifies that the process has failed and does not require a Throwable to be provided. This allows other threads to monitor this state and fail the entire process fast if another thread reported a failure.- Specified by:
failFast
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to report a failure
-
failFast
public void failFast(com.broadleafcommerce.search.api.type.IndexableType indexableType, @Nullable Throwable th)
Description copied from interface:ProcessStateService
Notifies that the process has failed and keeps track of the Throwables passed in. This allows other threads to monitor this state and fail the entire process fast if other thread reported a failure.- Specified by:
failFast
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to report a failureth
- the error which failed the process
-
isFailed
public boolean isFailed(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
Indicates if the process has been notified as failing by one or more threads.- Specified by:
isFailed
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type to check- Returns:
- whether the process is failed for the indexable type
-
isMaster
public boolean isMaster(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
Indicates if this JVM kicked off the process for this IndexableType.- Specified by:
isMaster
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type to check- Returns:
- whether the process is the master
-
getCurrentProcessStateHolder
public Optional<ProcessStateHolder> getCurrentProcessStateHolder(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
Method to retrieve the current ProcessStateHolder for the currently executing process of reindexing a particular IndexableType.- Specified by:
getCurrentProcessStateHolder
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to get the process state- Returns:
- if present, the process state for the indexable type
-
getCorrelationId
@Nullable public String getCorrelationId(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Description copied from interface:ProcessStateService
This returns the unique correlation. Correlation ID is unique to a node and an indexable type within a single reindex process. New processes should generate new correlationIds. But within a given process on a given node, the correlationId should be the same for a given IndexableType.- Specified by:
getCorrelationId
in interfaceProcessStateService
- Parameters:
indexableType
- the indexable type for which to get the process correlation ID- Returns:
- the process correlation ID for the indexable type, or null if there is none
-
getInstance
protected final ProcessStateHolder getInstance(com.broadleafcommerce.search.api.type.IndexableType indexableType)
Get the process state holder for the given indexable type.- Parameters:
indexableType
- the indexable type to get the state holder for- Returns:
- the process state holder for the indexable type
-
-