2929import java .io .IOException ;
3030
3131import org .apache .hc .client5 .http .HttpRequestRetryStrategy ;
32- import org .apache .hc .client5 .http .HttpRoute ;
3332import org .apache .hc .client5 .http .async .AsyncExecCallback ;
3433import org .apache .hc .client5 .http .async .AsyncExecChain ;
3534import org .apache .hc .client5 .http .async .AsyncExecChainHandler ;
4039import org .apache .hc .core5 .annotation .ThreadingBehavior ;
4140import org .apache .hc .core5 .http .EntityDetails ;
4241import org .apache .hc .core5 .http .HttpException ;
42+ import org .apache .hc .core5 .http .HttpHost ;
4343import org .apache .hc .core5 .http .HttpRequest ;
4444import org .apache .hc .core5 .http .HttpResponse ;
4545import org .apache .hc .core5 .http .nio .AsyncDataConsumer ;
@@ -96,6 +96,7 @@ public AsyncHttpRequestRetryExec(final HttpRequestRetryStrategy retryStrategy) {
9696 private static class State {
9797
9898 volatile boolean retrying ;
99+ volatile int status ;
99100 volatile TimeValue delay ;
100101
101102 }
@@ -125,6 +126,7 @@ public AsyncDataConsumer handleResponse(
125126 }
126127 state .retrying = retryStrategy .retryRequest (response , scope .execCount .get (), clientContext );
127128 if (state .retrying ) {
129+ state .status = response .getCode ();
128130 state .delay = retryStrategy .getRetryInterval (response , scope .execCount .get (), clientContext );
129131 return new DiscardingEntityConsumer <>();
130132 }
@@ -139,13 +141,16 @@ public void handleInformationResponse(final HttpResponse response) throws HttpEx
139141 @ Override
140142 public void completed () {
141143 if (state .retrying ) {
142- scope .execCount .incrementAndGet ();
144+ final int execCount = scope .execCount .incrementAndGet ();
143145 if (entityProducer != null ) {
144146 entityProducer .releaseResources ();
145147 }
148+ final HttpHost target = scope .route .getTargetHost ();
146149 final TimeValue delay = TimeValue .isPositive (state .delay ) ? state .delay : TimeValue .ZERO_MILLISECONDS ;
147- if (LOG .isDebugEnabled ()) {
148- LOG .debug ("{} wait for {}" , exchangeId , delay );
150+ if (LOG .isInfoEnabled ()) {
151+ LOG .info ("{} {} responded with status {}; " +
152+ "request will be automatically re-executed in {} (exec count {})" ,
153+ exchangeId , target , state .status , delay , execCount );
149154 }
150155 scope .scheduler .scheduleExecution (
151156 request ,
@@ -162,7 +167,7 @@ public void completed() {
162167 @ Override
163168 public void failed (final Exception cause ) {
164169 if (cause instanceof IOException ) {
165- final HttpRoute route = scope .route ;
170+ final HttpHost target = scope .route . getTargetHost () ;
166171 final HttpClientContext clientContext = scope .clientContext ;
167172 if (entityProducer != null && !entityProducer .isRepeatable ()) {
168173 if (LOG .isDebugEnabled ()) {
@@ -172,10 +177,6 @@ public void failed(final Exception cause) {
172177 if (LOG .isDebugEnabled ()) {
173178 LOG .debug ("{} {}" , exchangeId , cause .getMessage (), cause );
174179 }
175- if (LOG .isInfoEnabled ()) {
176- LOG .info ("Recoverable I/O exception ({}) caught when processing request to {}" ,
177- cause .getClass ().getName (), route );
178- }
179180 scope .execRuntime .discardEndpoint ();
180181 if (entityProducer != null ) {
181182 entityProducer .releaseResources ();
@@ -184,8 +185,10 @@ public void failed(final Exception cause) {
184185 final int execCount = scope .execCount .incrementAndGet ();
185186 state .delay = retryStrategy .getRetryInterval (request , (IOException ) cause , execCount - 1 , clientContext );
186187 final TimeValue delay = TimeValue .isPositive (state .delay ) ? state .delay : TimeValue .ZERO_MILLISECONDS ;
187- if (LOG .isDebugEnabled ()) {
188- LOG .debug ("{} wait for {}" , exchangeId , delay );
188+ if (LOG .isInfoEnabled ()) {
189+ LOG .info ("{} recoverable I/O exception ({}) caught when sending request to {};" +
190+ "request will be automatically re-executed in {} (exec count {})" ,
191+ exchangeId , cause .getClass ().getName (), target , delay , execCount );
189192 }
190193 scope .scheduler .scheduleExecution (
191194 request ,
0 commit comments