org.xbill.DNS
Class ExtendedResolver

java.lang.Object
  extended by org.xbill.DNS.ExtendedResolver
All Implemented Interfaces:
Resolver

public class ExtendedResolver
extends Object
implements Resolver

An implementation of Resolver that can send queries to multiple servers, sending the queries multiple times if necessary.

Author:
Brian Wellington
See Also:
Resolver

Constructor Summary
ExtendedResolver()
          Creates a new Extended Resolver.
ExtendedResolver(Resolver[] res)
          Creates a new Extended Resolver
ExtendedResolver(String[] servers)
          Creates a new Extended Resolver
 
Method Summary
 void addResolver(Resolver r)
          Adds a new resolver to be used by this ExtendedResolver
 void deleteResolver(Resolver r)
          Deletes a resolver used by this ExtendedResolver
 Resolver getResolver(int n)
          Returns the nth resolver used by this ExtendedResolver
 Resolver[] getResolvers()
          Returns all resolvers used by this ExtendedResolver
 Message send(Message query)
          Sends a message and waits for a response.
 Object sendAsync(Message query, ResolverListener listener)
          Asynchronously sends a message to multiple servers, potentially multiple times, registering a listener to receive a callback on success or exception.
 void setEDNS(int level)
          Sets the EDNS version used on outgoing messages.
 void setEDNS(int level, int payloadSize, int flags, List options)
          Sets the EDNS information on outgoing messages.
 void setIgnoreTruncation(boolean flag)
          Sets whether truncated responses will be ignored.
 void setLoadBalance(boolean flag)
          Sets whether the servers should be load balanced.
 void setPort(int port)
          Sets the port to communicate with on the server
 void setRetries(int retries)
          Sets the number of retries sent to each server per query
 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 setTimeout(int secs, int msecs)
          Sets the amount of time to wait for a response before giving up.
 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
 

Constructor Detail

ExtendedResolver

public ExtendedResolver()
                 throws UnknownHostException
Creates a new Extended Resolver. The default ResolverConfig is used to determine the servers for which SimpleResolver contexts should be initialized.

Throws:
UnknownHostException - Failure occured initializing SimpleResolvers
See Also:
SimpleResolver, ResolverConfig

ExtendedResolver

public ExtendedResolver(String[] servers)
                 throws UnknownHostException
Creates a new Extended Resolver

Parameters:
servers - An array of server names for which SimpleResolver contexts should be initialized.
Throws:
UnknownHostException - Failure occured initializing SimpleResolvers
See Also:
SimpleResolver

ExtendedResolver

public ExtendedResolver(Resolver[] res)
                 throws UnknownHostException
Creates a new Extended Resolver

Parameters:
res - An array of pre-initialized Resolvers is provided.
Throws:
UnknownHostException - Failure occured initializing SimpleResolvers
See Also:
SimpleResolver
Method Detail

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.

setEDNS

public void setEDNS(int level,
                    int payloadSize,
                    int flags,
                    List options)
Description copied from interface: Resolver
Sets the EDNS information on outgoing messages.

Specified by:
setEDNS in interface Resolver
Parameters:
level - The EDNS level 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:
OPTRecord

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(int secs,
                       int msecs)
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.
msecs - The number of milliseconds to wait.

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 and waits for a response. Multiple servers are queried, and queries are sent multiple times until either a successful response is received, or it is clear that there is no successful response.

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 multiple servers, potentially multiple times, 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

getResolver

public Resolver getResolver(int n)
Returns the nth resolver used by this ExtendedResolver


getResolvers

public Resolver[] getResolvers()
Returns all resolvers used by this ExtendedResolver


addResolver

public void addResolver(Resolver r)
Adds a new resolver to be used by this ExtendedResolver


deleteResolver

public void deleteResolver(Resolver r)
Deletes a resolver used by this ExtendedResolver


setLoadBalance

public void setLoadBalance(boolean flag)
Sets whether the servers should be load balanced.

Parameters:
flag - If true, servers will be tried in round-robin order. If false, servers will always be queried in the same order.

setRetries

public void setRetries(int retries)
Sets the number of retries sent to each server per query