public abstract class AbstractDnsClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
AbstractDnsClient.IpVersionSetting |
Modifier and Type | Field and Description |
---|---|
protected DnsCache |
cache
The internal DNS cache.
|
protected DnsDataSource |
dataSource |
protected static LruCache |
DEFAULT_CACHE |
protected static AbstractDnsClient.IpVersionSetting |
DEFAULT_IP_VERSION_SETTING |
protected Random |
insecureRandom |
protected AbstractDnsClient.IpVersionSetting |
ipVersionSetting |
protected static Logger |
LOGGER |
protected Random |
random
The internal random class for sequence generation.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractDnsClient()
Create a new DNS client using the global default cache.
|
protected |
AbstractDnsClient(DnsCache cache)
Create a new DNS client with the given DNS cache.
|
Modifier and Type | Method and Description |
---|---|
DnsCache |
getCache()
Get the cache used by this DNS client.
|
Set<A> |
getCachedIPv4AddressesFor(DnsName dnsName) |
Set<A> |
getCachedIPv4NameserverAddressesFor(DnsName dnsName) |
Set<AAAA> |
getCachedIPv6AddressesFor(DnsName dnsName) |
Set<AAAA> |
getCachedIPv6NameserverAddressesFor(DnsName dnsName) |
Set<NS> |
getCachedNameserverRecordsFor(DnsName dnsName) |
DnsDataSource |
getDataSource()
Returns the currently used
DnsDataSource . |
AbstractDnsClient.IpVersionSetting |
getPreferedIpVersion() |
protected DnsMessage |
getQueryFor(Question q) |
protected boolean |
isResponseCacheable(Question q,
DnsMessage dnsMessage)
Whether a response from the DNS system should be cached or not.
|
protected abstract DnsMessage.Builder |
newQuestion(DnsMessage.Builder questionMessage) |
DnsMessage |
query(CharSequence name,
Record.TYPE type)
Query the system nameservers for a single entry of the class IN
(which is used for MX, SRV, A, AAAA and most other RRs).
|
protected abstract DnsMessage |
query(DnsMessage.Builder query)
Send a query request to the DNS system.
|
DnsMessage |
query(DnsMessage query,
InetAddress host) |
DnsMessage |
query(DnsMessage requestMessage,
InetAddress address,
int port) |
DnsMessage |
query(DnsName name,
Record.TYPE type)
Query the system nameservers for a single entry of the class IN
(which is used for MX, SRV, A, AAAA and most other RRs).
|
DnsMessage |
query(Question q) |
DnsMessage |
query(Question q,
InetAddress address)
Query a specific server for one entry.
|
DnsMessage |
query(Question q,
InetAddress server,
int port) |
DnsMessage |
query(String name,
Record.TYPE type,
InetAddress address)
Query a nameserver for a single entry of class IN.
|
DnsMessage |
query(String name,
Record.TYPE type,
Record.CLASS clazz)
Query the system nameservers for a single entry of any class.
|
DnsMessage |
query(String name,
Record.TYPE type,
Record.CLASS clazz,
InetAddress address)
Query a nameserver for a single entry.
|
DnsMessage |
query(String name,
Record.TYPE type,
Record.CLASS clazz,
InetAddress address,
int port)
Query a nameserver for a single entry.
|
MiniDnsFuture<DnsMessage,IOException> |
queryAsync(CharSequence name,
Record.TYPE type) |
protected MiniDnsFuture<DnsMessage,IOException> |
queryAsync(DnsMessage.Builder query)
Default implementation of an asynchronous DNS query which just wraps the synchronous case.
|
MiniDnsFuture<DnsMessage,IOException> |
queryAsync(DnsMessage query,
InetAddress dnsServer) |
MiniDnsFuture<DnsMessage,IOException> |
queryAsync(DnsMessage requestMessage,
InetAddress address,
int port) |
MiniDnsFuture<DnsMessage,IOException> |
queryAsync(Question q) |
void |
setDataSource(DnsDataSource dataSource)
Set a
DnsDataSource to be used by the DnsClient. |
static void |
setDefaultIpVersion(AbstractDnsClient.IpVersionSetting preferedIpVersion) |
void |
setPreferedIpVersion(AbstractDnsClient.IpVersionSetting preferedIpVersion) |
protected static final LruCache DEFAULT_CACHE
protected final Random insecureRandom
protected DnsDataSource dataSource
protected static AbstractDnsClient.IpVersionSetting DEFAULT_IP_VERSION_SETTING
protected AbstractDnsClient.IpVersionSetting ipVersionSetting
protected AbstractDnsClient(DnsCache cache)
cache
- The backend DNS cache.protected AbstractDnsClient()
public static void setDefaultIpVersion(AbstractDnsClient.IpVersionSetting preferedIpVersion)
public void setPreferedIpVersion(AbstractDnsClient.IpVersionSetting preferedIpVersion)
public AbstractDnsClient.IpVersionSetting getPreferedIpVersion()
public final DnsMessage query(String name, Record.TYPE type, Record.CLASS clazz) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).IOException
- if an IO error occurs.public final DnsMessage query(DnsName name, Record.TYPE type) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).IOException
- if an IO error occurs.public final DnsMessage query(CharSequence name, Record.TYPE type) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).IOException
- if an IO error occurs.public DnsMessage query(Question q) throws IOException
IOException
protected abstract DnsMessage query(DnsMessage.Builder query) throws IOException
query
- The query to send to the server.IOException
- if an IO error occurs.public final MiniDnsFuture<DnsMessage,IOException> queryAsync(CharSequence name, Record.TYPE type)
public final MiniDnsFuture<DnsMessage,IOException> queryAsync(Question q)
protected MiniDnsFuture<DnsMessage,IOException> queryAsync(DnsMessage.Builder query)
Subclasses override this method to support true asynchronous queries.
query
- the query.public final DnsMessage query(Question q, InetAddress server, int port) throws IOException
IOException
public final DnsMessage query(DnsMessage requestMessage, InetAddress address, int port) throws IOException
IOException
public final MiniDnsFuture<DnsMessage,IOException> queryAsync(DnsMessage requestMessage, InetAddress address, int port)
protected boolean isResponseCacheable(Question q, DnsMessage dnsMessage)
q
- The question the response message should answer.dnsMessage
- The response message received using the DNS client.protected abstract DnsMessage.Builder newQuestion(DnsMessage.Builder questionMessage)
public DnsMessage query(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address, int port) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).address
- The DNS server address.port
- The DNS server port.IOException
- On IO Errors.public DnsMessage query(String name, Record.TYPE type, Record.CLASS clazz, InetAddress address) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).clazz
- The class of the request (usually IN for Internet).address
- The DNS server host.IOException
- On IO Errors.public DnsMessage query(String name, Record.TYPE type, InetAddress address) throws IOException
name
- The DNS name to request.type
- The DNS type to request (SRV, A, AAAA, ...).address
- The DNS server host.IOException
- On IO Errors.public final DnsMessage query(DnsMessage query, InetAddress host) throws IOException
IOException
public DnsMessage query(Question q, InetAddress address) throws IOException
q
- The question section of the DNS query.address
- The dns server address.IOException
- On IOErrors.public final MiniDnsFuture<DnsMessage,IOException> queryAsync(DnsMessage query, InetAddress dnsServer)
public DnsDataSource getDataSource()
DnsDataSource
. See setDataSource(DnsDataSource)
for details.DnsDataSource
public void setDataSource(DnsDataSource dataSource)
DnsDataSource
to be used by the DnsClient.
The default implementation will direct all queries directly to the Internet.
This can be used to define a non-default handling for outgoing data. This can be useful to redirect the requests
to a proxy or to modify requests after or responses before they are handled by the DnsClient implementation.dataSource
- An implementation of DNSDataSource that shall be used.public DnsCache getCache()
null
.protected DnsMessage getQueryFor(Question q)
public Set<NS> getCachedNameserverRecordsFor(DnsName dnsName)
public Set<A> getCachedIPv4AddressesFor(DnsName dnsName)
public Set<AAAA> getCachedIPv6AddressesFor(DnsName dnsName)
public Set<A> getCachedIPv4NameserverAddressesFor(DnsName dnsName)
public Set<AAAA> getCachedIPv6NameserverAddressesFor(DnsName dnsName)