Package ai.platon.pulsar.skeleton.event
Class DefaultServerSideEventHandlers
-
- All Implemented Interfaces:
-
ai.platon.pulsar.skeleton.event.ServerSideEventHandlers
public final class DefaultServerSideEventHandlers implements ServerSideEventHandlers
Default implementation of ServerSideEventHandlers.
This implementation uses a MutableSharedFlow to broadcast events to all subscribers. Events are emitted asynchronously and will not block the event producer.
The shared flow is configured with:
replay = 100: New subscribers receive the last 100 events (to handle late subscriptions)
extraBufferCapacity = 64: Buffer up to 64 additional events if consumers are slow
-
-
Field Summary
Fields Modifier and Type Field Description private final SharedFlow<ServerSideEvent>eventFlow
-
Constructor Summary
Constructors Constructor Description DefaultServerSideEventHandlers(Integer replay, Integer extraBufferCapacity)
-
Method Summary
Modifier and Type Method Description SharedFlow<ServerSideEvent>getEventFlow()The shared flow of server-side events. UnitonCrawlEvent(String eventType, String url, String message, Map<String, Object> metadata)Emits a browser-phase event. UnitonLoadEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)Emits a load-phase event. UnitonBrowseEvent(String eventType, WebPage page, String message, Map<String, Object> metadata)Emits a browse-phase event. UnitonEvent(String eventType, String eventPhase, String url, String message, Map<String, Object> metadata)Emits a generic event with custom phase. -
-
Method Detail
-
getEventFlow
SharedFlow<ServerSideEvent> getEventFlow()
The shared flow of server-side events. Subscribers can collect from this flow to receive all events.
-
onCrawlEvent
Unit onCrawlEvent(String eventType, String url, String message, Map<String, Object> metadata)
Emits a browser-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
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
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
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.
-
-
-
-