View Javadoc
1   /*
2    * Copyright 2014 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  
17  package io.netty.resolver;
18  
19  import io.netty.util.concurrent.Future;
20  import io.netty.util.concurrent.Promise;
21  
22  import java.io.Closeable;
23  import java.net.SocketAddress;
24  import java.nio.channels.UnsupportedAddressTypeException;
25  
26  /**
27   * Resolves an arbitrary string that represents the name of an endpoint into a {@link SocketAddress}.
28   */
29  public interface NameResolver<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 name into a {@link SocketAddress}.
45       *
46       * @param inetHost the name to resolve
47       * @param inetPort the port number
48       *
49       * @return the {@link SocketAddress} as the result of the resolution
50       */
51      Future<T> resolve(String inetHost, int inetPort);
52  
53      /**
54       * Resolves the specified name into a {@link SocketAddress}.
55       *
56       * @param inetHost the name to resolve
57       * @param inetPort the port number
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(String inetHost, int inetPort, 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 {@link SocketAddress} as the result of the resolution
71       */
72      Future<T> resolve(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 {@link SocketAddress} as the result of the resolution
82       */
83      Future<T> resolve(SocketAddress address, Promise<T> promise);
84  
85      /**
86       * Closes all the resources allocated and used by this resolver.
87       */
88      @Override
89      void close();
90  }