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    *   https://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  
21  import java.io.Closeable;
22  import java.net.SocketAddress;
23  import java.nio.channels.UnsupportedAddressTypeException;
24  import java.util.List;
25  
26  /**
27   * Resolves a possibility unresolved {@link SocketAddress}.
28   */
29  public interface AddressResolver<T extends SocketAddress> extends Closeable {
30  
31    /**
32     * Returns {@code true} if and only if the specified address is supported by this resolved.
33     */
34    boolean isSupported(SocketAddress address);
35  
36    /**
37     * Returns {@code true} if and only if the specified address has been resolved.
38     *
39     * @throws UnsupportedAddressTypeException if the specified address is not supported by this resolver
40     */
41    boolean isResolved(SocketAddress address);
42  
43    /**
44     * Resolves the specified address. If the specified address is resolved already, this method does nothing
45     * but returning the original address.
46     *
47     * @param address the address to resolve
48     *
49     * @return the {@link SocketAddress} as the result of the resolution
50     */
51    Future<T> resolve(SocketAddress address);
52  
53    /**
54     * Resolves the specified address. If the specified address is resolved already, this method does nothing
55     * but returning the original address.
56     *
57     * @param address the address to resolve
58     * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished
59     *
60     * @return the {@link SocketAddress} as the result of the resolution
61     */
62    Future<T> resolve(SocketAddress address, Promise<T> promise);
63  
64    /**
65     * Resolves the specified address. If the specified address is resolved already, this method does nothing
66     * but returning the original address.
67     *
68     * @param address the address to resolve
69     *
70     * @return the list of the {@link SocketAddress}es as the result of the resolution
71     */
72    Future<List<T>> resolveAll(SocketAddress address);
73  
74    /**
75     * Resolves the specified address. If the specified address is resolved already, this method does nothing
76     * but returning the original address.
77     *
78     * @param address the address to resolve
79     * @param promise the {@link Promise} which will be fulfilled when the name resolution is finished
80     *
81     * @return the list of the {@link SocketAddress}es as the result of the resolution
82     */
83    Future<List<T>> resolveAll(SocketAddress address, Promise<List<T>> promise);
84  
85    /**
86     * Closes all the resources allocated and used by this resolver.
87     */
88    @Override
89    void close();
90  }