Class CrawlerStateStore

java.lang.Object
com.norconex.crawler.core.session.CrawlerStateStore

public class CrawlerStateStore extends Object
Manages persistent crawl-state and session-scoped attributes stored in the distributed session cache. Can be injected directly in tests without the full CrawlerSession.
  • Constructor Details

    • CrawlerStateStore

      public CrawlerStateStore(CacheMap<String> sessionCache, CrawlerAttributes sessionAttributes, CrawlerAttributes runAttributes)
      Creates a new CrawlerStateStore instance.
      Parameters:
      sessionCache -
      sessionAttributes -
      runAttributes - Ephemeral (non-MapStore-backed) attributes for per-run flags that must survive partition migration after a node crash. Backed by the eph-crawlRun cache so that in-memory backup promotion is used directly without triggering a LAZY MapStore reload.
  • Method Details

    • loadState

      public CrawlerSession.State loadState()
      Loads the current crawl state directly from the distributed cache.
      Returns:
      the current state, or null if none has been saved yet
    • updateCrawlState

      public void updateCrawlState(CrawlerState state)
      Updates the crawl state in the distributed cache with a new timestamp.
      Parameters:
      state - the new crawl state
    • getCrawlState

      public CrawlerState getCrawlState()
      Returns the current crawl state, reading fresh from the distributed cache each call.
      Returns:
      the current crawl state, or null
    • isStartRefsQueueingComplete

      public boolean isStartRefsQueueingComplete()
      Returns whether start-reference queuing has completed.
      Returns:
      true when all start references have been queued
    • setStartRefsQueueingComplete

      public void setStartRefsQueueingComplete(boolean isComplete)
      Marks whether start-reference queuing has completed.
      Parameters:
      isComplete - true once all start references are queued
    • isStartRefsAllQueued

      public boolean isStartRefsAllQueued()
      Returns whether all start references of this crawl session were queued, by this run or a previous one. Unlike isStartRefsQueueingComplete(), it persists across runs, so a resumed crawl knows whether queueing was left unfinished.
      Returns:
      true once every start reference was queued
    • setStartRefsAllQueued

      public void setStartRefsAllQueued(boolean allQueued)
      Marks whether all start references of this crawl session were queued.
      Parameters:
      allQueued - true once every start reference was queued
    • getStartRefsQueueingNode

      public Optional<String> getStartRefsQueueingNode()
      Returns the name of the node queueing start references in this run.
      Returns:
      node name, or empty if queueing has not started
    • setStartRefsQueueingNode

      public void setStartRefsQueueingNode(String nodeName)
      Records the name of the node queueing start references in this run.
      Parameters:
      nodeName - node name
    • getSessionAttributes

      public CrawlerAttributes getSessionAttributes()
      Returns the session-scoped attribute store backed by the session cache.
      Returns:
      session attributes