Class BrokerSseSubscription

java.lang.Object
markets.alpaca.client.broker.sse.BrokerSseSubscription
All Implemented Interfaces:
AutoCloseable, AlpacaSseSubscription

public final class BrokerSseSubscription extends Object implements AlpacaSseSubscription
Handle for a Broker SSE subscription.

Closing the handle cancels the underlying shared SSE subscription.

  • Method Details

    • eventSource

      public okhttp3.sse.EventSource eventSource()
      Returns a stable OkHttp-compatible facade for this logical subscription.

      This compatibility facade delegates EventSource.request() and EventSource.cancel() to the shared SSE subscription; it is not the transport's underlying OkHttp event source. Identity, implementation casts, and access to the live OkHttp response are not supported. New code should call close().

    • request

      public okhttp3.Request request()
      Description copied from interface: AlpacaSseSubscription
      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.

      Specified by:
      request in interface AlpacaSseSubscription
    • state

      public AlpacaSseState state()
      Specified by:
      state in interface AlpacaSseSubscription
    • lastEventId

      public Optional<String> lastEventId()
      Description copied from interface: AlpacaSseSubscription
      Returns the latest completed SSE event ID, including a completed data-less id: block.
      Specified by:
      lastEventId in interface AlpacaSseSubscription
    • connection

      public Optional<AlpacaSseConnectionInfo> connection()
      Description copied from interface: AlpacaSseSubscription
      Returns the most recently accepted connection, including after closure.
      Specified by:
      connection in interface AlpacaSseSubscription
    • opened

      Description copied from interface: AlpacaSseSubscription
      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, AlpacaSseSubscription.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.

      Specified by:
      opened in interface AlpacaSseSubscription
    • completion

      Description copied from interface: AlpacaSseSubscription
      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.

      Specified by:
      completion in interface AlpacaSseSubscription
    • close

      public void close()
      Cancels the SSE stream.
      Specified by:
      close in interface AlpacaSseSubscription
      Specified by:
      close in interface AutoCloseable