Class SseRequestResult.HandshakeAccepted
- All Implemented Interfaces:
SseRequestResult, AutoCloseable
- Enclosing interface:
SseRequestResult
Simulator.performSseRequest(Request).
The registerEventConsumer(Consumer) and registerCommentConsumer(Consumer) methods can be used to "listen" for Server-Sent Events and Comments, respectively.
Before the first consumer registers, initializer and broadcast payloads are captured up to one combined
connection queue capacity. The first registration
starts simulated client reading. Thereafter, new payloads of types without a consumer are discarded;
already-captured payloads remain available when that type's consumer later registers.
Pending deliveries to registered consumers share a separate queue-capacity bound. Captured payloads and pending deliveries can each retain at most that many payloads, excluding consumer calls already in progress. Neither limit bounds payload bytes. Overflow before reading or in pending delivery terminates the connection. Closing releases both buffers; unfinished consumer calls remain tracked through physical return.
The configured LifecycleObserver and MetricsCollector receive connection establishment
and termination callbacks with the same immutable SseConnection metadata snapshot. Accepted
connections whose initializer fails still receive the establishment pair followed by termination.
The termination pair shares the first elected StreamTermination, including its original cause
and duration measured at election. Terminal observation runs asynchronously after framework state is
released and establishment observation finishes; close() does not wait for application observers.
Observer work remains counted until it returns, including after an incomplete simulator teardown.
Consumer delivery runs synchronously on the broadcasting or registration thread; a slow
consumer delays that caller and other clients in the same broadcast. Reentrant/concurrent
pending deliveries have the bounded queue described above. Typed payload delivery does not
produce broadcast/drop metrics, socket-write callbacks or byte/write-duration metrics.
The data provided when the handshake was accepted is available via getSseHandshakeResult(), and the final data sent to the client is available via getHttpRequestResult().
- Author:
- Mark Allen
-
Nested Class Summary
Nested classes/interfaces inherited from interface SseRequestResult
SseRequestResult.HandshakeAccepted, SseRequestResult.HandshakeRejected, SseRequestResult.RequestFailedModifier and TypeInterfaceDescriptionstatic final classRepresents the result of an SSE accepted handshake (connection stays open) when simulated bySimulator.performSseRequest(Request).static final classRepresents the result of an SSE rejected handshake (explicit rejection; connection closed) when simulated bySimulator.performSseRequest(Request).static final classRepresents the result of an SSE request failure (implicit rejection, e.g. an exception occurred; connection closed) when simulated bySimulator.performSseRequest(Request). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Disconnects this simulated client.Returns the initial handshake response; remains available afterclose().Returns the original accepted handshake, including its headers and cookies.voidregisterCommentConsumer(@NonNull Consumer<@NonNull SseComment> commentConsumer) Registers the sole comment consumer and delivers buffered comments in order.voidregisterEventConsumer(@NonNull Consumer<@NonNull SseEvent> eventConsumer) Registers the sole event consumer and delivers buffered events in order.toString()
-
Method Details
-
close
Disconnects this simulated client. Repeated calls are harmless. Handshake metadata remains available. Terminal callbacks are asynchronous; this method does not wait for lifecycle observers or metrics collectors.- Specified by:
closein interfaceAutoCloseable
-
registerEventConsumer
Registers the sole event consumer and delivers buffered events in order.The first event or comment consumer starts reading. New events received while only a comment consumer is registered are discarded; events captured before reading remain available to this consumer.
- Throws:
IllegalStateException- if a consumer is already registered or this connection has terminated
-
registerCommentConsumer
Registers the sole comment consumer and delivers buffered comments in order.The first event or comment consumer starts reading. New comments received while only an event consumer is registered are discarded; comments captured before reading remain available to this consumer.
- Throws:
IllegalStateException- if a consumer is already registered or this connection has terminated
-
getSseHandshakeResult
Returns the original accepted handshake, including its headers and cookies. -
getHttpRequestResult
Returns the initial handshake response; remains available afterclose(). -
toString
-