Class SseRequestResult.HandshakeAccepted

java.lang.Object
com.soklet.SseRequestResult.HandshakeAccepted
All Implemented Interfaces:
SseRequestResult, AutoCloseable
Enclosing interface:
SseRequestResult

Represents the result of an SSE accepted handshake (connection stays open) when simulated by 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
  • Method Details

    • close

      public void 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:
      close in interface AutoCloseable
    • 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 after close().
    • toString

      Overrides:
      toString in class Object