@Override protected Netty4TcpChannel initiateChannel(DiscoveryNode node) throws IOException { InetSocketAddress address = node.getAddress().address(); Bootstrap bootstrapWithHandler = clientBootstrap.clone(); bootstrapWithHandler.handler(getClientChannelInitializer(node)); bootstrapWithHandler.remoteAddress(address); ChannelFuture connectFuture = bootstrapWithHandler.connect(); Channel channel = connectFuture.channel(); if (channel == null) { ExceptionsHelper.maybeDieOnAnotherThread(connectFuture.cause()); throw new IOException(connectFuture.cause()); } addClosedExceptionLogger(channel); Netty4TcpChannel nettyChannel = new Netty4TcpChannel(channel, false, "default", connectFuture); channel.attr(CHANNEL_KEY).set(nettyChannel); return nettyChannel; }
@Override protected NettyTcpChannel initiateChannel(DiscoveryNode node, TimeValue connectTimeout, ActionListener<Void> listener) throws IOException { ChannelFuture channelFuture = bootstrap.connect(node.getAddress().address()); Channel channel = channelFuture.channel(); if (channel == null) { Netty4Utils.maybeDie(channelFuture.cause()); throw new IOException(channelFuture.cause()); } addClosedExceptionLogger(channel); NettyTcpChannel nettyChannel = new NettyTcpChannel(channel); channel.attr(CHANNEL_KEY).set(nettyChannel); channelFuture.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { Throwable cause = f.cause(); if (cause instanceof Error) { Netty4Utils.maybeDie(cause); listener.onFailure(new Exception(cause)); } else { listener.onFailure((Exception) cause); } } }); return nettyChannel; }
@Override protected NettyTcpChannel initiateChannel(DiscoveryNode node, ActionListener<Void> listener) throws IOException { InetSocketAddress address = node.getAddress().address(); Bootstrap bootstrapWithHandler = clientBootstrap.clone(); bootstrapWithHandler.handler(getClientChannelInitializer(node)); bootstrapWithHandler.remoteAddress(address); ChannelFuture channelFuture = bootstrapWithHandler.connect(); Channel channel = channelFuture.channel(); if (channel == null) { ExceptionsHelper.maybeDieOnAnotherThread(channelFuture.cause()); throw new IOException(channelFuture.cause()); } addClosedExceptionLogger(channel); NettyTcpChannel nettyChannel = new NettyTcpChannel(channel); channel.attr(CHANNEL_KEY).set(nettyChannel); channelFuture.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { Throwable cause = f.cause(); if (cause instanceof Error) { ExceptionsHelper.maybeDieOnAnotherThread(cause); listener.onFailure(new Exception(cause)); } else { listener.onFailure((Exception) cause); } } }); return nettyChannel; }