Class HttpStreamManager

java.lang.Object
software.amazon.awssdk.crt.http.HttpStreamManager
All Implemented Interfaces:
AutoCloseable

public class HttpStreamManager extends Object implements AutoCloseable
Manages a Pool of HTTP Streams. Wraps either Http1StreamManager or Http2StreamManager depending on the expected protocol configured via HttpStreamManagerOptions.
  • Method Details

    • create

      public static HttpStreamManager create(HttpStreamManagerOptions options)
      Factory function for HttpStreamManager instances
      Parameters:
      options - the stream manager options to configure the manager
      Returns:
      a new instance of an HttpStreamManager
    • acquireStream

      public CompletableFuture<HttpStreamBase> acquireStream(HttpRequestBase request, HttpStreamBaseResponseHandler streamHandler)
      Request an HttpStream from StreamManager.

      HTTP/1.1 note: For HTTP/1.1 streams, the future is completed before activate() is called. Operations on the stream (such as cancel()) require activate to have been called first — otherwise they are a no-op. Callers that need to operate on the stream from a future callback should call stream.activate() before any other operation. activate() is idempotent and safe to call multiple times. HTTP/2 does not have this concern — the H2 stream manager activates the stream from the connection's event-loop thread in the C implementation before completing the future.

      Parameters:
      request - HttpRequestBase. The Request to make to the Server.
      streamHandler - HttpStreamBaseResponseHandler. The Stream Handler to be called from the Native EventLoop
      Returns:
      A future for a HttpStreamBase that will be completed when the stream is acquired.
    • acquireStream

      public CompletableFuture<HttpStreamBase> acquireStream(HttpRequestBase request, HttpStreamBaseResponseHandler streamHandler, boolean useManualDataWrites)
      Request an HttpStream from StreamManager.

      HTTP/1.1 note: For HTTP/1.1 streams, the future is completed before activate() is called. Operations on the stream (such as cancel()) require activate to have been called first — otherwise they are a no-op. Callers that need to operate on the stream from a future callback should call stream.activate() before any other operation. activate() is idempotent and safe to call multiple times. HTTP/2 does not have this concern — the H2 stream manager activates the stream from the connection's event-loop thread in the C implementation before completing the future.

      Parameters:
      request - HttpRequestBase. The Request to make to the Server.
      streamHandler - HttpStreamBaseResponseHandler. The Stream Handler to be called from the Native EventLoop
      useManualDataWrites - A boolean variable to signal that body will be streamed using async writes.
      Returns:
      A future for a HttpStreamBase that will be completed when the stream is acquired.
    • getShutdownCompleteFuture

      public CompletableFuture<Void> getShutdownCompleteFuture()
    • getManagerMetrics

      public HttpManagerMetrics getManagerMetrics()
      Returns:
      concurrency metrics for the current manager
    • getMaxConnections

      public int getMaxConnections()
      Returns:
      maximum number of connections this connection manager will pool
    • abortStream

      public void abortStream(HttpStreamBase stream)
      Abort an in-flight stream obtained from this manager. Cancels the HTTP exchange and ensures the underlying connection/stream slot is properly released back to the pool so it can be reused by new requests.

      This is the correct way to cancel an in-flight request from outside the stream callback lifecycle (e.g., on SDK timeout). For HTTP/1.1, the connection release is guaranteed by the AtomicBoolean guard and isNull() check inside Http1StreamManager.acquireStream() — calling cancel() triggers onResponseComplete on activated streams, or the post-activate guard catches streams closed before activation. For HTTP/2, the native layer handles stream slot accounting internally.

      Safe to call with null (e.g., if the stream was never acquired), after normal completion, or multiple times.

      Parameters:
      stream - the stream to abort, or null
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable