@@ -159,8 +159,7 @@ private <T> ListenableFuture<T> sendRequestThroughSslProxy(//
159
159
newFuture = newNettyRequestAndResponseFuture (request , asyncHandler , future , uri , proxyServer , false );
160
160
161
161
if (Channels .isChannelValid (channel ))
162
- // if the channel is still active, we can use it, otherwise try
163
- // gain
162
+ // if the channel is still active, we can use it, otherwise try gain
164
163
return sendRequestWithCachedChannel (request , uri , proxyServer , newFuture , asyncHandler , channel );
165
164
else
166
165
// pool is empty
@@ -190,12 +189,15 @@ private Channel getCachedChannel(NettyResponseFuture<?> future, UriComponents ur
190
189
if (future != null && future .reuseChannel () && Channels .isChannelValid (future .channel ()))
191
190
return future .channel ();
192
191
else
193
- return pollAndVerifyCachedChannel (uri , proxyServer , poolKeyGen );
192
+ return pollAndVerifyCachedChannel (uri , proxyServer , poolKeyGen , future . getAsyncHandler () );
194
193
}
195
194
196
195
private <T > ListenableFuture <T > sendRequestWithCachedChannel (Request request , UriComponents uri , ProxyServer proxy , NettyResponseFuture <T > future ,
197
196
AsyncHandler <T > asyncHandler , Channel channel ) throws IOException {
198
197
198
+ if (asyncHandler instanceof AsyncHandlerExtensions )
199
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onConnectionPooled ();
200
+
199
201
future .setState (NettyResponseFuture .STATE .POOLED );
200
202
future .attachChannel (channel , false );
201
203
@@ -254,6 +256,9 @@ private <T> ListenableFuture<T> sendRequestWithNewChannel(//
254
256
channelPreempted = preemptChannel (asyncHandler , poolKey );
255
257
}
256
258
259
+ if (asyncHandler instanceof AsyncHandlerExtensions )
260
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onOpenConnection ();
261
+
257
262
try {
258
263
ChannelFuture channelFuture = connect (request , uri , proxy , useProxy , bootstrap );
259
264
channelFuture .addListener (new NettyConnectListener <T >(config , future , this , channelManager , channelPreempted , poolKey ));
@@ -303,7 +308,7 @@ public <T> void writeRequest(NettyResponseFuture<T> future, Channel channel) {
303
308
if (!future .isHeadersAlreadyWrittenOnContinue ()) {
304
309
try {
305
310
if (future .getAsyncHandler () instanceof AsyncHandlerExtensions )
306
- AsyncHandlerExtensions .class .cast (future .getAsyncHandler ()).onRequestSent ();
311
+ AsyncHandlerExtensions .class .cast (future .getAsyncHandler ()).onSendRequest ();
307
312
308
313
channel .writeAndFlush (httpRequest , channel .newProgressivePromise ()).addListener (new ProgressListener (config , future .getAsyncHandler (), future , true , 0L ));
309
314
} catch (Throwable cause ) {
@@ -474,7 +479,11 @@ private boolean validateWebSocketRequest(Request request, AsyncHandler<?> asyncH
474
479
return request .getMethod ().equals (HttpMethod .GET .name ()) && asyncHandler instanceof WebSocketUpgradeHandler ;
475
480
}
476
481
477
- private Channel pollAndVerifyCachedChannel (UriComponents uri , ProxyServer proxy , ConnectionPoolKeyStrategy connectionPoolKeyStrategy ) {
482
+ private Channel pollAndVerifyCachedChannel (UriComponents uri , ProxyServer proxy , ConnectionPoolKeyStrategy connectionPoolKeyStrategy , AsyncHandler <?> asyncHandler ) {
483
+
484
+ if (asyncHandler instanceof AsyncHandlerExtensions )
485
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onPoolConnection ();
486
+
478
487
final Channel channel = channelManager .poll (connectionPoolKeyStrategy .getKey (uri , proxy ));
479
488
480
489
if (channel != null ) {
0 commit comments