Class ServerSentEventParser
java.lang.Object
org.a2aproject.sdk.client.http.ServerSentEventParser
Streaming parser for Server-Sent Events (SSE).
Feed lines one at a time via processLine(String); call flush() when the stream ends.
Not thread-safe — each connection should use its own instance.
-
Constructor Summary
ConstructorsConstructorDescriptionServerSentEventParser(Consumer<ServerSentEvent> eventConsumer) ServerSentEventParser(Consumer<ServerSentEvent> eventConsumer, @Nullable Consumer<Throwable> errorConsumer) ServerSentEventParser(Consumer<ServerSentEvent> eventConsumer, @Nullable Consumer<Throwable> errorConsumer, SSEParserConfig config) -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Dispatches any buffered data not yet followed by an empty line.@Nullable StringReturns the last event ID received, ornullif none.@Nullable LonggetRetry()Returns the reconnection interval in milliseconds from the lastretry:field, ornullif none.voidprocessLine(@Nullable String line) Processes a single line from the SSE stream.voidSignals that the transport layer detected a line exceeding the configured limit before materialising the full line in memory.
-
Constructor Details
-
ServerSentEventParser
-
ServerSentEventParser
public ServerSentEventParser(Consumer<ServerSentEvent> eventConsumer, @Nullable Consumer<Throwable> errorConsumer) -
ServerSentEventParser
public ServerSentEventParser(Consumer<ServerSentEvent> eventConsumer, @Nullable Consumer<Throwable> errorConsumer, SSEParserConfig config)
-
-
Method Details
-
processLineTooLong
public void processLineTooLong()Signals that the transport layer detected a line exceeding the configured limit before materialising the full line in memory. This marks the current event block as corrupt (same as ifprocessLine(String)had received an oversized string) and reports the error, without requiring the caller to allocate a placeholder string. -
processLine
Processes a single line from the SSE stream. An empty line dispatches any buffered event. Anullline is routed to the error consumer (or logged) without affecting the current event block. -
flush
public void flush()Dispatches any buffered data not yet followed by an empty line. Call when the stream ends. -
getLastEventId
Returns the last event ID received, ornullif none. -
getRetry
Returns the reconnection interval in milliseconds from the lastretry:field, ornullif none.
-