Class SocketAddressResolver.Async

java.lang.Object
org.eclipse.jetty.util.SocketAddressResolver.Async
All Implemented Interfaces:
SocketAddressResolver
Enclosing interface:
SocketAddressResolver

@ManagedObject("The asynchronous address resolver") public static class SocketAddressResolver.Async extends Object implements SocketAddressResolver

Creates InetSocketAddress instances asynchronously in a different thread.

InetSocketAddress(String, int) attempts to perform a DNS resolution of the host name, and this may block for several seconds. This class creates the InetSocketAddress in a separate thread and provides the result through a Promise, with the possibility to specify a timeout for the operation.

Example usage:

 SocketAddressResolver resolver = new SocketAddressResolver.Async(executor, scheduler, timeout);
 resolver.resolve("www.google.com", 80, new Promise<SocketAddress>()
 {
     public void succeeded(SocketAddress result)
     {
         // The address was resolved
     }

     public void failed(Throwable failure)
     {
         // The address resolution failed
     }
 });
 
  • Constructor Details

    • Async

      public Async(Executor executor, Scheduler scheduler, long timeout)
      Creates a new instance with the specified executor (to perform DNS resolution in a separate thread), scheduler (to cancel the operation if it takes too long) and timeout, in milliseconds.
      Parameters:
      executor - the thread pool to use to perform DNS resolution in pooled threads
      scheduler - the scheduler to schedule tasks to cancel DNS resolution if it takes too long
      timeout - the timeout, in milliseconds, for the DNS resolution to complete
  • Method Details

    • getExecutor

      public Executor getExecutor()
      Returns:
      the executor used for DNS resolution
    • getScheduler

      public Scheduler getScheduler()
      Returns:
      the scheduler used for timeout operations
    • getTimeout

      @ManagedAttribute(value="The timeout, in milliseconds, to resolve an address", readonly=true) public long getTimeout()
    • resolve

      public void resolve(String host, int port, Promise<List<InetSocketAddress>> promise)
      Description copied from interface: SocketAddressResolver
      Resolves via DNS the given host and port, within the connect timeout, returning a list of InetSocketAddress through the given Promise.
      Specified by:
      resolve in interface SocketAddressResolver
      Parameters:
      host - the host to resolve
      port - the port of the resulting socket address
      promise - the callback invoked when the resolution succeeds or fails