Class HttpDestination

All Implemented Interfaces:
Destination, Callback, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Invocable, Sweeper.Sweepable

@ManagedObject public class HttpDestination extends ContainerLifeCycle implements Destination, Callback, Dumpable, Sweeper.Sweepable
  • Constructor Details

  • Method Details

    • accept

      public void accept(Connection connection)
    • stale

      public boolean stale()
    • sweep

      public boolean sweep()
      Specified by:
      sweep in interface Sweeper.Sweepable
      Returns:
      whether this resource should be swept
    • doStart

      protected void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class ContainerLifeCycle
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • doStop

      protected void doStop() throws Exception
      Description copied from class: ContainerLifeCycle
      Stops the managed lifecycle beans in the reverse order they were added.
      Overrides:
      doStop in class ContainerLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • newConnectionPool

      protected ConnectionPool newConnectionPool(HttpClient client)
    • newExchangeQueue

      protected Queue<HttpExchange> newExchangeQueue(HttpClient client)
    • isSecure

      public boolean isSecure()
      Specified by:
      isSecure in interface Destination
      Returns:
      whether the communication with the destination is secure
    • getHttpClient

      public HttpClient getHttpClient()
      Specified by:
      getHttpClient in interface Destination
      Returns:
      the HttpClient that manages this destination
    • getOrigin

      public Origin getOrigin()
      Specified by:
      getOrigin in interface Destination
      Returns:
      the origin of this destination
    • getHttpExchanges

      public Queue<HttpExchange> getHttpExchanges()
    • getProxy

      public ProxyConfiguration.Proxy getProxy()
      Specified by:
      getProxy in interface Destination
      Returns:
      the proxy associated with this destination, or null if there is no proxy
    • getClientConnectionFactory

      public ClientConnectionFactory getClientConnectionFactory()
    • getScheme

      @ManagedAttribute(value="The destination scheme", readonly=true) public String getScheme()
    • getHost

      @ManagedAttribute(value="The destination host", readonly=true) public String getHost()
    • getPort

      @ManagedAttribute(value="The destination port", readonly=true) public int getPort()
    • getQueuedRequestCount

      @ManagedAttribute(value="The number of queued requests", readonly=true) public int getQueuedRequestCount()
    • getHostField

      public HttpField getHostField()
    • getConnectionPool

      @ManagedAttribute(value="The connection pool", readonly=true) public ConnectionPool getConnectionPool()
      Specified by:
      getConnectionPool in interface Destination
      Returns:
      the connection pool associated with this destination
    • succeeded

      public void succeeded()
      Description copied from interface: Callback

      Callback invoked when the operation completes.

      Specified by:
      succeeded in interface Callback
      See Also:
    • failed

      public void failed(Throwable x)
      Description copied from interface: Callback

      Callback invoked when the operation fails.

      Specified by:
      failed in interface Callback
      Parameters:
      x - the reason for the operation failure
    • send

      public void send(Request request, Response.CompleteListener listener)
      Description copied from interface: Destination

      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 -> { ... });
       
      Specified by:
      send in interface Destination
      Parameters:
      request - the request to send to this destination
      listener - the listener that receives response events
    • send

      public void send(HttpExchange exchange)
    • enqueue

      protected boolean enqueue(Queue<HttpExchange> queue, HttpExchange exchange)
    • send

      public void send()
    • send

      protected SendFailure send(IConnection connection, HttpExchange exchange)
    • newConnection

      public void newConnection(Promise<Connection> promise)
      Description copied from interface: Destination
      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);
       
      Specified by:
      newConnection in interface Destination
      Parameters:
      promise - the promise of a new, unpooled, Connection
    • createConnection

      protected void createConnection(Promise<Connection> promise)
    • remove

      public boolean remove(HttpExchange exchange)
    • release

      public void release(Connection connection)
    • remove

      public boolean remove(Connection connection)
    • abort

      public void abort(Throwable cause)
      Aborts all the HttpExchanges queued in this destination.
      Parameters:
      cause - the abort cause
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Overrides:
      dump in class ContainerLifeCycle
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • asString

      public String asString()
    • getIdle

      @ManagedAttribute("For how long this destination has been idle in ms") public long getIdle()
    • isStale

      @ManagedAttribute("Whether this destinations is stale") public boolean isStale()
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLifeCycle