Class HttpClientAgent

java.lang.Object
io.vertx.reactivex.core.http.HttpClientAgent
All Implemented Interfaces:
io.vertx.lang.rx.RxDelegate, HttpClient, Measured

public class HttpClientAgent extends Object implements io.vertx.lang.rx.RxDelegate, HttpClient, Measured
An asynchronous HTTP client.

It allows you to make requests to HTTP servers, and a single client can make requests to any server.

The client can also pool HTTP connections.

For pooling to occur, keep-alive must be true on the HttpClientOptions (default is true). In this case connections will be pooled and re-used if there are pending HTTP requests waiting to get a connection, otherwise they will be closed.

This gives the benefits of keep alive when the client is loaded but means we don't keep connections hanging around unnecessarily when there would be no benefits anyway.

The client also supports pipe-lining of requests. Pipe-lining means another request is sent on the same connection before the response from the preceding one has returned. Pipe-lining is not appropriate for all requests.

To enable pipe-lining, it must be enabled on the HttpClientOptions (default is false).

When pipe-lining is enabled the connection will be automatically closed when all in-flight responses have returned and there are no outstanding pending requests to write.

The client is designed to be reused between requests.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.

  • Field Details

    • __TYPE_ARG

      public static final io.vertx.lang.rx.TypeArg<HttpClientAgent> __TYPE_ARG
  • Constructor Details

    • HttpClientAgent

      public HttpClientAgent(HttpClientAgent delegate)
    • HttpClientAgent

      public HttpClientAgent(Object delegate)
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getDelegate

      public HttpClientAgent getDelegate()
      Specified by:
      getDelegate in interface HttpClient
      Specified by:
      getDelegate in interface Measured
      Specified by:
      getDelegate in interface io.vertx.lang.rx.RxDelegate
    • isMetricsEnabled

      public boolean isMetricsEnabled()
      Whether the metrics are enabled for this measured object
      Specified by:
      isMetricsEnabled in interface Measured
      Returns:
      true if metrics are enabled
    • request

      public Future<HttpClientRequest> request()
      Create an HTTP request to send to the server with the default host and port of the client.
      Specified by:
      request in interface HttpClient
      Returns:
      a future notified when the request is ready to be sent
    • rxRequest

      public Single<HttpClientRequest> rxRequest()
      Create an HTTP request to send to the server with the default host and port of the client.
      Specified by:
      rxRequest in interface HttpClient
      Returns:
      a future notified when the request is ready to be sent
    • request

      public Future<HttpClientRequest> request(RequestOptions options)
      Create an HTTP request to send to the server.
      Specified by:
      request in interface HttpClient
      Parameters:
      options - the request options
      Returns:
      a future notified when the request is ready to be sent
    • rxRequest

      public Single<HttpClientRequest> rxRequest(RequestOptions options)
      Create an HTTP request to send to the server.
      Specified by:
      rxRequest in interface HttpClient
      Parameters:
      options - the request options
      Returns:
      a future notified when the request is ready to be sent
    • request

      public Future<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI)
      Create an HTTP request to send to the server at the host and port.
      Specified by:
      request in interface HttpClient
      Parameters:
      method - the HTTP method
      port - the port
      host - the host
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • rxRequest

      public Single<HttpClientRequest> rxRequest(HttpMethod method, int port, String host, String requestURI)
      Create an HTTP request to send to the server at the host and port.
      Specified by:
      rxRequest in interface HttpClient
      Parameters:
      method - the HTTP method
      port - the port
      host - the host
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • request

      public Future<HttpClientRequest> request(HttpMethod method, String host, String requestURI)
      Create an HTTP request to send to the server at the host and default port.
      Specified by:
      request in interface HttpClient
      Parameters:
      method - the HTTP method
      host - the host
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • rxRequest

      public Single<HttpClientRequest> rxRequest(HttpMethod method, String host, String requestURI)
      Create an HTTP request to send to the server at the host and default port.
      Specified by:
      rxRequest in interface HttpClient
      Parameters:
      method - the HTTP method
      host - the host
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • request

      public Future<HttpClientRequest> request(HttpMethod method, String requestURI)
      Create an HTTP request to send to the server at the default host and port.
      Specified by:
      request in interface HttpClient
      Parameters:
      method - the HTTP method
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • rxRequest

      public Single<HttpClientRequest> rxRequest(HttpMethod method, String requestURI)
      Create an HTTP request to send to the server at the default host and port.
      Specified by:
      rxRequest in interface HttpClient
      Parameters:
      method - the HTTP method
      requestURI - the relative URI
      Returns:
      a future notified when the request is ready to be sent
    • shutdown

      public Future<Void> shutdown()
      Shutdown with a 30 seconds timeout (shutdown(30, TimeUnit.SECONDS)).
      Specified by:
      shutdown in interface HttpClient
      Returns:
      a future completed when shutdown has completed
    • rxShutdown

      public Completable rxShutdown()
      Shutdown with a 30 seconds timeout (shutdown(30, TimeUnit.SECONDS)).
      Specified by:
      rxShutdown in interface HttpClient
      Returns:
      a future completed when shutdown has completed
    • close

      public Future<Void> close()
      Close immediately (shutdown(0, TimeUnit.SECONDS).
      Specified by:
      close in interface HttpClient
      Returns:
      a future notified when the client is closed
    • rxClose

      public Completable rxClose()
      Close immediately (shutdown(0, TimeUnit.SECONDS).
      Specified by:
      rxClose in interface HttpClient
      Returns:
      a future notified when the client is closed
    • shutdown

      public Future<Void> shutdown(long timeout, TimeUnit unit)
      Specified by:
      shutdown in interface HttpClient
      Parameters:
      timeout -
      unit -
      Returns:
    • rxShutdown

      public Completable rxShutdown(long timeout, TimeUnit unit)
      Specified by:
      rxShutdown in interface HttpClient
      Parameters:
      timeout -
      unit -
      Returns:
    • updateSSLOptions

      public Future<Boolean> updateSSLOptions(ClientSSLOptions options)

      Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      Returns:
      a future signaling the update success
    • rxUpdateSSLOptions

      public Single<Boolean> rxUpdateSSLOptions(ClientSSLOptions options)

      Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      Returns:
      a future signaling the update success
    • updateSSLOptions

      public Future<Boolean> updateSSLOptions(ClientSSLOptions options, boolean force)

      Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      force - force the update when options are equals
      Returns:
      a future signaling the update success
    • rxUpdateSSLOptions

      public Single<Boolean> rxUpdateSSLOptions(ClientSSLOptions options, boolean force)

      Update the client with new SSL options, the update happens if the options object is valid and different from the existing options object.

      The options object is compared using its equals method against the existing options to prevent an update when the objects are equals since loading options can be costly, this can happen for share TCP servers. When object are equals, setting force to true forces the update.

      The boolean succeeded future result indicates whether the update occurred.

      Parameters:
      options - the new SSL options
      force - force the update when options are equals
      Returns:
      a future signaling the update success
    • connect

      public Future<HttpClientConnection> connect(HttpConnectOptions options)
      Connect to a remote HTTP server with the specific options, the connection is un-pooled and the management of the connection is left to the user.
      Parameters:
      options - the server connect options
      Returns:
      a future notified when the connection is available
    • rxConnect

      public Single<HttpClientConnection> rxConnect(HttpConnectOptions options)
      Connect to a remote HTTP server with the specific options, the connection is un-pooled and the management of the connection is left to the user.
      Parameters:
      options - the server connect options
      Returns:
      a future notified when the connection is available
    • shutdown

      public Future<Void> shutdown(Duration timeout)
      Initiate the client shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed, client connection are immediately removed from the pool. When all connections are closed the client is closed. When the timeout expires, all unclosed connections are immediately closed.

      • HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      • HTTP/1.x client connection will be closed after the current response is received
      Parameters:
      timeout - the amount of time after which all resources are forcibly closed
      Returns:
      a future notified when the client is closed
    • rxShutdown

      public Completable rxShutdown(Duration timeout)
      Initiate the client shutdown sequence.

      Connections are taken out of service and closed when all inflight requests are processed, client connection are immediately removed from the pool. When all connections are closed the client is closed. When the timeout expires, all unclosed connections are immediately closed.

      • HTTP/2 connections will send a go away frame immediately to signal the other side the connection will close
      • HTTP/1.x client connection will be closed after the current response is received
      Parameters:
      timeout - the amount of time after which all resources are forcibly closed
      Returns:
      a future notified when the client is closed
    • newInstance

      public static HttpClientAgent newInstance(HttpClientAgent arg)