Skip to content

Commit

Permalink
Rework the hostname resolution to use Netty AddressResolverGroup so w…
Browse files Browse the repository at this point in the history
…e can use it in Bootstrap and simplify some code
  • Loading branch information
vietj committed May 26, 2016
1 parent 16a586d commit c3f21da
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 246 deletions.
146 changes: 73 additions & 73 deletions src/main/asciidoc/dataobjects.adoc
@@ -1,5 +1,74 @@
= Cheatsheets

[[AddressResolverOptions]]
== AddressResolverOptions

++++
Configuration options for Vert.x hostname resolver. The resolver uses the local <i>hosts</i> file and performs
DNS <i>A</i> and <i>AAAA</i> queries.
++++
'''

[cols=">25%,^25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[cacheMaxTimeToLive]]`cacheMaxTimeToLive`|`Number (int)`|
+++
Set the cache maximum TTL value in seconds. After successful resolution IP addresses are cached with their DNS response TTL,
use this to set a maximum value to all responses TTL.
+++
|[[cacheMinTimeToLive]]`cacheMinTimeToLive`|`Number (int)`|
+++
Set the cache minimum TTL value in seconds. After resolution successful IP addresses are cached with their DNS response TTL,
use this to set a minimum value to all responses TTL.
+++
|[[cacheNegativeTimeToLive]]`cacheNegativeTimeToLive`|`Number (int)`|
+++
Set the negative cache TTL value in seconds. After a failed hostname resolution, DNS queries won't be retried
for a period of time equals to the negative TTL. This allows to reduce the response time of negative replies
and reduce the amount of messages to DNS servers.
+++
|[[hostsPath]]`hostsPath`|`String`|
+++
Set the path of an alternate hosts configuration file to use instead of the one provided by the os.
<p/>
The default value is null, so the operating system hosts config is used.
+++
|[[hostsValue]]`hostsValue`|`Buffer`|
+++
Set an alternate hosts configuration file to use instead of the one provided by the os.
<p/>
The value should contain the hosts content literaly, for instance <i>127.0.0.1 localhost</i>
<p/>
The default value is null, so the operating system hosts config is used.
+++
|[[maxQueries]]`maxQueries`|`Number (int)`|
+++
Set the maximum number of queries when an hostname is resolved.
+++
|[[optResourceEnabled]]`optResourceEnabled`|`Boolean`|
+++
Set to true to enable the automatic inclusion in DNS queries of an optional record that hints
the remote DNS server about how much data the resolver can read per response.
+++
|[[queryTimeout]]`queryTimeout`|`Number (long)`|
+++
Set the query timeout in milliseconds, i.e the amount of time after a query is considered to be failed.
+++
|[[rdFlag]]`rdFlag`|`Boolean`|
+++
Set the DNS queries <i>Recursion Desired</i> flag value.
+++
|[[servers]]`servers`|`Array of String`|
+++
Set the list of DNS server addresses, an address is the IP of the dns server, followed by an optional
colon and a port, e.g <code>8.8.8.8</code> or {code 192.168.0.1:40000}. When the list is empty, the resolver
will use the list of the system DNS server addresses from the environment, if that list cannot be retrieved
it will use Google's public DNS servers <code>"8.8.8.8"</code> and <code>"8.8.4.4"</code>.
+++
|===

[[Argument]]
== Argument

Expand Down Expand Up @@ -499,75 +568,6 @@ Set the last stream id.
+++
|===

[[HostnameResolverOptions]]
== HostnameResolverOptions

++++
Configuration options for Vert.x hostname resolver. The resolver uses the local <i>hosts</i> file and performs
DNS <i>A</i> and <i>AAAA</i> queries.
++++
'''

