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.netty5.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      static final class Builder {
62  
63          private int ndots = 1;
64          private int timeout = 5;
65          private int attempts = 16;
66  
67          private Builder() {
68          }
69  
70          void setNdots(int ndots) {
71              this.ndots = ndots;
72          }
73  
74          void setTimeout(int timeout) {
75              this.timeout = timeout;
76          }
77  
78          void setAttempts(int attempts) {
79              this.attempts = attempts;
80          }
81  
82          UnixResolverOptions build() {
83              return new UnixResolverOptions(ndots, timeout, attempts);
84          }
85      }
86  }