1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.resolver;
18
19 import io.netty.util.concurrent.EventExecutor;
20 import io.netty.util.concurrent.Future;
21 import io.netty.util.concurrent.Promise;
22
23 import java.util.List;
24
25 import static io.netty.util.internal.ObjectUtil.*;
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 = checkNotNull(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 checkNotNull(promise, "promise");
59
60 try {
61 doResolve(inetHost, promise);
62 return promise;
63 } catch (Exception e) {
64 return promise.setFailure(e);
65 }
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 checkNotNull(promise, "promise");
77
78 try {
79 doResolveAll(inetHost, promise);
80 return promise;
81 } catch (Exception e) {
82 return promise.setFailure(e);
83 }
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 }