[cols=">25%,^25%,50%"]
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[cacheMaxTimeToLive]]`cacheMaxTimeToLive`|`Number (int)`|
+++
Set the cache maximum TTL value in seconds. After successful resolution IP addresses are cached with their DNS response TTL,
use this to set a maximum value to all responses TTL.
+++
|[[cacheMinTimeToLive]]`cacheMinTimeToLive`|`Number (int)`|
+++
Set the cache minimum TTL value in seconds. After resolution successful IP addresses are cached with their DNS response TTL,
use this to set a minimum value to all responses TTL.
+++
|[[cacheNegativeTimeToLive]]`cacheNegativeTimeToLive`|`Number (int)`|
+++
Set the negative cache TTL value in seconds. After a failed hostname resolution, DNS queries won't be retried
for a period of time equals to the negative TTL. This allows to reduce the response time of negative replies
and reduce the amount of messages to DNS servers.
+++
|[[hostsPath]]`hostsPath`|`String`|
+++
Set the path of an alternate hosts configuration file to use instead of the one provided by the os.
<p/>
The default value is null, so the operating system hosts config is used.
+++
|[[hostsValue]]`hostsValue`|`Buffer`|
+++
Set an alternate hosts configuration file to use instead of the one provided by the os.
<p/>
The value should contain the hosts content literaly, for instance <i>127.0.0.1 localhost</i>
<p/>
The default value is null, so the operating system hosts config is used.
+++
|[[maxQueries]]`maxQueries`|`Number (int)`|
+++
Set the maximum number of queries when an hostname is resolved.
+++
|[[optResourceEnabled]]`optResourceEnabled`|`Boolean`|
+++
Set to true to enable the automatic inclusion in DNS queries of an optional record that hints
the remote DNS server about how much data the resolver can read per response.
+++
|[[queryTimeout]]`queryTimeout`|`Number (long)`|
+++
Set the query timeout in milliseconds, i.e the amount of time after a query is considered to be failed.
+++
|[[rdFlag]]`rdFlag`|`Boolean`|
+++
Set the DNS queries <i>Recursion Desired</i> flag value.
+++
|[[servers]]`servers`|`Array of String`|
+++
Set the list of DNS server addresses, an address is the IP of the dns server, followed by an optional
colon and a port, e.g <code>8.8.8.8</code> or {code 192.168.0.1:40000}. When the list is empty, the resolver
will use the list of the system DNS server addresses from the environment, if that list cannot be retrieved
it will use Google's public DNS servers <code>"8.8.8.8"</code> and <code>"8.8.4.4"</code>.
+++
|===

[[Http2Settings]]
== Http2Settings

Expand Down Expand Up @@ -1778,6 +1778,10 @@ Set whether Netty pooled buffers are enabled
[frame="topbot"]
|===
^|Name | Type ^| Description
|[[addressResolverOptions]]`addressResolverOptions`|`link:dataobjects.html#AddressResolverOptions[AddressResolverOptions]`|
+++
Sets the address resolver configuration to configure resolving DNS servers, cache TTL, etc...
+++
|[[blockedThreadCheckInterval]]`blockedThreadCheckInterval`|`Number (long)`|
+++
Sets the value of blocked thread check period, in ms.
Expand Down Expand Up @@ -1830,10 +1834,6 @@ Set whether HA will be enabled on the Vert.x instance.
+++
Set the HA group to be used when HA is enabled.
+++
|[[hostnameResolverOptions]]`hostnameResolverOptions`|`link:dataobjects.html#HostnameResolverOptions[HostnameResolverOptions]`|
+++
Sets the hostname resolver configuration to configure resolving DNS servers, cache TTL, etc...
+++
|[[internalBlockingPoolSize]]`internalBlockingPoolSize`|`Number (int)`|
+++
Set the value of internal blocking pool size
Expand Down
14 changes: 7 additions & 7 deletions src/main/asciidoc/java/index.adoc
Expand Up @@ -1290,12 +1290,12 @@ logger.info("something happened");
logger.error("oops!", exception);
----

== Hostname resolution
== Host name resolution

Vert.x uses an an hostname resolver for resolving hostname into IP addresses instead of
Vert.x uses an an address resolver for resolving host name into IP addresses instead of
the JVM built-in blocking resolver.

An hostname are resolve to an IP address using:
An host name resolves to an IP address using:

