Class NetworkUtil


  • public class NetworkUtil
    extends java.lang.Object
    Network utilities class.
    • Constructor Summary

      Constructors 
      Constructor Description
      NetworkUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int findAvailablePort​(java.lang.String hostname, int startPort, int endPort)
      Finds an available port within a port range on a host
      static void waitUntilPortListening​(java.lang.String hostname, int port, int timeout)
      Waits until a port is listening on a given host.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NetworkUtil

        public NetworkUtil()
    • Method Detail

      • findAvailablePort

        public static int findAvailablePort​(java.lang.String hostname,
                                            int startPort,
                                            int endPort)
        Finds an available port within a port range on a host
        Parameters:
        hostname - Host name
        startPort - Port number starting the range
        endPort - Port number ending the range
        Returns:
        An available port number, or 0 if none is available.
      • waitUntilPortListening

        public static void waitUntilPortListening​(java.lang.String hostname,
                                                  int port,
                                                  int timeout)
                                           throws java.io.IOException
        Waits until a port is listening on a given host. An exception is thrown if the timeout is excedeed.
        Parameters:
        hostname - Host name
        port - Port number
        timeout - Timeout in seconds
        Throws:
        java.io.IOException - If a connection error occurs or if the timeout is exceeded