Class CrawlerSession

java.lang.Object
com.norconex.crawler.core.session.CrawlerSession
All Implemented Interfaces:
Closeable, AutoCloseable

public class CrawlerSession extends Object implements Closeable
A crawl session, representing a crawl from begin to finish, which may include zero to multiple "resumes" from stops, or failures. There is one crawl session per cluster, each node having their own instance of this class, exposing the same information.
  • Method Details

    • getCrawlerId

      public String getCrawlerId()
      The crawler unique identifier, for a specific crawler setup and does not change across sessions. Same as configured in the crawler configuration.
      Returns:
      crawler id
    • oncePerSession

      public void oncePerSession(String taskId, Runnable runnable)
    • oncePerSessionAndGet

      public <T> T oncePerSessionAndGet(String taskId, Supplier<T> supplier)
    • oncePerRun

      public void oncePerRun(String taskId, Runnable runnable)
    • oncePerRunAndGet

      public <T> T oncePerRunAndGet(String taskId, Supplier<T> supplier)
    • getCrawlSessionId

      public String getCrawlSessionId()
      A crawl session unique identifier, which represents a begin-to-end crawl, regardless how many times it may have been resumed due to stops or failures. Resuming crawls will keep the same session id.
      Returns:
      crawl session id
    • getCrawlRunId

      public String getCrawlRunId()
      A crawl run unique identifier, which is renewed every time the crawler is launched, regardless whether we are resuming an existing session or creating a new one.
      Returns:
      crawl run id
    • isIncremental

      public boolean isIncremental()
    • resolveRunInfoAfterClean

      public void resolveRunInfoAfterClean()
      Works out again what this run is (the crawl session it belongs to, whether it resumes one, its mode and how many documents it may process) after the stored history was cleared by a clean command that ran in this same session.

      All of that is worked out once, when the session opens, from what is stored. A clean erases what it was worked out from, so a crawl that follows it in the same session, as start -clean does, would otherwise still believe it was resuming: it would skip its start references and be allowed extra documents for what was cleared.

    • isResumed

      public boolean isResumed()
    • getCrawlState

      public CrawlerState getCrawlState()
    • isClosed

      public boolean isClosed()
    • getSessionAttributes

      public CrawlerAttributes getSessionAttributes()
    • getCrawlRunAttributes

      public CrawlerAttributes getCrawlRunAttributes()
    • getCrawlerAttributes

      public CrawlerAttributes getCrawlerAttributes()
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • setPostCloseCleanup

      public void setPostCloseCleanup(Runnable cleanup)
      Registers a cleanup action to run AFTER the session has closed all its resources. This is useful for components like loggers that need to capture all session cleanup events before shutting down.
      Parameters:
      cleanup - the cleanup action to run after session close
    • getAdminPort

      public int getAdminPort()
    • isStopRequested

      public boolean isStopRequested()
      Whether a stop was requested on this node. Long-running work outside the crawl pipeline steps (e.g., queueing start references in the background) checks it to end early.
      Returns:
      true once a stop was requested
    • markStopRequested

      public void markStopRequested()
      Marks this session as stopping. Called when a node stops (see Cluster.stopLocally()).
    • isStartRefsQueueingComplete

      public boolean isStartRefsQueueingComplete()
    • setStartRefsQueueingComplete

      public void setStartRefsQueueingComplete(boolean isComplete)
    • isStartRefsAllQueued

      public boolean isStartRefsAllQueued()
      Whether all start references of this crawl session were queued, by this run or a previous one.
      Returns:
      true once every start reference was queued
    • setStartRefsAllQueued

      public void setStartRefsAllQueued(boolean allQueued)
    • markStartRefsQueueingNode

      public void markStartRefsQueueingNode()
      Records this node as the one queueing start references in this run.
    • isStartRefsQueueingNodeAlive

      public boolean isStartRefsQueueingNodeAlive()
      Whether the node queueing start references in this run is still part of the cluster. When it is not (e.g., it crashed), nobody will finish the queueing in this run.
      Returns:
      true if the queueing node is alive
    • updateCrawlState

      public void updateCrawlState(CrawlerState state)
    • fire

      public void fire(Event event)
      Shortcut method for firing an event equivalent to: session.getCrawlContext().getEventManager().fire(event).
      Parameters:
      event - the event to fire
    • fire

      public void fire(String eventName, Object source)
      Shortcut method for firing a CrawlerEvent with the supplied source and with the crawlSession field already set. Equivalent to: session.getCrawlContext().getEventManager().fire(crawlerEvent) .
      Parameters:
      eventName - name of the event to fire
      source - the event source
    • loadState

      public CrawlerSession.State loadState()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCluster

      public Cluster getCluster()
    • getCrawlContext

      public CrawlerContext getCrawlContext()
    • getRunCoordinator

      public CrawlerRunCoordinator getRunCoordinator()
      Coordinates task deduplication across session and run scopes.
    • getStateStore

      public CrawlerStateStore getStateStore()
      Manages persistent crawl state and session-scoped attributes.
    • getEventBus

      public CrawlerEventBus getEventBus()
      Fires events through the underlying event manager.