Package org.apache.cassandra.locator
Class InetAddressAndPort
java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
org.apache.cassandra.locator.InetAddressAndPort
- All Implemented Interfaces:
Serializable,Comparable<InetAddressAndPort>
public final class InetAddressAndPort
extends InetSocketAddress
implements Comparable<InetAddressAndPort>, Serializable
A class to replace the usage of InetAddress to identify hosts in the cluster.
Opting for a full replacement class so that in the future if we change the nature
of the identifier the refactor will be easier in that we don't have to change the type
just the methods.
Because an IP might contain multiple C* instances the identification must be done
using the IP + port. InetSocketAddress is undesirable for a couple of reasons. It's not comparable,
it's toString() method doesn't correctly bracket IPv6, it doesn't handle optional default values,
and a couple of other minor behaviors that are slightly less troublesome like handling the
need to sometimes return a port and sometimes not.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSerializer for handling FWD_FRM message parameters.static final classAs of version 4.0 the endpoint description includes a port number as an unsigned short -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintstatic List<InetAddressAndPort>getAllByName(String name) static List<InetAddressAndPort>getAllByNameOverrideDefaults(String name, Integer port) static InetAddressAndPortgetByAddress(byte[] address) static InetAddressAndPortgetByAddress(InetAddress address) static InetAddressAndPortgetByAddress(InetSocketAddress address) static InetAddressAndPortgetByAddressOverrideDefaults(InetAddress address, byte[] addressBytes, Integer port) static InetAddressAndPortgetByAddressOverrideDefaults(InetAddress address, Integer port) static InetAddressAndPortstatic InetAddressAndPortgetByNameOverrideDefaults(String name, Integer port) getHostAddress(boolean withPort) Return a version of getHostAddressAndPort suitable for use in JMX object names without requiring any escaping.getHostName(boolean withPort) static InetAddressAndPortstatic InetAddressAndPortstatic StringhostAddress(InetSocketAddress address, boolean withPort) static StringhostAddressAndPort(InetSocketAddress address) static voidinitializeDefaultPort(int port) static Set<InetAddressAndPort>parseHosts(String value, boolean failOnError) Parses a comma-separated list of hosts to a set ofInetAddressAndPortstringify(Iterable<InetAddressAndPort> endpoints) stringify(Iterable<InetAddressAndPort> endpoints, boolean withPort) toString()toString(boolean withPort) static StringtoString(InetAddress address, int port) Format an InetAddressAndPort in the same style as InetAddress.toString.static StringtoString(InetSocketAddress address) static StringtoString(InetSocketAddress address, boolean withPort) withPort(int port) Methods inherited from class java.net.InetSocketAddress
createUnresolved, equals, getAddress, getHostName, getHostString, getPort, hashCode, isUnresolved
-
Field Details
-
addressBytes
public final byte[] addressBytes
-
-
Method Details
-
withPort
-
compareTo
- Specified by:
compareToin interfaceComparable<InetAddressAndPort>
-
getHostAddressAndPort
-
getHostAddressAndPortForJMX
Return a version of getHostAddressAndPort suitable for use in JMX object names without requiring any escaping. Replaces each character invalid for JMX names with an underscore.- Returns:
- String with JMX-safe representation of the IP address and port
-
getHostAddress
-
getHostName
-
hostAddressAndPort
-
hostAddress
-
toString
- Overrides:
toStringin classInetSocketAddress
-
toString
-
toString
-
toString
-
toString
Format an InetAddressAndPort in the same style as InetAddress.toString. The string returned is of the form: hostname / literal IP address : port (without the whitespace). Literal IPv6 addresses will be wrapped with [ ] to make the port number clear. If the host name is unresolved, no reverse name service lookup is performed. The hostname part will be represented by an empty string.- Parameters:
address- InetAddress to convert Stringport- Port number to convert to String- Returns:
- String representation of the IP address and port
-
getByName
- Throws:
UnknownHostException
-
getAllByName
- Throws:
UnknownHostException
-
getAllByNameOverrideDefaults
public static List<InetAddressAndPort> getAllByNameOverrideDefaults(String name, Integer port) throws UnknownHostException - Parameters:
name- Hostname + optional ports stringport- Port to connect on, overridden by values in hostname string, defaults to DatabaseDescriptor default if not specified anywhere.- Throws:
UnknownHostException
-
getByNameOverrideDefaults
public static InetAddressAndPort getByNameOverrideDefaults(String name, Integer port) throws UnknownHostException - Parameters:
name- Hostname + optional ports stringport- Port to connect on, overridden by values in hostname string, defaults to DatabaseDescriptor default if not specified anywhere.- Throws:
UnknownHostException
-
getByAddress
- Throws:
UnknownHostException
-
getByAddress
-
getByAddress
-
getByAddressOverrideDefaults
-
getByAddressOverrideDefaults
public static InetAddressAndPort getByAddressOverrideDefaults(InetAddress address, byte[] addressBytes, Integer port) -
getLoopbackAddress
-
getLocalHost
-
initializeDefaultPort
public static void initializeDefaultPort(int port) -
stringify
-
stringify
-
parseHosts
Parses a comma-separated list of hosts to a set ofInetAddressAndPort- Parameters:
value- the comma-separated list of hosts to parsefailOnError- whether to fail when encountering an invalid hostname- Returns:
- the set of parsed
InetAddressAndPort
-