public String getHostName ( ) throws IOException , InterruptedException { if ( hostNameCached ) // in the worst case we end up having multiple threads computing the host name simultaneously, but that's not harmful, just wasteful. return cachedHostName ; VirtualChannel channel = getChannel ( ) ; if ( channel == null ) return null ; // can't compute right now for ( String address : channel . call ( new ListPossibleNames ( ) ) ) { try { InetAddress ia = InetAddress . getByName ( address ) ; if ( ! ( ia instanceof Inet4Address ) ) { LOGGER . log ( Level . FINE , "{0} is not an IPv4 address" , address ) ; continue ; } if ( ! ComputerPinger . checkIsReachable ( ia , 3 ) ) { LOGGER . log ( Level . FINE , "{0} didn't respond to ping" , address ) ; continue ; } cachedHostName = ia . getCanonicalHostName ( ) ; hostNameCached = true ; return cachedHostName ; } catch ( IOException e ) { // if a given name fails to parse on this host, we get this error LogRecord lr = new LogRecord ( Level . FINE , "Failed to parse {0}" ) ; lr . setThrown ( e ) ; lr . setParameters ( new Object [ ] { address } ) ; LOGGER . log ( lr ) ; } } // allow the administrator to manually specify the host name as a fallback. HUDSON-5373 cachedHostName = channel . call ( new GetFallbackName ( ) ) ; hostNameCached = true ; return cachedHostName ; }
This method tries to compute the name of the host that s reachable by all the other nodes .