Interface AlpacaSseSubscription

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
BrokerSseSubscription

public interface AlpacaSseSubscription extends AutoCloseable
Thread-safe, cancellable handle for one logical SSE subscription.
  • Method Details

    • request

      okhttp3.Request request()
      Returns the original logical request used to create this subscription.

      Reconnect-specific resume headers and query parameters are applied to internal request copies and are not reflected here.

    • state

    • lastEventId

      Optional<String> lastEventId()
      Returns the latest completed SSE event ID, including a completed data-less id: block.
    • connection

      Returns the most recently accepted connection, including after closure.
    • opened

      Completes with the first accepted connection.

      Once the response is accepted, this future completes successfully with that connection even if closure races with opening. The ordered onOpen callback remains ahead of the terminal listener callback.

      Keep synchronous continuations short. The lifecycle dependency above is supported, but use an asynchronous continuation such as thenApplyAsync with an application-owned executor for unrelated or potentially unbounded blocking work.

      If the subscription terminates before opening, completion() is settled before this future is cancelled or completed exceptionally. A synchronous opening continuation may therefore safely inspect terminal completion.

      Each call returns an independently settled defensive copy. Cancelling or manually completing one copy does not affect this subscription or another saved copy.

    • completion

      Returns terminal lifecycle completion.

      Normal and user closure complete successfully; terminal failures complete exceptionally. Lifecycle completion is resolved before the serialized terminal listener callback and does not wait for an active user callback. Settlement is handed off from the active callback path, so a synchronous completion continuation may wait for the ordered terminal listener even when the active callback initiated closure.

      Each call returns an independently settled defensive copy. Cancelling or manually completing one copy does not affect this subscription or another saved copy. Synchronous continuations run on isolated SDK lifecycle workers and must remain short. The ordered-terminal wait above is supported, and a blocked continuation does not delay another saved lifecycle copy or queue another subscription's settlement. Use an asynchronous continuation such as thenApplyAsync with an application-owned executor for unrelated or potentially unbounded blocking work.

    • close

      void close()
      Selects AlpacaSseCloseResult.Reason.USER_CLOSED when this call wins the terminal transition, cancels transport work, and waits for completion() to settle before returning.

      If another terminal transition wins concurrently, this method observes its normal or exceptional completion without rethrowing the terminal failure.

      Specified by:
      close in interface AutoCloseable