1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty5.resolver;
18
19 import io.netty5.util.concurrent.EventExecutor;
20 import io.netty5.util.concurrent.Future;
21 import io.netty5.util.concurrent.Promise;
22
23 import java.util.List;
24
25 import static java.util.Objects.requireNonNull;
26
27
28
29
30 public abstract class SimpleNameResolver<T> implements NameResolver<T> {
31
32 private final EventExecutor executor;
33
34
35
36
37
38 protected SimpleNameResolver(EventExecutor executor) {
39 this.executor = requireNonNull(executor, "executor");
40 }
41
42
43
44
45
46 protected EventExecutor executor() {
47 return executor;
48 }
49
50 @Override
51 public final Future<T> resolve(String inetHost) {
52 final Promise<T> promise = executor().newPromise();
53 return resolve(inetHost, promise);
54 }
55
56 @Override
57 public Future<T> resolve(String inetHost, Promise<T> promise) {
58 requireNonNull(promise, "promise");
59
60 try {
61 doResolve(inetHost, promise);
62 } catch (Exception e) {
63 promise.setFailure(e);
64 }
65 return promise.asFuture();
66 }
67
68 @Override
69 public final Future<List<T>> resolveAll(String inetHost) {
70 final Promise<List<T>> promise = executor().newPromise();
71 return resolveAll(inetHost, promise);
72 }
73
74 @Override
75 public Future<List<T>> resolveAll(String inetHost, Promise<List<T>> promise) {
76 requireNonNull(promise, "promise");
77
78 try {
79 doResolveAll(inetHost, promise);
80 } catch (Exception e) {
81 promise.setFailure(e);
82 }
83 return promise.asFuture();
84 }
85
86
87
88
89 protected abstract void doResolve(String inetHost, Promise<T> promise) throws Exception;
90
91
92
93
94 protected abstract void doResolveAll(String inetHost, Promise<List<T>> promise) throws Exception;
95
96 @Override
97 public void close() { }
98 }