25
25
import org .asynchttpclient .handler .AsyncHandlerExtensions ;
26
26
import org .asynchttpclient .netty .SimpleChannelFutureListener ;
27
27
import org .asynchttpclient .netty .channel .NettyConnectListener ;
28
+ import org .asynchttpclient .netty .timeout .TimeoutsHolder ;
28
29
29
30
public class NettyChannelConnector {
30
31
31
32
private final AsyncHandlerExtensions asyncHandlerExtensions ;
32
33
private final InetSocketAddress localAddress ;
33
34
private final List <InetSocketAddress > remoteAddresses ;
35
+ private final TimeoutsHolder timeoutsHolder ;
34
36
private volatile int i = 0 ;
35
37
36
- public NettyChannelConnector (InetAddress localAddress , List <InetSocketAddress > remoteAddresses , AsyncHandler <?> asyncHandler ) {
38
+ public NettyChannelConnector (InetAddress localAddress , List <InetSocketAddress > remoteAddresses , AsyncHandler <?> asyncHandler , TimeoutsHolder timeoutsHolder ) {
37
39
this .localAddress = localAddress != null ? new InetSocketAddress (localAddress , 0 ) : null ;
38
40
this .remoteAddresses = remoteAddresses ;
39
41
this .asyncHandlerExtensions = toAsyncHandlerExtensions (asyncHandler );
42
+ this .timeoutsHolder = timeoutsHolder ;
40
43
}
41
44
42
45
private boolean pickNextRemoteAddress () {
@@ -46,7 +49,7 @@ private boolean pickNextRemoteAddress() {
46
49
47
50
public void connect (final Bootstrap bootstrap , final NettyConnectListener <?> connectListener ) {
48
51
final InetSocketAddress remoteAddress = remoteAddresses .get (i );
49
-
52
+
50
53
if (asyncHandlerExtensions != null )
51
54
asyncHandlerExtensions .onTcpConnectAttempt (remoteAddress );
52
55
@@ -56,9 +59,10 @@ public void connect(final Bootstrap bootstrap, final NettyConnectListener<?> con
56
59
57
60
@ Override
58
61
public void onSuccess (Channel channel ) throws Exception {
59
- if (asyncHandlerExtensions != null )
62
+ if (asyncHandlerExtensions != null ) {
60
63
asyncHandlerExtensions .onTcpConnectSuccess (remoteAddress , future .channel ());
61
-
64
+ }
65
+ timeoutsHolder .initRemoteAddress (remoteAddress );
62
66
connectListener .onSuccess (channel );
63
67
}
64
68
0 commit comments