Package org.xbill.DNS

Class SimpleResolver

java.lang.Object
org.xbill.DNS.SimpleResolver
All Implemented Interfaces:
Resolver

public class SimpleResolver extends Object implements Resolver
An implementation of Resolver that sends one query to one server. SimpleResolver handles TCP retries, transaction security (TSIG), and EDNS 0.
Author:
Brian Wellington
See Also:
  • Field Details

    • DEFAULT_PORT

      public static final int DEFAULT_PORT
      The default port to send queries to
      See Also:
    • DEFAULT_EDNS_PAYLOADSIZE

      public static final int DEFAULT_EDNS_PAYLOADSIZE
      The default EDNS payload size
      See Also:
  • Constructor Details

    • SimpleResolver

      public SimpleResolver() throws UnknownHostException
      Creates a SimpleResolver. The host to query is either found by using ResolverConfig, or the default host is used.
      Throws:
      UnknownHostException - Failure occurred while finding the host
      See Also:
    • SimpleResolver

      public SimpleResolver(String hostname) throws UnknownHostException
      Creates a SimpleResolver that will query the specified host
      Throws:
      UnknownHostException - Failure occurred while finding the host
    • SimpleResolver

      public SimpleResolver(InetSocketAddress host)
      Creates a SimpleResolver that will query the specified host
    • SimpleResolver

      public SimpleResolver(InetAddress host)
      Creates a SimpleResolver that will query the specified host
  • Method Details

    • getAddress

      public InetSocketAddress getAddress()
      Gets the destination address associated with this SimpleResolver. Messages sent using this SimpleResolver will be sent to this address.
      Returns:
      The destination address associated with this SimpleResolver.
    • setDefaultResolver

      public static void setDefaultResolver(InetSocketAddress hostname)
      Sets the default host (initially localhost) to query
    • setDefaultResolver

      public static void setDefaultResolver(String hostname)
      Sets the default host (initially localhost) to query
    • getPort

      public int getPort()
      Gets the port to communicate with on the server
      Since:
      3.2
    • setPort

      public void setPort(int port)
      Description copied from interface: Resolver
      Sets the port to communicate with on the server
      Specified by:
      setPort in interface Resolver
      Parameters:
      port - The port to send messages to
    • setAddress

      public void setAddress(InetSocketAddress addr)
      Sets the address of the server to communicate with.
      Parameters:
      addr - The address of the DNS server
    • setAddress

      public void setAddress(InetAddress addr)
      Sets the address of the server to communicate with (on the default DNS port)
      Parameters:
      addr - The address of the DNS server
    • setLocalAddress

      public void setLocalAddress(InetSocketAddress addr)
      Sets the local address to bind to when sending messages.
      Parameters:
      addr - The local address to send messages from.
    • setLocalAddress

      public void setLocalAddress(InetAddress addr)
      Sets the local address to bind to when sending messages. A random port will be used.
      Parameters:
      addr - The local address to send messages from.
    • getTCP

      public boolean getTCP()
      Gets whether TCP connections will be used by default
      Since:
      3.2
    • setTCP

      public void setTCP(boolean flag)
      Description copied from interface: Resolver
      Sets whether TCP connections will be used by default
      Specified by:
      setTCP in interface Resolver
      Parameters:
      flag - Indicates whether TCP connections are made
    • getIgnoreTruncation

      public boolean getIgnoreTruncation()
      Gets whether truncated responses will be ignored.
      Since:
      3.2
    • setIgnoreTruncation

      public void setIgnoreTruncation(boolean flag)
      Description copied from interface: Resolver
      Sets whether truncated responses will be ignored. If not, a truncated response over UDP will cause a retransmission over TCP.
      Specified by:
      setIgnoreTruncation in interface Resolver
      Parameters:
      flag - Indicates whether truncated responses should be ignored.
    • getEDNS

      public OPTRecord getEDNS()
      Gets the EDNS information on outgoing messages.
      Returns:
      The current OPTRecord for EDNS or null if EDNS is disabled.
      Since:
      3.2
    • setEDNS

      public void setEDNS(OPTRecord optRecord)
      Sets the EDNS information on outgoing messages.
      Parameters:
      optRecord - the OPTRecord for EDNS options or null to disable EDNS.
      Since:
      3.2
      See Also:
    • setEDNS

      public void setEDNS(int version, int payloadSize, int flags, List<EDNSOption> options)
      Description copied from interface: Resolver
      Sets the EDNS information on outgoing messages.
      Specified by:
      setEDNS in interface Resolver
      Parameters:
      version - The EDNS version to use. 0 indicates EDNS0 and -1 indicates no EDNS.
      payloadSize - The maximum DNS packet size that this host is capable of receiving over UDP. If 0 is specified, the default (1280) is used.
      flags - EDNS extended flags to be set in the OPT record.
      options - EDNS options to be set in the OPT record, specified as a List of OPTRecord.Option elements.
      See Also:
    • getTSIGKey

      public TSIG getTSIGKey()
      Get the TSIG key that messages will be signed with.
      Returns:
      the TSIG signature for outgoing messages or null if not specified.
      Since:
      3.2
    • setTSIGKey

      public void setTSIGKey(TSIG key)
      Description copied from interface: Resolver
      Specifies the TSIG key that messages will be signed with
      Specified by:
      setTSIGKey in interface Resolver
      Parameters:
      key - The key
    • setTimeout

      public void setTimeout(Duration timeout)
      Description copied from interface: Resolver
      Sets the amount of time to wait for a response before giving up.
      Specified by:
      setTimeout in interface Resolver
      Parameters:
      timeout - The amount of time to wait.
    • getTimeout

      public Duration getTimeout()
      Description copied from interface: Resolver
      Gets the amount of time to wait for a response before giving up.
      Specified by:
      getTimeout in interface Resolver
      See Also:
    • sendAsync

      public CompletionStage<Message> sendAsync(Message query)
      Asynchronously sends a message to a single server.
      Specified by:
      sendAsync in interface Resolver
      Parameters:
      query - The query to send
      Returns:
      A future that completes when the response has arrived.
    • sendAsync

      public CompletionStage<Message> sendAsync(Message query, Executor executor)
      Asynchronously sends a message to a single server.
      Specified by:
      sendAsync in interface Resolver
      Parameters:
      query - The query to send
      executor - The service to use for async operations.
      Returns:
      A future that completes when the response has arrived.
    • toString

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

      public IoClientFactory getIoClientFactory()
      Gets or sets the factory that creates clients for sending messages to the wire.
      Since:
      3.6
    • setIoClientFactory

      public void setIoClientFactory(IoClientFactory ioClientFactory)
      Gets or sets the factory that creates clients for sending messages to the wire.
      Since:
      3.6