Class Http2ClientConnection

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class Http2ClientConnection
    extends HttpClientConnection
    This class wraps aws-c-http to provide the basic HTTP/2 request/response functionality via the AWS Common Runtime. Http2ClientConnection represents a single connection to a HTTP/2 service endpoint. This class is not thread safe and should not be called from different threads.
    • Constructor Detail

      • Http2ClientConnection

        public Http2ClientConnection​(long connectionBinding)
    • Method Detail

      • updateSettings

        public java.util.concurrent.CompletableFuture<java.lang.Void> updateSettings​(java.util.List<Http2ConnectionSetting> settings)
        Send a SETTINGS frame. SETTINGS will be applied locally when SETTINGS ACK is received from peer.
        Parameters:
        settings - The array of settings to change. Note: each setting has its boundary.
        Returns:
        When this future completes without exception, the peer has acknowledged the settings and the change has been applied.
      • sendPing

        public java.util.concurrent.CompletableFuture<java.lang.Long> sendPing​(byte[] pingData)
        Send a PING frame. Round-trip-time is calculated when PING ACK is received from peer.
        Parameters:
        pingData - 8 Bytes data with the PING frame or null for not include data in ping
        Returns:
        When this future completes without exception, the peer has acknowledged the PING and future will be completed with the round trip time in nano seconds for the connection.
      • sendPing

        public java.util.concurrent.CompletableFuture<java.lang.Long> sendPing()
      • sendGoAway

        public void sendGoAway​(Http2ClientConnection.Http2ErrorCode Http2ErrorCode,
                               boolean allowMoreStreams,
                               byte[] debugData)
        Send a custom GOAWAY frame. Note that the connection automatically attempts to send a GOAWAY during shutdown (unless a GOAWAY with a valid Last-Stream-ID has already been sent). This call can be used to gracefully warn the peer of an impending shutdown (http2_error=0, allow_more_streams=true), or to customize the final GOAWAY frame that is sent by this connection. The other end may not receive the goaway, if the connection already closed.
        Parameters:
        Http2ErrorCode - The HTTP/2 error code (RFC-7540 section 7) to send. `enum Http2ErrorCode` lists official codes.
        allowMoreStreams - If true, new peer-initiated streams will continue to be acknowledged and the GOAWAY's Last-Stream-ID will be set to a max value. If false, new peer-initiated streams will be ignored and the GOAWAY's Last-Stream-ID will be set to the latest acknowledged stream.
        debugData - Optional debug data to send. Size must not exceed 16KB. null is acceptable to not include debug data.
      • updateConnectionWindow

        public void updateConnectionWindow​(long incrementSize)
        Increment the connection's flow-control window to keep data flowing. If the connection was created with `manualWindowManagement` set true, the flow-control window of the connection will shrink as body data is received for all the streams created on it. (headers, padding, and other metadata do not affect the window). The initial connection flow-control window is 65,535. Once the connection's flow-control window reaches to 0, all the streams on the connection stop receiving any further data. If `manualWindowManagement` is false, this call will have no effect. The connection maintains its flow-control windows such that no back-pressure is applied and data arrives as fast as possible. If you are not connected, this call will have no effect. Crashes when the connection is not http2 connection. The limit of the Maximum Size is 2**31 - 1. If the increment size cause the connection flow window exceeds the Maximum size, this call will result in the connection lost.
        Parameters:
        incrementSize - The size to increment for the connection's flow control window
      • makeRequest

        public Http2Stream makeRequest​(HttpRequestBase request,
                                       HttpStreamBaseResponseHandler streamHandler)
                                throws CrtRuntimeException
        Schedules an HttpRequest on the Native EventLoop for this HttpClientConnection. The HTTP/1.1 request will be transformed to HTTP/2 request under the hood.
        Overrides:
        makeRequest in class HttpClientConnection
        Parameters:
        request - The Request to make to the Server.
        streamHandler - The Stream Handler to be called from the Native EventLoop
        Returns:
        The Http2Stream that represents this Request/Response Pair. It can be closed at any time during the request/response, but must be closed by the user thread making this request when it's done.
        Throws:
        CrtRuntimeException - if stream creation fails