use of rpc.turbo.transport.client.sender.BatchSender in project turbo-rpc by hank-whu.
the class NettyClientConnector method connect.
void connect() throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(eventLoopGroup);
bootstrap.option(ChannelOption.SO_REUSEADDR, true);
bootstrap.option(ChannelOption.SO_RCVBUF, 256 * 1024);
bootstrap.option(ChannelOption.SO_SNDBUF, 256 * 1024);
//
bootstrap.option(//
ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(1024 * 1024, 2048 * 1024));
if (eventLoopGroup instanceof EpollEventLoopGroup) {
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
bootstrap.channel(EpollSocketChannel.class);
} else if (eventLoopGroup instanceof NioEventLoopGroup) {
bootstrap.channel(NioSocketChannel.class);
}
bootstrap.handler(new TurboChannelInitializer(serializer));
Sender[] newSenders = new Sender[connectCount];
for (int i = 0; i < connectCount; i++) {
Channel channel = bootstrap.connect(serverAddress.host, serverAddress.port).sync().channel();
newSenders[i] = new BatchSender(channel);
if (logger.isInfoEnabled()) {
logger.info(serverAddress + " connect " + i + "/" + connectCount);
}
if (i == 0) {
InetSocketAddress insocket = (InetSocketAddress) channel.localAddress();
clientAddress = new HostPort(insocket.getAddress().getHostAddress(), 0);
}
}
Sender[] old = senders;
senders = newSenders;
if (old != null) {
for (int i = 0; i < old.length; i++) {
try {
old[i].close();
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("关闭出错", e);
}
}
}
}
}
Aggregations