private < T extends Request , U > void sendRequest ( T request , BiFunction < Request , Connection , CompletableFuture < U > > sender , Connection connection , Throwable error , CompletableFuture < U > future ) { if ( open ) { if ( error == null ) { if ( connection != null ) { LOGGER . trace ( "{} - Sending {}" , id , request ) ; sender . apply ( request , connection ) . whenComplete ( ( r , e ) -> { if ( e != null || r != null ) { handleResponse ( request , sender , connection , ( Response ) r , e , future ) ; } else { future . complete ( null ) ; } } ) ; } else { future . completeExceptionally ( new ConnectException ( "Failed to connect to the cluster" ) ) ; } } else { LOGGER . trace ( "{} - Resending {}: {}" , id , request , error ) ; resendRequest ( error , request , sender , connection , future ) ; } } }
Sends the given request attempt to the cluster via the given connection if connected .