Class CrawlerSession
java.lang.Object
com.norconex.crawler.core.session.CrawlerSession
- All Implemented Interfaces:
Closeable,AutoCloseable
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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidShortcut method for firing an event equivalent to:session.getCrawlContext().getEventManager().fire(event).voidShortcut method for firing aCrawlerEventwith the supplied source and with thecrawlSessionfield already set.intThe crawler unique identifier, for a specific crawler setup and does not change across sessions.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.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.Fires events through the underlying event manager.Coordinates task deduplication across session and run scopes.Manages persistent crawl state and session-scoped attributes.booleanisClosed()booleanbooleanbooleanWhether all start references of this crawl session were queued, by this run or a previous one.booleanbooleanWhether the node queueing start references in this run is still part of the cluster.booleanWhether a stop was requested on this node.voidRecords this node as the one queueing start references in this run.voidMarks this session as stopping.voidoncePerRun(String taskId, Runnable runnable) <T> ToncePerRunAndGet(String taskId, Supplier<T> supplier) voidoncePerSession(String taskId, Runnable runnable) <T> ToncePerSessionAndGet(String taskId, Supplier<T> supplier) voidWorks 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.voidsetPostCloseCleanup(Runnable cleanup) Registers a cleanup action to run AFTER the session has closed all its resources.voidsetStartRefsAllQueued(boolean allQueued) voidsetStartRefsQueueingComplete(boolean isComplete) toString()voidupdateCrawlState(CrawlerState state)
-
Method Details
-
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
-
oncePerSessionAndGet
-
oncePerRun
-
oncePerRunAndGet
-
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
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 -cleandoes, 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
-
isClosed
public boolean isClosed() -
getSessionAttributes
-
getCrawlRunAttributes
-
getCrawlerAttributes
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
setPostCloseCleanup
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:
trueonce a stop was requested
-
markStopRequested
public void markStopRequested()Marks this session as stopping. Called when a node stops (seeCluster.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:
trueonce 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:
trueif the queueing node is alive
-
updateCrawlState
-
fire
Shortcut method for firing an event equivalent to:session.getCrawlContext().getEventManager().fire(event).- Parameters:
event- the event to fire
-
fire
Shortcut method for firing aCrawlerEventwith the supplied source and with thecrawlSessionfield already set. Equivalent to:session.getCrawlContext().getEventManager().fire(crawlerEvent).- Parameters:
eventName- name of the event to firesource- the event source
-
loadState
-
toString
-
getCluster
-
getCrawlContext
-
getRunCoordinator
Coordinates task deduplication across session and run scopes. -
getStateStore
Manages persistent crawl state and session-scoped attributes. -
getEventBus
Fires events through the underlying event manager.
-