1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.resolver.dns;
17
18 import io.netty5.channel.EventLoop;
19 import io.netty5.handler.codec.dns.DnsRecord;
20
21 import java.net.InetAddress;
22 import java.util.Collections;
23 import java.util.List;
24
25
26
27
28 public final class NoopDnsCache implements DnsCache {
29
30 public static final NoopDnsCache INSTANCE = new NoopDnsCache();
31
32
33
34
35 private NoopDnsCache() {
36 }
37
38 @Override
39 public void clear() {
40 }
41
42 @Override
43 public boolean clear(String hostname) {
44 return false;
45 }
46
47 @Override
48 public List<? extends DnsCacheEntry> get(String hostname, DnsRecord[] additionals) {
49 return Collections.emptyList();
50 }
51
52 @Override
53 public DnsCacheEntry cache(String hostname, DnsRecord[] additional,
54 InetAddress address, long originalTtl, EventLoop loop) {
55 return new NoopDnsCacheEntry(address);
56 }
57
58 @Override
59 public DnsCacheEntry cache(String hostname, DnsRecord[] additional, Throwable cause, EventLoop loop) {
60 return null;
61 }
62
63 @Override
64 public String toString() {
65 return NoopDnsCache.class.getSimpleName();
66 }
67
68 private static final class NoopDnsCacheEntry implements DnsCacheEntry {
69 private final InetAddress address;
70
71 NoopDnsCacheEntry(InetAddress address) {
72 this.address = address;
73 }
74
75 @Override
76 public InetAddress address() {
77 return address;
78 }
79
80 @Override
81 public Throwable cause() {
82 return null;
83 }
84
85 @Override
86 public String toString() {
87 return address.toString();
88 }
89 }
90 }