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 import io.netty.util.internal.UnstableApi;
23
24 import java.util.List;
25
26 import static io.netty.util.internal.ObjectUtil.*;
27
28
29
30
31 @UnstableApi
32 public abstract class SimpleNameResolver<T> implements NameResolver<T> {
33
34 private final EventExecutor executor;
35
36
37
38
39
40 protected SimpleNameResolver(EventExecutor executor) {
41 this.executor = checkNotNull(executor, "executor");
42 }
43
44
45
46
47
48 protected EventExecutor executor() {
49 return executor;
50 }
51
52 @Override
53 public final Future<T> resolve(String inetHost) {
54 final Promise<T> promise = executor().newPromise();
55 return resolve(inetHost, promise);
56 }
57
58 @Override
59 public Future<T> resolve(String inetHost, Promise<T> promise) {
60 checkNotNull(promise, "promise");
61
62 try {
63 doResolve(inetHost, promise);
64 return promise;
65 } catch (Exception e) {
66 return promise.setFailure(e);
67 }
68 }
69
70 @Override
71 public final Future<List<T>> resolveAll(String inetHost) {
72 final Promise<List<T>> promise = executor().newPromise();
73 return resolveAll(inetHost, promise);
74 }
75
76 @Override
77 public Future<List<T>> resolveAll(String inetHost, Promise<List<T>> promise) {
78 checkNotNull(promise, "promise");
79
80 try {
81 doResolveAll(inetHost, promise);
82 return promise;
83 } catch (Exception e) {
84 return promise.setFailure(e);
85 }
86 }
87
88
89
90
91 protected abstract void doResolve(String inetHost, Promise<T> promise) throws Exception;
92
93
94
95
96 protected abstract void doResolveAll(String inetHost, Promise<List<T>> promise) throws Exception;
97
98 @Override
99 public void close() { }
100 }