查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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.netty.resolver.dns;
17  
18  import io.netty.handler.codec.dns.DnsQuestion;
19  import io.netty.util.internal.EmptyArrays;
20  import io.netty.util.internal.ObjectUtil;
21  
22  import java.net.InetSocketAddress;
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);
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);
43          this.remoteAddress = validateRemoteAddress(remoteAddress);
44          this.question = validateQuestion(question);
45      }
46  
47      private static InetSocketAddress validateRemoteAddress(InetSocketAddress remoteAddress) {
48          return ObjectUtil.checkNotNull(remoteAddress, "remoteAddress");
49      }
50  
51      private static DnsQuestion validateQuestion(DnsQuestion question) {
52          return ObjectUtil.checkNotNull(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  
69      // Suppress a warning since the method doesn't need synchronization
70      @Override
71      public Throwable fillInStackTrace() {
72          setStackTrace(EmptyArrays.EMPTY_STACK_TRACE);
73          return this;
74      }
75  }