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