org.xbill.DNS
Class SimpleResolver

java.lang.Object
  extended byorg.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:
Resolver, TSIG, OPTRecord

Field Summary
static int DEFAULT_PORT
          The default port to send queries to
 
Constructor Summary
SimpleResolver()
          Creates a SimpleResolver.
SimpleResolver(String hostname)
          Creates a SimpleResolver that will query the specified host
 
Method Summary
 Message send(Message query)
          Sends a message to a single server and waits for a response.
 Object sendAsync(Message query, ResolverListener listener)
          Asynchronously sends a message to a single server, registering a listener to receive a callback on success or exception.
static void setDefaultResolver(String hostname)
          Sets the default host (initially localhost) to query
 void setEDNS(int level)
          Sets the EDNS version used on outgoing messages.
 void setIgnoreTruncation(boolean flag)
          Sets whether truncated responses will be ignored.
 void setPort(int port)
          Sets the port to communicate with on the server
 void setTCP(boolean flag)
          Sets whether TCP connections will be sent by default
 void setTimeout(int secs)
          Sets the amount of time to wait for a response before giving up.
 void setTSIGKey(Name name, byte[] key)
          Specifies the TSIG key that messages will be signed with
 void setTSIGKey(String key)
          Specifies the TSIG key (with the same name as the local host) that messages will be signed with.
 void setTSIGKey(String name, String key)
          Specifies the TSIG key that messages will be signed with
 void setTSIGKey(TSIG key)
          Specifies the TSIG key that messages will be signed with
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to send queries to

See Also:
Constant Field Values
Constructor Detail

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()
               throws UnknownHostException
Creates a SimpleResolver. The host to query is either found by FindServer, or the default host is used.

Throws:
UnknownHostException - Failure occurred while finding the host
See Also:
FindServer
Method Detail

setDefaultResolver

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


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

setTCP

public void setTCP(boolean flag)
Description copied from interface: Resolver
Sets whether TCP connections will be sent by default

Specified by:
setTCP in interface Resolver
Parameters:
flag - Indicates whether TCP connections are made

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.

setEDNS

public void setEDNS(int level)
Description copied from interface: Resolver
Sets the EDNS version used on outgoing messages.

Specified by:
setEDNS in interface Resolver
Parameters:
level - The EDNS level to use. 0 indicates EDNS0 and -1 indicates no EDNS.

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

setTSIGKey

public void setTSIGKey(Name name,
                       byte[] key)
Description copied from interface: Resolver
Specifies the TSIG key that messages will be signed with

Specified by:
setTSIGKey in interface Resolver
Parameters:
name - The key name
key - The key data

setTSIGKey

public void setTSIGKey(String name,
                       String key)
Description copied from interface: Resolver
Specifies the TSIG key that messages will be signed with

Specified by:
setTSIGKey in interface Resolver
Parameters:
name - The key name
key - The key data, represented as either a base64 encoded string or (if the first character is ':') a hex encoded string

setTSIGKey

public void setTSIGKey(String key)
                throws UnknownHostException
Description copied from interface: Resolver
Specifies the TSIG key (with the same name as the local host) that messages will be signed with.

Specified by:
setTSIGKey in interface Resolver
Parameters:
key - The key data, represented as either a base64 encoded string or (if the first character is ':') a hex encoded string
Throws:
UnknownHostException - The local host name could not be determined

setTimeout

public void setTimeout(int secs)
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:
secs - The number of seconds to wait.

send

public Message send(Message query)
             throws IOException
Sends a message to a single server and waits for a response. No checking is done to ensure that the response is associated with the query.

Specified by:
send in interface Resolver
Parameters:
query - The query to send.
Returns:
The response.
Throws:
IOException - An error occurred while sending or receiving.

sendAsync

public Object sendAsync(Message query,
                        ResolverListener listener)
Asynchronously sends a message to a single server, registering a listener to receive a callback on success or exception. Multiple asynchronous lookups can be performed in parallel. Since the callback may be invoked before the function returns, external synchronization is necessary.

Specified by:
sendAsync in interface Resolver
Parameters:
query - The query to send
listener - The object containing the callbacks.
Returns:
An identifier, which is also a parameter in the callback