Package org.apache.hadoop.hbase.util
Class Addressing
java.lang.Object
org.apache.hadoop.hbase.util.Addressing
Utility for network addresses, resolving and naming.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Interface for AddressSelectionCondition to check if address is acceptable -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
createHostAndPortStr
(String hostname, int port) Create a host-and-port stringstatic InetSocketAddress
createInetSocketAddressFromHostAndPortStr
(String hostAndPort) Create a socket addressstatic InetAddress
static InetAddress
static InetAddress
private static InetAddress
getIpAddress
(Addressing.AddressSelectionCondition condition) static String
Given an InetSocketAddress object returns a String represent of it.static boolean
isLocalAddress
(InetAddress addr) Given an InetAddress, checks to see if the address is a local address, by comparing the address with all the interfaces on the node.static String
parseHostname
(String hostAndPort) Parse the hostname portion of a host-and-port stringstatic int
Parse the port portion of a host-and-port string
-
Field Details
-
VALID_PORT_REGEX
- See Also:
-
HOSTNAME_PORT_SEPARATOR
- See Also:
-
-
Constructor Details
-
Addressing
public Addressing()
-
-
Method Details
-
createInetSocketAddressFromHostAndPortStr
Create a socket address- Parameters:
hostAndPort
- Formatted as<hostname> ':' <port>
- Returns:
- An InetSocketInstance
-
createHostAndPortStr
Create a host-and-port string- Parameters:
hostname
- Server hostnameport
- Server port- Returns:
- Returns a concatenation of
hostname
andport
in following form:<hostname> ':' <port>
. For example, if hostname isexample.org
and port is 1234, this method will returnexample.org:1234
-
parseHostname
Parse the hostname portion of a host-and-port string- Parameters:
hostAndPort
- Formatted as<hostname> ':' <port>
- Returns:
- The hostname portion of
hostAndPort
-
parsePort
Parse the port portion of a host-and-port string- Parameters:
hostAndPort
- Formatted as<hostname> ':' <port>
- Returns:
- The port portion of
hostAndPort
-
getIpAddress
- Throws:
SocketException
-
getIp4Address
- Throws:
SocketException
-
getIp6Address
- Throws:
SocketException
-
getIpAddress
private static InetAddress getIpAddress(Addressing.AddressSelectionCondition condition) throws SocketException - Throws:
SocketException
-
isLocalAddress
Given an InetAddress, checks to see if the address is a local address, by comparing the address with all the interfaces on the node.- Parameters:
addr
- address to check if it is local node's address- Returns:
- true if the address corresponds to the local node
-
inetSocketAddress2String
Given an InetSocketAddress object returns a String represent of it. This is a util method for Java 17. The toString() function of InetSocketAddress will flag the unresolved address with a substring in the string, which will result in unexpected problem. We should use this util function to get the string when we not sure whether the input address is resolved or not.- Parameters:
address
- address to convert to a "host:port" String.- Returns:
- the String represent of the given address, like "foo:1234".
-