View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.resolver.dns;
17  
18  /**
19   * Represents options defined in a file of the format <a href=https://linux.die.net/man/5/resolver>etc/resolv.conf</a>.
20   */
21  final class UnixResolverOptions {
22  
23      private final int ndots;
24      private final int timeout;
25      private final int attempts;
26  
27      UnixResolverOptions(int ndots, int timeout, int attempts) {
28          this.ndots = ndots;
29          this.timeout = timeout;
30          this.attempts = attempts;
31      }
32  
33      static UnixResolverOptions.Builder newBuilder() {
34          return new UnixResolverOptions.Builder();
35      }
36  
37      /**
38       * The number of dots which must appear in a name before an initial absolute query is made.
39       * The default value is {@code 1}.
40       */
41      int ndots() {
42          return ndots;
43      }
44  
45      /**
46       * The timeout of each DNS query performed by this resolver (in seconds).
47       * The default value is {@code 5}.
48       */
49      int timeout() {
50          return timeout;
51      }
52  
53      /**
54       * The maximum allowed number of DNS queries to send when resolving a host name.
55       * The default value is {@code 16}.
56       */
57      int attempts() {
58          return attempts;
59      }
60  
61      @Override
62      public String toString() {
63          return getClass().getSimpleName() +
64                  "{ndots=" + ndots +
65                  ", timeout=" + timeout +
66                  ", attempts=" + attempts +
67                  '}';
68      }
69  
70      static final class Builder {
71  
72          private int ndots = 1;
73          private int timeout = 5;
74          private int attempts = 16;
75  
76          private Builder() {
77          }
78  
79          void setNdots(int ndots) {
80              this.ndots = ndots;
81          }
82  
83          void setTimeout(int timeout) {
84              this.timeout = timeout;
85          }
86  
87          void setAttempts(int attempts) {
88              this.attempts = attempts;
89          }
90  
91          UnixResolverOptions build() {
92              return new UnixResolverOptions(ndots, timeout, attempts);
93          }
94      }
95  }