Class NetUtil


  • public class NetUtil
    extends Object
    This class is taken from the Netty project, and all credit goes to them. It has been modified, to remove dependencies on other classes, and to convert to methods, rather than a static value. The getAllLocalIPs() method was taken from the Apache Curator project which is also under the Apache 2.0 license.
    • Constructor Detail

      • NetUtil

        public NetUtil()
    • Method Detail

      • getTcpBacklog

        public static int getTcpBacklog()
        The SOMAXCONN value of the current machine. If failed to get the value, 200 is used as a default value for Windows or 128 for others.
      • getTcpBacklog

        public static int getTcpBacklog​(int tcpBacklog)
        The SOMAXCONN value of the current machine. If failed to get the value, defaultBacklog argument is used
      • isWindows

        public static boolean isWindows()
      • getDefaultTcpBacklog

        public static int getDefaultTcpBacklog()
      • setLocalIpFilter

        public static void setLocalIpFilter​(LocalIpFilter newLocalIpFilter)
        Replace the default local ip filter used by getAllLocalIPs()
        Parameters:
        newLocalIpFilter - the new local ip filter
      • getLocalIpFilter

        public static LocalIpFilter getLocalIpFilter()
        Return the current local ip filter used by getAllLocalIPs()
        Returns:
        ip filter
      • getAllLocalIPs

        public static Collection<InetAddress> getAllLocalIPs()
                                                      throws SocketException
        based on http://pastebin.com/5X073pUc

        Returns all available IP addresses.

        In error case or if no network connection is established, we return an empty list here.

        Loopback addresses are excluded - so 127.0.0.1 will not be never returned.

        The "primary" IP might not be the first one in the returned list.

        Returns:
        Returns all IP addresses (can be an empty list in error case or if network connection is missing).
        Throws:
        SocketException - errors
        See Also:
        getAllLocalIPs, ServiceInstanceBuilder.java