Class AbstractCrawlEventHandlers
-
- All Implemented Interfaces:
-
ai.platon.pulsar.skeleton.event.CrawlEventHandlers
public abstract class AbstractCrawlEventHandlers implements CrawlEventHandlers
-
-
Field Summary
Fields Modifier and Type Field Description private final UrlAwareEventHandleronWillLoadprivate final UrlAwareWebPageEventHandleronLoaded
-
Constructor Summary
Constructors Constructor Description AbstractCrawlEventHandlers(UrlAwareEventHandler onWillLoad, UrlAwareWebPageEventHandler onLoaded)
-
Method Summary
Modifier and Type Method Description UrlAwareEventHandlergetOnWillLoad()Fires when the URL is about to be loaded in the Main loop. UrlAwareWebPageEventHandlergetOnLoaded()Fires when the URL has been loaded in the Main loop. CrawlEventHandlerschain(CrawlEventHandlers other)Chains another browser event handler to the tail of this one. -
-
Constructor Detail
-
AbstractCrawlEventHandlers
AbstractCrawlEventHandlers(UrlAwareEventHandler onWillLoad, UrlAwareWebPageEventHandler onLoaded)
- Parameters:
onLoaded- The URL that was processed
-
-
Method Detail
-
getOnWillLoad
UrlAwareEventHandler getOnWillLoad()
Fires when the URL is about to be loaded in the Main loop.
This is the first event in the page lifecycle. Use this handler to:
Filter URLs (return
nullto skip)Modify URL properties before loading
Log or track browser progress
(UrlAware) -> UrlAware?onWillLoad.addLast { url: UrlAware -> if (isBlacklisted(url.url)) null else url }- Returns:
The URL to continue processing, or
nullto skip this URL
-
getOnLoaded
UrlAwareWebPageEventHandler getOnLoaded()
Fires when the URL has been loaded in the Main loop.
This is the last event in the page lifecycle. Use this handler to:
Process loaded page content
Handle load failures (page will be
null)Collect statistics or metrics
(UrlAware, WebPage?) -> Any?onLoaded.addLast { url, page -> if (page != null) { saveToDatabase(page) } else { logFailure(url) } }
-
chain
CrawlEventHandlers chain(CrawlEventHandlers other)
Chains another browser event handler to the tail of this one.
Chained handlers execute in order: this handler's callbacks run first, then the other handler's callbacks.
- Parameters:
other- The browser event handlers to chain- Returns:
This handler instance for fluent chaining
-
-
-
-