View Javadoc
1   /*
2    * Copyright 2015 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  import io.netty5.handler.codec.dns.DnsQuestion;
19  
20  import java.net.InetSocketAddress;
21  
22  import static java.util.Objects.requireNonNull;
23  
24  /**
25   * A {@link RuntimeException} raised when {@link DnsNameResolver} failed to perform a successful query.
26   */
27  public class DnsNameResolverException extends RuntimeException {
28  
29      private static final long serialVersionUID = -8826717909627131850L;
30  
31      private final InetSocketAddress remoteAddress;
32      private final DnsQuestion question;
33  
34      public DnsNameResolverException(InetSocketAddress remoteAddress, DnsQuestion question, String message) {
35          super(message, null, true, false);
36          this.remoteAddress = validateRemoteAddress(remoteAddress);
37          this.question = validateQuestion(question);
38      }
39  
40      public DnsNameResolverException(
41              InetSocketAddress remoteAddress, DnsQuestion question, String message, Throwable cause) {
42          super(message, cause, true, false);
43          this.remoteAddress = validateRemoteAddress(remoteAddress);
44          this.question = validateQuestion(question);
45      }
46  
47      private static InetSocketAddress validateRemoteAddress(InetSocketAddress remoteAddress) {
48          return requireNonNull(remoteAddress, "remoteAddress");
49      }
50  
51      private static DnsQuestion validateQuestion(DnsQuestion question) {
52          return requireNonNull(question, "question");
53      }
54  
55      /**
56       * Returns the {@link InetSocketAddress} of the DNS query that has failed.
57       */
58      public InetSocketAddress remoteAddress() {
59          return remoteAddress;
60      }
61  
62      /**
63       * Returns the {@link DnsQuestion} of the DNS query that has failed.
64       */
65      public DnsQuestion question() {
66          return question;
67      }
68  }