Class DefaultServerSentEventParser
java.lang.Object
dev.langchain4j.http.client.sse.DefaultServerSentEventParser
- All Implemented Interfaces:
ServerSentEventParser
-
Nested Class Summary
Nested classes/interfaces inherited from interface ServerSentEventParser
ServerSentEventParser.Incremental -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a freshServerSentEventParser.Incrementalparser instance backed by the same parsing logic asServerSentEventParser.parse(InputStream, ServerSentEventListener), but driven by byte chunks instead of a blockingInputStream.voidparse(InputStream httpResponseBody, ServerSentEventListener listener) Parses an input stream containing server-sent events and notifies the listener of parsed events.
-
Constructor Details
-
DefaultServerSentEventParser
public DefaultServerSentEventParser()
-
-
Method Details
-
parse
Description copied from interface:ServerSentEventParserParses an input stream containing server-sent events and notifies the listener of parsed events. This method blocks until the input stream is exhausted or an error occurs.For each complete event found in the stream,
ServerSentEventListener.onEvent(ServerSentEvent)is called. If any parsing or processing error occurs,ServerSentEventListener.onError(Throwable)is called and parsing may terminate.- Specified by:
parsein interfaceServerSentEventParser- Parameters:
httpResponseBody- the input stream containing SSE data to parselistener- the listener to receive parsed events or error notifications
-
incremental
Description copied from interface:ServerSentEventParserReturns a freshServerSentEventParser.Incrementalparser instance backed by the same parsing logic asServerSentEventParser.parse(InputStream, ServerSentEventListener), but driven by byte chunks instead of a blockingInputStream. Used by the publisher-based HTTP client API to avoid pinning a thread per active stream.A parser opts into the publisher path by overriding this method. One that has not opted in throws
AsyncNotSupportedException, the same "this component is not asynchronous" marker the rest of the non-blocking API reports through its return type - this method returns a plain value, so it has nowhere to carry a failure and must throw. Existing parsers that only supportServerSentEventParser.parse(InputStream, ServerSentEventListener)continue to work unchanged.- Specified by:
incrementalin interfaceServerSentEventParser
-