Interface Destination

All Known Implementing Classes:
HttpDestination

public interface Destination

A Destination represents the receiver of HTTP requests, and it is identified by an Origin.

Destination holds a pool of Connections, but allows to create unpooled connections if the application wants full control over connection management via newConnection(Promise).

Destinations may be obtained via HttpClient.resolveDestination(Request).

  • Method Details

    • getOrigin

      Origin getOrigin()
      Returns:
      the origin of this destination
    • isSecure

      boolean isSecure()
      Returns:
      whether the communication with the destination is secure
    • getProxy

      Returns:
      the proxy associated with this destination, or null if there is no proxy
    • getConnectionPool

      ConnectionPool getConnectionPool()
      Returns:
      the connection pool associated with this destination
    • getHttpClient

      HttpClient getHttpClient()
      Returns:
      the HttpClient that manages this destination
    • newConnection

      void newConnection(Promise<Connection> promise)
      Creates asynchronously a new, unpooled, Connection that will be returned at a later time through the given Promise.

      Use FuturePromise to wait for the connection:

      
       Destination destination = ...;
       FuturePromise<Connection> futureConnection = new FuturePromise<>();
       destination.newConnection(futureConnection);
       Connection connection = futureConnection.get(5, TimeUnit.SECONDS);
       
      Parameters:
      promise - the promise of a new, unpooled, Connection
    • newConnection

      default CompletableFuture<Connection> newConnection()

      Creates asynchronously a new, unpooled, Connection that will be returned at a later time through the given Promise.

      Returns:
      a CompletableFuture for a new, unpooled, Connection
    • send

      void send(Request request, Response.CompleteListener listener)

      Sends the given request to this destination.

      You can use this method to send the request to a specific destination that may be different from the request authority.

      For example when HttpClient is used in a proxy, it may receive a request with authority yourserver.com but the proxy logic may want to forward the request to a specific backend server, say backend01, therefore:

      
       // Resolve the backend destination.
       Origin backendOrigin = new Origin(backendScheme, "backend01", backendPort);
       Destination backendDestination = httpClient.resolveDestination(backendOrigin);
      
       // Create a request with the original authority.
       Request request = httpClient.newRequest("https://yourserver.com/path");
      
       // Send the request to the specific backend.
       backendDestination.send(request, result -> { ... });
       
      Parameters:
      request - the request to send to this destination
      listener - the listener that receives response events