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.handler.codec.dns.DnsQuestion;
19 import io.netty5.handler.codec.dns.DnsResponseCode;
20 import io.netty5.util.concurrent.Future;
21
22 import java.net.InetSocketAddress;
23 import java.util.List;
24
25 import static java.util.Objects.requireNonNull;
26
27
28
29
30 public final class BiDnsQueryLifecycleObserver implements DnsQueryLifecycleObserver {
31 private final DnsQueryLifecycleObserver a;
32 private final DnsQueryLifecycleObserver b;
33
34
35
36
37
38
39 public BiDnsQueryLifecycleObserver(DnsQueryLifecycleObserver a, DnsQueryLifecycleObserver b) {
40 this.a = requireNonNull(a, "a");
41 this.b = requireNonNull(b, "b");
42 }
43
44 @Override
45 public void queryWritten(InetSocketAddress dnsServerAddress, Future<Void> future) {
46 try {
47 a.queryWritten(dnsServerAddress, future);
48 } finally {
49 b.queryWritten(dnsServerAddress, future);
50 }
51 }
52
53 @Override
54 public void queryCancelled(int queriesRemaining) {
55 try {
56 a.queryCancelled(queriesRemaining);
57 } finally {
58 b.queryCancelled(queriesRemaining);
59 }
60 }
61
62 @Override
63 public DnsQueryLifecycleObserver queryRedirected(List<InetSocketAddress> nameServers) {
64 try {
65 a.queryRedirected(nameServers);
66 } finally {
67 b.queryRedirected(nameServers);
68 }
69 return this;
70 }
71
72 @Override
73 public DnsQueryLifecycleObserver queryCNAMEd(DnsQuestion cnameQuestion) {
74 try {
75 a.queryCNAMEd(cnameQuestion);
76 } finally {
77 b.queryCNAMEd(cnameQuestion);
78 }
79 return this;
80 }
81
82 @Override
83 public DnsQueryLifecycleObserver queryNoAnswer(DnsResponseCode code) {
84 try {
85 a.queryNoAnswer(code);
86 } finally {
87 b.queryNoAnswer(code);
88 }
89 return this;
90 }
91
92 @Override
93 public void queryFailed(Throwable cause) {
94 try {
95 a.queryFailed(cause);
96 } finally {
97 b.queryFailed(cause);
98 }
99 }
100
101 @Override
102 public void querySucceed() {
103 try {
104 a.querySucceed();
105 } finally {
106 b.querySucceed();
107 }
108 }
109 }