57
57
import org .reactivestreams .Publisher ;
58
58
import org .reactivestreams .Subscriber ;
59
59
import org .reactivestreams .Subscription ;
60
- import org .slf4j .Logger ;
61
- import org .slf4j .LoggerFactory ;
62
60
import software .amazon .awssdk .annotations .SdkInternalApi ;
63
61
import software .amazon .awssdk .http .Protocol ;
64
62
import software .amazon .awssdk .http .nio .netty .internal .http2 .FlushOnReadHandler ;
68
66
import software .amazon .awssdk .http .nio .netty .internal .nrs .HttpStreamsClientHandler ;
69
67
import software .amazon .awssdk .http .nio .netty .internal .nrs .StreamedHttpRequest ;
70
68
import software .amazon .awssdk .http .nio .netty .internal .utils .ChannelUtils ;
69
+ import software .amazon .awssdk .http .nio .netty .internal .utils .NettyClientLogger ;
71
70
import software .amazon .awssdk .http .nio .netty .internal .utils .NettyUtils ;
72
71
import software .amazon .awssdk .metrics .MetricCollector ;
73
72
74
73
@ SdkInternalApi
75
74
public final class NettyRequestExecutor {
76
- private static final Logger log = LoggerFactory .getLogger (NettyRequestExecutor .class );
75
+ private static final NettyClientLogger log = NettyClientLogger .getLogger (NettyRequestExecutor .class );
77
76
private static final RequestAdapter REQUEST_ADAPTER_HTTP2 = new RequestAdapter (Protocol .HTTP2 );
78
77
private static final RequestAdapter REQUEST_ADAPTER_HTTP1_1 = new RequestAdapter (Protocol .HTTP1_1 );
79
78
private static final AtomicLong EXECUTION_COUNTER = new AtomicLong (0L );
@@ -129,7 +128,7 @@ private CompletableFuture<Void> createExecutionFuture(Promise<Channel> channelPr
129
128
}
130
129
});
131
130
} catch (Throwable exc ) {
132
- log .warn ("Unable to add a task to cancel the request to channel's EventLoop" , exc );
131
+ log .warn (ch , () -> "Unable to add a task to cancel the request to channel's EventLoop" , exc );
133
132
}
134
133
}
135
134
});
@@ -151,13 +150,13 @@ private void verifyMetricsWereCollected(CompletableFuture<Void> metricsFuture) {
151
150
}
152
151
153
152
if (!metricsFuture .isDone ()) {
154
- log .debug ("HTTP request metric collection did not finish in time, so results may be incomplete." );
153
+ log .debug (null , () -> "HTTP request metric collection did not finish in time, so results may be incomplete." );
155
154
metricsFuture .cancel (false );
156
155
return ;
157
156
}
158
157
159
158
metricsFuture .exceptionally (t -> {
160
- log .debug ("HTTP request metric collection failed, so results may be incomplete." , t );
159
+ log .debug (null , () -> "HTTP request metric collection failed, so results may be incomplete." , t );
161
160
return null ;
162
161
});
163
162
}
@@ -172,7 +171,7 @@ private void makeRequestListener(Future<Channel> channelFuture) {
172
171
}
173
172
});
174
173
} else {
175
- handleFailure (() -> "Failed to create connection to " + endpoint (), channelFuture .cause ());
174
+ handleFailure (channel , () -> "Failed to create connection to " + endpoint (), channelFuture .cause ());
176
175
}
177
176
}
178
177
@@ -203,7 +202,7 @@ private boolean tryConfigurePipeline() {
203
202
default :
204
203
String errorMsg = "Unknown protocol: " + protocol ;
205
204
closeAndRelease (channel );
206
- handleFailure (() -> errorMsg , new RuntimeException (errorMsg ));
205
+ handleFailure (channel , () -> errorMsg , new RuntimeException (errorMsg ));
207
206
return false ;
208
207
}
209
208
@@ -220,7 +219,7 @@ private boolean tryConfigurePipeline() {
220
219
if (!channel .isActive ()) {
221
220
String errorMessage = "Channel was closed before it could be written to." ;
222
221
closeAndRelease (channel );
223
- handleFailure (() -> errorMessage , new IOException (errorMessage ));
222
+ handleFailure (channel , () -> errorMessage , new IOException (errorMessage ));
224
223
return false ;
225
224
}
226
225
@@ -254,7 +253,7 @@ private void writeRequest(HttpRequest request) {
254
253
} else {
255
254
// TODO: Are there cases where we can keep the channel open?
256
255
closeAndRelease (channel );
257
- handleFailure (() -> "Failed to make request to " + endpoint (), wireCall .cause ());
256
+ handleFailure (channel , () -> "Failed to make request to " + endpoint (), wireCall .cause ());
258
257
}
259
258
});
260
259
@@ -297,8 +296,8 @@ private URI endpoint() {
297
296
return context .executeRequest ().request ().getUri ();
298
297
}
299
298
300
- private void handleFailure (Supplier <String > msg , Throwable cause ) {
301
- log .debug (msg . get () , cause );
299
+ private void handleFailure (Channel channel , Supplier <String > msgSupplier , Throwable cause ) {
300
+ log .debug (channel , msgSupplier , cause );
302
301
cause = decorateException (cause );
303
302
context .handler ().onError (cause );
304
303
executeFuture .completeExceptionally (cause );
@@ -379,7 +378,7 @@ private String getMessageForTooManyAcquireOperationsError() {
379
378
* @param channel The channel.
380
379
*/
381
380
private void closeAndRelease (Channel channel ) {
382
- log .trace ("closing and releasing channel {} " , channel .id ().asLongText ());
381
+ log .trace (channel , () -> String . format ( "closing and releasing channel %s " , channel .id ().asLongText () ));
383
382
channel .attr (KEEP_ALIVE ).set (false );
384
383
channel .close ();
385
384
context .channelPool ().release (channel );
@@ -472,7 +471,7 @@ public String toString() {
472
471
/**
473
472
* Decorator around {@link StreamedHttpRequest} to adapt a publisher of {@link ByteBuffer} (i.e. {@link
474
473
* software.amazon.awssdk.http.async.SdkHttpContentPublisher}) to a publisher of {@link HttpContent}.
475
- * <p / >
474
+ * <p>
476
475
* This publisher also prevents the adapted publisher from publishing more content to the subscriber than
477
476
* the specified 'Content-Length' of the request.
478
477
*/
@@ -565,7 +564,7 @@ private static Optional<Long> contentLength(HttpRequest request) {
565
564
try {
566
565
return Optional .of (Long .parseLong (value ));
567
566
} catch (NumberFormatException e ) {
568
- log .warn ("Unable to parse 'Content-Length' header. Treating it as non existent." );
567
+ log .warn (null , () -> "Unable to parse 'Content-Length' header. Treating it as non existent." );
569
568
}
570
569
}
571
570
return Optional .empty ();
0 commit comments