Package ai.platon.pulsar.skeleton.crawl
Interface ServerSideEventHandlers
-
- All Implemented Interfaces:
public interface ServerSideEventHandlersServer-side event handlers for capturing and broadcasting events during the page lifecycle.
This interface defines methods for receiving events from various phases (crawl, load, browse) and forwarding them to subscribed listeners through a reactive stream.
Events can be emitted at any point during the page processing lifecycle and will be automatically forwarded to all subscribers through the event flow.
val eventHandlers = DefaultServerSideEventHandlers() // Subscribe to events eventHandlers.eventFlow.collect { event -> println("Received event: ${event.eventType} at ${event.url}") } // Emit events during page processing eventHandlers.onCrawlEvent("onWillLoad", "https://example.com") eventHandlers.onLoadEvent("onFetched", page)
-
-
Method Summary
Modifier and Type Method Description abstract UnitonCrawlEvent(String eventType, String url, String message, Map<String, Object> metadata)Emits a crawl-phase event. abstract UnitonLoadEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)Emits a load-phase event. abstract UnitonBrowseEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)Emits a browse-phase event. abstract UnitonEvent(String eventType, String eventPhase, String url, String message, Map<String, Object> metadata)Emits a generic event with custom phase. abstract SharedFlow<ServerSideEvent>getEventFlow()The shared flow of server-side events. -
-
Method Detail
-
onCrawlEvent
abstract Unit onCrawlEvent(String eventType, String url, String message, Map<String, Object> metadata)
Emits a crawl-phase event.
- Parameters:
eventType- The type of the event (e.g., "onWillLoad", "onLoaded").url- The URL associated with the event.message- Optional message describing the event.metadata- Additional metadata for the event.
-
onLoadEvent
abstract Unit onLoadEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)
Emits a load-phase event.
- Parameters:
eventType- The type of the event (e.g., "onWillFetch", "onFetched", "onHTMLDocumentParsed").page- The web page associated with the event.message- Optional message describing the event.metadata- Additional metadata for the event.
-
onBrowseEvent
abstract Unit onBrowseEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)
Emits a browse-phase event.
- Parameters:
eventType- The type of the event (e.g., "onBrowserLaunched", "onNavigated", "onDocumentSteady").page- The web page associated with the event.message- Optional message describing the event.metadata- Additional metadata for the event.
-
onEvent
abstract Unit onEvent(String eventType, String eventPhase, String url, String message, Map<String, Object> metadata)
Emits a generic event with custom phase.
- Parameters:
eventType- The type of the event.eventPhase- The phase of the event.url- The URL associated with the event.message- Optional message describing the event.metadata- Additional metadata for the event.
-
getEventFlow
abstract SharedFlow<ServerSideEvent> getEventFlow()
The shared flow of server-side events. Subscribers can collect from this flow to receive all events.
-
-
-
-