@@ -162,8 +162,7 @@ private <T> ListenableFuture<T> sendRequestThroughSslProxy(//
162
162
newFuture = newNettyRequestAndResponseFuture (request , asyncHandler , future , uri , proxyServer , false );
163
163
164
164
if (Channels .isChannelValid (channel ))
165
- // if the channel is still active, we can use it, otherwise try
166
- // gain
165
+ // if the channel is still active, we can use it, otherwise try gain
167
166
return sendRequestWithCachedChannel (request , uri , proxyServer , newFuture , asyncHandler , channel );
168
167
else
169
168
// pool is empty
@@ -194,12 +193,15 @@ private Channel getCachedChannel(NettyResponseFuture<?> future, UriComponents ur
194
193
if (future != null && future .reuseChannel () && Channels .isChannelValid (future .channel ()))
195
194
return future .channel ();
196
195
else
197
- return pollAndVerifyCachedChannel (uri , proxyServer , poolKeyGen );
196
+ return pollAndVerifyCachedChannel (uri , proxyServer , poolKeyGen , future . getAsyncHandler () );
198
197
}
199
198
200
199
private <T > ListenableFuture <T > sendRequestWithCachedChannel (Request request , UriComponents uri , ProxyServer proxy ,
201
200
NettyResponseFuture <T > future , AsyncHandler <T > asyncHandler , Channel channel ) throws IOException {
202
201
202
+ if (asyncHandler instanceof AsyncHandlerExtensions )
203
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onConnectionPooled ();
204
+
203
205
future .setState (NettyResponseFuture .STATE .POOLED );
204
206
future .attachChannel (channel , false );
205
207
@@ -258,6 +260,9 @@ private <T> ListenableFuture<T> sendRequestWithNewChannel(//
258
260
}
259
261
260
262
try {
263
+ if (asyncHandler instanceof AsyncHandlerExtensions )
264
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onOpenConnection ();
265
+
261
266
ChannelFuture channelFuture = connect (request , uri , proxy , useProxy , bootstrap );
262
267
channelFuture .addListener (new NettyConnectListener <T >(config , future , this , channelManager , channelPreempted , poolKey ));
263
268
@@ -306,9 +311,8 @@ public <T> void writeRequest(NettyResponseFuture<T> future, Channel channel) {
306
311
307
312
if (!future .isHeadersAlreadyWrittenOnContinue ()) {
308
313
try {
309
- if (future .getAsyncHandler () instanceof AsyncHandlerExtensions ) {
310
- AsyncHandlerExtensions .class .cast (future .getAsyncHandler ()).onRequestSent ();
311
- }
314
+ if (future .getAsyncHandler () instanceof AsyncHandlerExtensions )
315
+ AsyncHandlerExtensions .class .cast (future .getAsyncHandler ()).onSendRequest ();
312
316
channel .write (httpRequest ).addListener (new ProgressListener (config , future .getAsyncHandler (), future , true ));
313
317
} catch (Throwable cause ) {
314
318
// FIXME why not notify?
@@ -481,7 +485,11 @@ private boolean validateWebSocketRequest(Request request, AsyncHandler<?> asyncH
481
485
return request .getMethod ().equals (HttpMethod .GET .getName ()) && asyncHandler instanceof WebSocketUpgradeHandler ;
482
486
}
483
487
484
- public Channel pollAndVerifyCachedChannel (UriComponents uri , ProxyServer proxy , ConnectionPoolKeyStrategy connectionPoolKeyStrategy ) {
488
+ public Channel pollAndVerifyCachedChannel (UriComponents uri , ProxyServer proxy , ConnectionPoolKeyStrategy connectionPoolKeyStrategy , AsyncHandler <?> asyncHandler ) {
489
+
490
+ if (asyncHandler instanceof AsyncHandlerExtensions )
491
+ AsyncHandlerExtensions .class .cast (asyncHandler ).onPoolConnection ();
492
+
485
493
final Channel channel = channelManager .poll (connectionPoolKeyStrategy .getKey (uri , proxy ));
486
494
487
495
if (channel != null ) {
0 commit comments