private SocketChannel createLeaderSocket ( SocketAddress hostAddr , ConnectStrategy mode ) throws IOException { SocketChannel socket ; int connectAttempts = 0 ; do { try { socket = SocketChannel . open ( ) ; socket . socket ( ) . connect ( hostAddr , 5000 ) ; } catch ( java . net . ConnectException | java . nio . channels . UnresolvedAddressException | java . net . NoRouteToHostException | java . net . PortUnreachableException e ) { // reset the socket to null for loop purposes socket = null ; if ( mode == ConnectStrategy . PROBE ) { return null ; } if ( ( ++ connectAttempts % 8 ) == 0 ) { LOG . warn ( "Joining primary failed: " + e + " retrying.." ) ; } try { Thread . sleep ( 250 ) ; // milliseconds } catch ( InterruptedException dontcare ) { } } } while ( socket == null ) ; return socket ; }
Create socket to the leader node