private < T > T execute ( UriComponentsBuilder uriTemplate , HttpMethod method , MultiValueMap < String , String > requestData , Class < T > responseType ) throws EtcdException { long startTimeMillis = System . currentTimeMillis ( ) ; int retry = - 1 ; ResourceAccessException lastException = null ; do { lastException = null ; URI uri = uriTemplate . buildAndExpand ( locations [ locationIndex ] ) . toUri ( ) ; RequestEntity < MultiValueMap < String , String > > requestEntity = new RequestEntity <> ( requestData , null , method , uri ) ; try { ResponseEntity < T > responseEntity = template . exchange ( requestEntity , responseType ) ; return responseEntity . getBody ( ) ; } catch ( HttpStatusCodeException e ) { EtcdError error = null ; try { error = responseConverter . getObjectMapper ( ) . readValue ( e . getResponseBodyAsByteArray ( ) , EtcdError . class ) ; } catch ( IOException ex ) { error = null ; } throw new EtcdException ( error , "Failed to execute " + requestEntity + "." , e ) ; } catch ( ResourceAccessException e ) { log . debug ( "Failed to execute " + requestEntity + ", retrying if possible." , e ) ; if ( locationIndex == locations . length - 1 ) { locationIndex = 0 ; } else { locationIndex ++ ; } lastException = e ; } } while ( retry <= retryCount && System . currentTimeMillis ( ) - startTimeMillis < retryDuration ) ; if ( lastException != null ) { throw lastException ; } else { return null ; } }
Executes the given method on the given location using the given request data .