Class InetAddressAndPort

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<InetAddressAndPort>

    public final class InetAddressAndPort
    extends java.lang.Object
    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
    • Field Detail

      • address

        public final java.net.InetAddress address
      • addressBytes

        public final byte[] addressBytes
      • port

        public final int port
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • 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)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(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 String
        port - 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
      • getByNameOverrideDefaults

        public static InetAddressAndPort getByNameOverrideDefaults​(java.lang.String name,
                                                                   java.lang.Integer port)
                                                            throws java.net.UnknownHostException
        Parameters:
        name - Hostname + optional ports string
        port - 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)
      • 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)
      • initializeDefaultPort

        public static void initializeDefaultPort​(int port)