View Javadoc
1   /*
2    * Copyright 2016 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.channel.EventLoop;
19  import io.netty.handler.codec.dns.DnsRecord;
20  
21  import java.net.InetAddress;
22  import java.util.List;
23  
24  /**
25   * A cache for DNS resolution entries.
26   */
27  public interface DnsCache {
28  
29      /**
30       * Clears all the resolved addresses cached by this resolver.
31       *
32       * @see #clear(String)
33       */
34      void clear();
35  
36      /**
37       * Clears the resolved addresses of the specified host name from the cache of this resolver.
38       *
39       * @return {@code true} if and only if there was an entry for the specified host name in the cache and
40       *         it has been removed by this method
41       */
42      boolean clear(String hostname);
43  
44      /**
45       * Return the cached entries for the given hostname.
46       * @param hostname the hostname
47       * @param additionals the additional records
48       * @return the cached entries
49       */
50      List<? extends DnsCacheEntry> get(String hostname, DnsRecord[] additionals);
51  
52      /**
53       * Create a new {@link DnsCacheEntry} and cache a resolved address for a given hostname.
54       * @param hostname the hostname
55       * @param additionals the additional records
56       * @param address the resolved address
57       * @param originalTtl the TLL as returned by the DNS server
58       * @param loop the {@link EventLoop} used to register the TTL timeout
59       * @return The {@link DnsCacheEntry} corresponding to this cache entry.
60       */
61      DnsCacheEntry cache(String hostname, DnsRecord[] additionals, InetAddress address, long originalTtl,
62                          EventLoop loop);
63  
64      /**
65       * Cache the resolution failure for a given hostname.
66       * Be aware this <strong>won't</strong> be called with timeout / cancel / transport exceptions.
67        *
68       * @param hostname the hostname
69       * @param additionals the additional records
70       * @param cause the resolution failure
71       * @param loop the {@link EventLoop} used to register the TTL timeout
72       * @return The {@link DnsCacheEntry} corresponding to this cache entry, or {@code null} if this cache doesn't
73       * support caching failed responses.
74       */
75      DnsCacheEntry cache(String hostname, DnsRecord[] additionals, Throwable cause, EventLoop loop);
76  }