Class ConnectionUtils


  • public class ConnectionUtils
    extends Object
    Utilities to determine the network interface and address that should be used to bind the TaskManager communication to.

    Implementation note: This class uses System.nanoTime() to measure elapsed time, because that is not susceptible to clock changes.

    • Constructor Detail

      • ConnectionUtils

        public ConnectionUtils()
    • Method Detail

      • findConnectingAddress

        public static InetAddress findConnectingAddress​(InetSocketAddress targetAddress,
                                                        long maxWaitMillis,
                                                        long startLoggingAfter)
                                                 throws IOException
        Finds the local network address from which this machine can connect to the target address. This method tries to establish a proper network connection to the given target, so it only succeeds if the target socket address actually accepts connections. The method tries various strategies multiple times and uses an exponential backoff timer between tries.

        If no connection attempt was successful after the given maximum time, the method will choose some address based on heuristics (excluding link-local and loopback addresses.)

        This method will initially not log on info level (to not flood the log while the backoff time is still very low). It will start logging after a certain time has passes.

        Parameters:
        targetAddress - The address that the method tries to connect to.
        maxWaitMillis - The maximum time that this method tries to connect, before falling back to the heuristics.
        startLoggingAfter - The time after which the method will log on INFO level.
        Throws:
        IOException