- the _hosts_ file of the operating system
- otherwise DNS queries against a list of servers
Expand All @@ -1308,8 +1308,8 @@ DNS servers can be also configured when creating a `link:../../apidocs/io/vertx/
[source,java]
----
Vertx vertx = Vertx.vertx(new VertxOptions().
setHostnameResolverOptions(
new HostnameResolverOptions().
setAddressResolverOptions(
new AddressResolverOptions().
addServer("192.168.0.1").
addServer("192.168.0.2:40000"))
);
Expand All @@ -1323,8 +1323,8 @@ The resolver can be configured to use an alternative _hosts_ file:
[source,java]
----
Vertx vertx = Vertx.vertx(new VertxOptions().
setHostnameResolverOptions(
new HostnameResolverOptions().
setAddressResolverOptions(
new AddressResolverOptions().
setHostsPath("/path/to/hosts"))
);
----
Expand Down
12 changes: 6 additions & 6 deletions src/main/generated/io/vertx/core/VertxOptionsConverter.java
Expand Up @@ -27,6 +27,9 @@
public class VertxOptionsConverter {

public static void fromJson(JsonObject json, VertxOptions obj) {
if (json.getValue("addressResolverOptions") instanceof JsonObject) {
obj.setAddressResolverOptions(new io.vertx.core.dns.AddressResolverOptions((JsonObject)json.getValue("addressResolverOptions")));
}
if (json.getValue("blockedThreadCheckInterval") instanceof Number) {
obj.setBlockedThreadCheckInterval(((Number)json.getValue("blockedThreadCheckInterval")).longValue());
}
Expand Down Expand Up @@ -63,9 +66,6 @@ public static void fromJson(JsonObject json, VertxOptions obj) {
if (json.getValue("haGroup") instanceof String) {
obj.setHAGroup((String)json.getValue("haGroup"));
}
if (json.getValue("hostnameResolverOptions") instanceof JsonObject) {
obj.setHostnameResolverOptions(new io.vertx.core.dns.HostnameResolverOptions((JsonObject)json.getValue("hostnameResolverOptions")));
}
if (json.getValue("internalBlockingPoolSize") instanceof Number) {
obj.setInternalBlockingPoolSize(((Number)json.getValue("internalBlockingPoolSize")).intValue());
}
Expand All @@ -90,6 +90,9 @@ public static void fromJson(JsonObject json, VertxOptions obj) {
}

public static void toJson(VertxOptions obj, JsonObject json) {
if (obj.getAddressResolverOptions() != null) {
json.put("addressResolverOptions", obj.getAddressResolverOptions().toJson());
}
json.put("blockedThreadCheckInterval", obj.getBlockedThreadCheckInterval());
if (obj.getClusterHost() != null) {
json.put("clusterHost", obj.getClusterHost());
Expand All @@ -110,9 +113,6 @@ public static void toJson(VertxOptions obj, JsonObject json) {
if (obj.getHAGroup() != null) {
json.put("haGroup", obj.getHAGroup());
}
if (obj.getHostnameResolverOptions() != null) {
json.put("hostnameResolverOptions", obj.getHostnameResolverOptions().toJson());
}
json.put("internalBlockingPoolSize", obj.getInternalBlockingPoolSize());
json.put("maxEventLoopExecuteTime", obj.getMaxEventLoopExecuteTime());
json.put("maxWorkerExecuteTime", obj.getMaxWorkerExecuteTime());
Expand Down
Expand Up @@ -20,13 +20,13 @@
import io.vertx.core.json.JsonArray;

/**
* Converter for {@link io.vertx.core.dns.HostnameResolverOptions}.
* Converter for {@link io.vertx.core.dns.AddressResolverOptions}.
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.dns.HostnameResolverOptions} original class using Vert.x codegen.
* NOTE: This class has been automatically generated from the {@link io.vertx.core.dns.AddressResolverOptions} original class using Vert.x codegen.
*/
public class HostnameResolverOptionsConverter {
public class AddressResolverOptionsConverter {

public static void fromJson(JsonObject json, HostnameResolverOptions obj) {
public static void fromJson(JsonObject json, AddressResolverOptions obj) {
if (json.getValue("cacheMaxTimeToLive") instanceof Number) {
obj.setCacheMaxTimeToLive(((Number)json.getValue("cacheMaxTimeToLive")).intValue());
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void fromJson(JsonObject json, HostnameResolverOptions obj) {
}
}

public static void toJson(HostnameResolverOptions obj, JsonObject json) {
public static void toJson(AddressResolverOptions obj, JsonObject json) {
json.put("cacheMaxTimeToLive", obj.getCacheMaxTimeToLive());
json.put("cacheMinTimeToLive", obj.getCacheMinTimeToLive());
json.put("cacheNegativeTimeToLive", obj.getCacheNegativeTimeToLive());
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/examples/CoreExamples.java
Expand Up @@ -18,7 +18,7 @@

import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.dns.HostnameResolverOptions;
import io.vertx.core.dns.AddressResolverOptions;
import io.vertx.core.file.FileSystem;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
Expand Down Expand Up @@ -303,17 +303,17 @@ public void systemAndEnvProperties() {

public void configureDNSServers() {
Vertx vertx = Vertx.vertx(new VertxOptions().
setHostnameResolverOptions(
new HostnameResolverOptions().
setAddressResolverOptions(
new AddressResolverOptions().
addServer("192.168.0.1").
addServer("192.168.0.2:40000"))
);
}

public void configureHosts() {
Vertx vertx = Vertx.vertx(new VertxOptions().
setHostnameResolverOptions(
new HostnameResolverOptions().
setAddressResolverOptions(
new AddressResolverOptions().
setHostsPath("/path/to/hosts"))
);
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/io/vertx/core/VertxOptions.java
Expand Up @@ -17,7 +17,7 @@
package io.vertx.core;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.dns.HostnameResolverOptions;
import io.vertx.core.dns.AddressResolverOptions;
import io.vertx.core.eventbus.EventBusOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.core.metrics.MetricsOptions;
Expand Down Expand Up @@ -135,7 +135,7 @@ public class VertxOptions {
private MetricsOptions metricsOptions = new MetricsOptions();
private long warningExceptionTime = DEFAULT_WARNING_EXCEPTION_TIME;
private EventBusOptions eventBusOptions = new EventBusOptions();
private HostnameResolverOptions hostnameResolverOptions = new HostnameResolverOptions();
private AddressResolverOptions addressResolverOptions = new AddressResolverOptions();

/**
* Default constructor
Expand All @@ -162,7 +162,7 @@ public VertxOptions(VertxOptions other) {
this.metricsOptions = other.getMetricsOptions() != null ? new MetricsOptions(other.getMetricsOptions()) : null;
this.warningExceptionTime = other.warningExceptionTime;
this.eventBusOptions = new EventBusOptions(other.eventBusOptions);
this.hostnameResolverOptions = other.hostnameResolverOptions != null ? new HostnameResolverOptions() : null;
this.addressResolverOptions = other.addressResolverOptions != null ? new AddressResolverOptions() : null;
}

/**
Expand Down Expand Up @@ -631,20 +631,20 @@ public VertxOptions setEventBusOptions(EventBusOptions options) {
}

/**
* @return the hostname resolver options to configure resolving DNS servers, cache TTL, etc...
* @return the address resolver options to configure resolving DNS servers, cache TTL, etc...
*/
public HostnameResolverOptions getHostnameResolverOptions() {
return hostnameResolverOptions;
public AddressResolverOptions getAddressResolverOptions() {
return addressResolverOptions;
}

/**
* Sets the hostname resolver configuration to configure resolving DNS servers, cache TTL, etc...
* Sets the address resolver configuration to configure resolving DNS servers, cache TTL, etc...
*
* @param hostnameResolverOptions the hostname resolver options
* @param addressResolverOptions the address resolver options
* @return a reference to this, so the API can be used fluently
*/
public VertxOptions setHostnameResolverOptions(HostnameResolverOptions hostnameResolverOptions) {
this.hostnameResolverOptions = hostnameResolverOptions;
public VertxOptions setAddressResolverOptions(AddressResolverOptions addressResolverOptions) {
this.addressResolverOptions = addressResolverOptions;
return this;
}

Expand All @@ -669,7 +669,7 @@ public boolean equals(Object o) {
if (haGroup != null ? !haGroup.equals(that.haGroup) : that.haGroup != null) return false;
if (eventBusOptions != null ? !eventBusOptions.equals(that.eventBusOptions) : that.eventBusOptions != null)
return false;
if (hostnameResolverOptions != null ? !hostnameResolverOptions.equals(that.hostnameResolverOptions) : that.hostnameResolverOptions != null)
if (addressResolverOptions != null ? !addressResolverOptions.equals(that.addressResolverOptions) : that.addressResolverOptions != null)
return false;
return !(metricsOptions != null ? !metricsOptions.equals(that.metricsOptions) : that.metricsOptions != null);

Expand All @@ -689,7 +689,7 @@ public int hashCode() {
result = 31 * result + (haGroup != null ? haGroup.hashCode() : 0);
result = 31 * result + (metricsOptions != null ? metricsOptions.hashCode() : 0);
result = 31 * result + (eventBusOptions != null ? eventBusOptions.hashCode() : 0);
result = 31 * result + (hostnameResolverOptions != null ? hostnameResolverOptions.hashCode() : 0);
result = 31 * result + (addressResolverOptions != null ? addressResolverOptions.hashCode() : 0);
result = 31 * result + (int) (warningExceptionTime ^ (warningExceptionTime >>> 32));
return result;
}
Expand All @@ -708,7 +708,7 @@ public String toString() {
", quorumSize=" + quorumSize +
", haGroup='" + haGroup + '\'' +
", metrics=" + metricsOptions +
", hostnameResolver=" + hostnameResolverOptions.toJson() +
", addressResolver=" + addressResolverOptions.toJson() +
", eventbus=" + eventBusOptions.toJson() +
", warningExceptionTime=" + warningExceptionTime +
'}';
Expand Down

0 comments on commit c3f21da

Please sign in to comment.