Interface ProcessStateService

  • All Superinterfaces:
    Distributable, EventPublisher
    All Known Implementing Classes:
    AbstractProcessStateService, DefaultProcessStateService

    public interface ProcessStateService
    extends EventPublisher
    Component to track the state of a given reindex process. More than one reindex can happen at the same time, assuming that the indexes are unique. In other words, you can reindex products and customers simultaneously as long as they are in separate indexes.
    Author:
    Kelly Tisdell (ktisdell)
    • Method Summary

      All Methods Instance Methods Abstract 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.
      int getClusterMemberCount​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
      Returns the number of cluster members that may be working together to process data.
      String getCorrelationId​(com.broadleafcommerce.search.api.type.IndexableType type)
      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.
      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.
    • Method Detail

      • startProcessState

        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. 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.

        Parameters:
        indexableType - the indexable type for which to start the process state
        master - whether this process state is the master
        Returns:
        the started process state holder
      • endProcessState

        void endProcessState​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
        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.
        Parameters:
        indexableType - the indexable type for which to end the process state
      • isProcessStateEnabled

        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.
        Parameters:
        indexableType - the indexable type for which to check the process state
      • failFast

        void failFast​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
        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.
        Parameters:
        indexableType - the indexable type for which to report a failure
      • failFast

        void failFast​(com.broadleafcommerce.search.api.type.IndexableType indexableType,
                      @Nullable
                      Throwable th)
        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.
        Parameters:
        indexableType - the indexable type for which to report a failure
        th - the error which failed the process
      • isFailed

        boolean isFailed​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
        Indicates if the process has been notified as failing by one or more threads.
        Parameters:
        indexableType - the indexable type to check
        Returns:
        whether the process is failed for the indexable type
      • isMaster

        boolean isMaster​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
        Indicates if this JVM kicked off the process for this IndexableType.
        Parameters:
        indexableType - the indexable type to check
        Returns:
        whether the process is the master
      • getClusterMemberCount

        int getClusterMemberCount​(com.broadleafcommerce.search.api.type.IndexableType indexableType)
        Returns the number of cluster members that may be working together to process data. If Distributable.isDistributed() is false, then this should ALWAYS return 1.
        Parameters:
        indexableType - the indexable type for which to get the cluster member count
        Returns:
        the number of cluster members that may be working together to process data
      • getCurrentProcessStateHolder

        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.
        Parameters:
        indexableType - the indexable type for which to get the process state
        Returns:
        if present, the process state for the indexable type
      • getCorrelationId

        @Nullable
        String getCorrelationId​(com.broadleafcommerce.search.api.type.IndexableType type)
        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.
        Parameters:
        type - 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