@Override public String toString() { return "Netty4TcpChannel{" + "localAddress=" + getLocalAddress() + ", remoteAddress=" + channel.remoteAddress() + '}'; } }
@Override protected void initChannel(Channel ch) throws Exception { addClosedExceptionLogger(ch); Netty4TcpChannel nettyTcpChannel = new Netty4TcpChannel(ch, true, name, ch.newSucceededFuture()); ch.attr(CHANNEL_KEY).set(nettyTcpChannel); serverAcceptedChannel(nettyTcpChannel); ch.pipeline().addLast("logging", new ESLoggingHandler()); ch.pipeline().addLast("size", new Netty4SizeHeaderFrameDecoder()); ch.pipeline().addLast("dispatcher", new Netty4MessageChannelHandler(Netty4Transport.this)); }
@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; }