Package org.apache.cassandra.locator
Class InetAddressAndPort
- java.lang.Object
-
- java.net.SocketAddress
-
- java.net.InetSocketAddress
-
- org.apache.cassandra.locator.InetAddressAndPort
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<InetAddressAndPort>
public final class InetAddressAndPort extends java.net.InetSocketAddress implements java.lang.Comparable<InetAddressAndPort>, java.io.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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InetAddressAndPort.FwdFrmSerializer
Serializer for handling FWD_FRM message parameters.static class
InetAddressAndPort.Serializer
As of version 4.0 the endpoint description includes a port number as an unsigned short
-
Field Summary
Fields Modifier and Type Field Description byte[]
addressBytes
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(InetAddressAndPort o)
static java.util.List<InetAddressAndPort>
getAllByName(java.lang.String name)
static java.util.List<InetAddressAndPort>
getAllByNameOverrideDefaults(java.lang.String name, java.lang.Integer port)
static InetAddressAndPort
getByAddress(byte[] address)
static InetAddressAndPort
getByAddress(java.net.InetAddress address)
static InetAddressAndPort
getByAddress(java.net.InetSocketAddress address)
static InetAddressAndPort
getByAddressOverrideDefaults(java.net.InetAddress address, byte[] addressBytes, java.lang.Integer port)
static InetAddressAndPort
getByAddressOverrideDefaults(java.net.InetAddress address, java.lang.Integer port)
static InetAddressAndPort
getByName(java.lang.String name)
static InetAddressAndPort
getByNameOverrideDefaults(java.lang.String name, java.lang.Integer port)
java.lang.String
getHostAddress(boolean withPort)
java.lang.String
getHostAddressAndPort()
java.lang.String
getHostAddressAndPortForJMX()
Return a version of getHostAddressAndPort suitable for use in JMX object names without requiring any escaping.java.lang.String
getHostName(boolean withPort)
static InetAddressAndPort
getLocalHost()
static InetAddressAndPort
getLoopbackAddress()
static java.lang.String
hostAddress(java.net.InetSocketAddress address, boolean withPort)
static java.lang.String
hostAddressAndPort(java.net.InetSocketAddress address)
static void
initializeDefaultPort(int port)
java.lang.String
toString()
java.lang.String
toString(boolean withPort)
static java.lang.String
toString(java.net.InetAddress address, int port)
Format an InetAddressAndPort in the same style as InetAddress.toString.static java.lang.String
toString(java.net.InetSocketAddress address)
static java.lang.String
toString(java.net.InetSocketAddress address, boolean withPort)
InetAddressAndPort
withPort(int port)
-
-
-
Method Detail
-
withPort
public InetAddressAndPort withPort(int port)
-
compareTo
public int compareTo(InetAddressAndPort o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<InetAddressAndPort>
-
getHostAddressAndPort
public java.lang.String getHostAddressAndPort()
-
getHostAddressAndPortForJMX
public java.lang.String 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
public java.lang.String getHostAddress(boolean withPort)
-
getHostName
public java.lang.String getHostName(boolean withPort)
-
hostAddressAndPort
public static java.lang.String hostAddressAndPort(java.net.InetSocketAddress address)
-
hostAddress
public static java.lang.String hostAddress(java.net.InetSocketAddress address, boolean withPort)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.net.InetSocketAddress
-
toString
public java.lang.String toString(boolean withPort)
-
toString
public static java.lang.String toString(java.net.InetSocketAddress address)
-
toString
public static java.lang.String toString(java.net.InetSocketAddress address, boolean withPort)
-
toString
public static java.lang.String toString(java.net.InetAddress address, int port)
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
public static InetAddressAndPort getByName(java.lang.String name) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
getAllByName
public static java.util.List<InetAddressAndPort> getAllByName(java.lang.String name) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
getAllByNameOverrideDefaults
public static java.util.List<InetAddressAndPort> getAllByNameOverrideDefaults(java.lang.String name, java.lang.Integer port) throws java.net.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:
java.net.UnknownHostException
-
getByNameOverrideDefaults
public static InetAddressAndPort getByNameOverrideDefaults(java.lang.String name, java.lang.Integer port) throws java.net.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:
java.net.UnknownHostException
-
getByAddress
public static InetAddressAndPort getByAddress(byte[] address) throws java.net.UnknownHostException
- Throws:
java.net.UnknownHostException
-
getByAddress
public static InetAddressAndPort getByAddress(java.net.InetAddress address)
-
getByAddress
public static InetAddressAndPort getByAddress(java.net.InetSocketAddress address)
-
getByAddressOverrideDefaults
public static InetAddressAndPort getByAddressOverrideDefaults(java.net.InetAddress address, java.lang.Integer port)
-
getByAddressOverrideDefaults
public static InetAddressAndPort getByAddressOverrideDefaults(java.net.InetAddress address, byte[] addressBytes, java.lang.Integer port)
-
getLoopbackAddress
public static InetAddressAndPort getLoopbackAddress()
-
getLocalHost
public static InetAddressAndPort getLocalHost()
-
initializeDefaultPort
public static void initializeDefaultPort(int port)
-
-