View Javadoc
1   /*
2    * Copyright 2018 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.channel.EventLoop;
19  
20  import java.net.InetSocketAddress;
21  
22  /**
23   * Cache which stores the nameservers that should be used to resolve a specific hostname.
24   */
25  public interface AuthoritativeDnsServerCache {
26  
27      /**
28       * Returns the cached nameservers that should be used to resolve the given hostname. The returned
29       * {@link DnsServerAddressStream} may contain unresolved {@link InetSocketAddress}es that will be resolved
30       * when needed while resolving other domain names.
31       *
32       * @param hostname the hostname
33       * @return the cached entries or an {@code null} if none.
34       */
35      DnsServerAddressStream get(String hostname);
36  
37      /**
38       * Caches a nameserver that should be used to resolve the given hostname.
39       *
40       * @param hostname the hostname
41       * @param address the nameserver address (which may be unresolved).
42       * @param originalTtl the TTL as returned by the DNS server
43       * @param loop the {@link EventLoop} used to register the TTL timeout
44       */
45      void cache(String hostname, InetSocketAddress address, long originalTtl, EventLoop loop);
46  
47      /**
48       * Clears all cached nameservers.
49       *
50       * @see #clear(String)
51       */
52      void clear();
53  
54      /**
55       * Clears the cached nameservers for the specified hostname.
56       *
57       * @return {@code true} if and only if there was an entry for the specified host name in the cache and
58       *         it has been removed by this method
59       */
60      boolean clear(String hostname);
61  }