View Javadoc
1   /*
2    * Copyright 2015 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.resolver;
17  
18  import io.netty.util.concurrent.Future;
19  import io.netty.util.concurrent.Promise;
20  import io.netty.util.internal.UnstableApi;
21  
22  import java.io.Closeable;
23  import java.net.SocketAddress;
24  import java.nio.channels.UnsupportedAddressTypeException;
25  import java.util.List;
26  
27  /**
28   * Resolves a possibility unresolved {@link SocketAddress}.
29   */
30  @UnstableApi
31  public interface AddressResolver<T extends SocketAddress> extends Closeable {
32  
33    /**
34     * Returns {@code true} if and only if the specified address is supported by this resolved.
35     */
36    boolean isSupported(SocketAddress address);
37  
38    /**
39     * Returns {@code true} if and only if the specified address has been resolved.
40     *
41     * @throws UnsupportedAddressTypeException if the specified address is not supported by this resolver
42     */
43    boolean isResolved(SocketAddress address);
44  
45    /**
46     * Resolves the specified address. If the specified address is resolved already, this method does nothing
47     * but returning the original address.
48     *
49     * @param address the address to resolve
50     *
51     * @return the {@link SocketAddress} as the result of the resolution
52     */
53    Future<T> resolve(SocketAddress address);
54  
55    /**
56     * Resolves the specified address. If the specified address is resolved already, this method does nothing
57     * but returning the original address.
58     *
59     * @param address the address to resolve
60     * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished
61     *
62     * @return the {@link SocketAddress} as the result of the resolution
63     */
64    Future<T> resolve(SocketAddress address, Promise<T> promise);
65  
66    /**
67     * Resolves the specified address. If the specified address is resolved already, this method does nothing
68     * but returning the original address.
69     *
70     * @param address the address to resolve
71     *
72     * @return the list of the {@link SocketAddress}es as the result of the resolution
73     */
74    Future<List<T>> resolveAll(SocketAddress address);
75  
76    /**
77     * Resolves the specified address. If the specified address is resolved already, this method does nothing
78     * but returning the original address.
79     *
80     * @param address the address to resolve
81     * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished
82     *
83     * @return the list of the {@link SocketAddress}es as the result of the resolution
84     */
85    Future<List<T>> resolveAll(SocketAddress address, Promise<List<T>> promise);
86  
87    /**
88     * Closes all the resources allocated and used by this resolver.
89     */
90    @Override
91    void close();
92  }