Search in sources :

Example 1 with SimpleChannelFutureListener

use of org.asynchttpclient.netty.SimpleChannelFutureListener in project async-http-client by AsyncHttpClient.

the class NettyChannelConnector method connect0.

private void connect0(Bootstrap bootstrap, final NettyConnectListener<?> connectListener, InetSocketAddress remoteAddress) {
    //
    bootstrap.connect(remoteAddress, localAddress).addListener(new SimpleChannelFutureListener() {

        @Override
        public void onSuccess(Channel channel) {
            if (asyncHandlerExtensions != null) {
                asyncHandlerExtensions.onTcpConnectSuccess(remoteAddress, channel);
            }
            connectListener.onSuccess(channel, remoteAddress);
        }

        @Override
        public void onFailure(Channel channel, Throwable t) {
            if (asyncHandlerExtensions != null)
                asyncHandlerExtensions.onTcpConnectFailure(remoteAddress, t);
            boolean retry = pickNextRemoteAddress();
            if (retry)
                NettyChannelConnector.this.connect(bootstrap, connectListener);
            else
                connectListener.onFailure(channel, t);
        }
    });
}
Also used : Channel(io.netty.channel.Channel) SimpleChannelFutureListener(org.asynchttpclient.netty.SimpleChannelFutureListener)

Example 2 with SimpleChannelFutureListener

use of org.asynchttpclient.netty.SimpleChannelFutureListener in project async-http-client by AsyncHttpClient.

the class NettyChannelConnector method connect0.

private void connect0(Bootstrap bootstrap, final NettyConnectListener<?> connectListener, InetSocketAddress remoteAddress) {
    bootstrap.connect(remoteAddress, localAddress).addListener(new SimpleChannelFutureListener() {

        @Override
        public void onSuccess(Channel channel) {
            try {
                asyncHandler.onTcpConnectSuccess(remoteAddress, channel);
            } catch (Exception e) {
                LOGGER.error("onTcpConnectSuccess crashed", e);
                connectListener.onFailure(channel, e);
                return;
            }
            connectListener.onSuccess(channel, remoteAddress);
        }

        @Override
        public void onFailure(Channel channel, Throwable t) {
            try {
                asyncHandler.onTcpConnectFailure(remoteAddress, t);
            } catch (Exception e) {
                LOGGER.error("onTcpConnectFailure crashed", e);
                connectListener.onFailure(channel, e);
                return;
            }
            boolean retry = pickNextRemoteAddress();
            if (retry) {
                NettyChannelConnector.this.connect(bootstrap, connectListener);
            } else {
                connectListener.onFailure(channel, t);
            }
        }
    });
}
Also used : Channel(io.netty.channel.Channel) SimpleChannelFutureListener(org.asynchttpclient.netty.SimpleChannelFutureListener) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

Channel (io.netty.channel.Channel)2 SimpleChannelFutureListener (org.asynchttpclient.netty.SimpleChannelFutureListener)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1