|
@@ -5,6 +5,7 @@ import com.its.api.xnettcp.client.codec.NettyTcpClientEncoder;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientIdleHandler;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientIdleHandler;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientInboundHandler;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientInboundHandler;
|
|
import io.netty.bootstrap.Bootstrap;
|
|
import io.netty.bootstrap.Bootstrap;
|
|
|
|
+import io.netty.channel.ChannelFuture;
|
|
import io.netty.channel.ChannelInitializer;
|
|
import io.netty.channel.ChannelInitializer;
|
|
import io.netty.channel.ChannelOption;
|
|
import io.netty.channel.ChannelOption;
|
|
import io.netty.channel.EventLoopGroup;
|
|
import io.netty.channel.EventLoopGroup;
|
|
@@ -18,20 +19,24 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
-public class NettyTcpClientBootstrapFactory {
|
|
|
|
|
|
+public class NettyTcpClientVdsBootstrapFactory {
|
|
|
|
|
|
private final int workerThread;
|
|
private final int workerThread;
|
|
private final int connectTimeout;
|
|
private final int connectTimeout;
|
|
|
|
+ private EventLoopGroup nioEventLoopGroup = null;
|
|
|
|
+ //private List<ChannelFuture> channelFutures = new ArrayList<>();
|
|
|
|
|
|
- public Bootstrap createBootstrap() throws Exception {
|
|
|
|
-
|
|
|
|
- EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(this.workerThread);
|
|
|
|
|
|
+ public Bootstrap createBootstrap() {
|
|
|
|
+ if (this.nioEventLoopGroup == null) {
|
|
|
|
+ this.nioEventLoopGroup = new NioEventLoopGroup(this.workerThread);
|
|
|
|
+ }
|
|
Bootstrap bootstrap = new Bootstrap();
|
|
Bootstrap bootstrap = new Bootstrap();
|
|
|
|
+ bootstrap.group(this.nioEventLoopGroup);
|
|
|
|
+
|
|
bootstrap.channel(NioSocketChannel.class);
|
|
bootstrap.channel(NioSocketChannel.class);
|
|
- bootstrap.group(nioEventLoopGroup);
|
|
|
|
bootstrap.option(ChannelOption.AUTO_READ, true);
|
|
bootstrap.option(ChannelOption.AUTO_READ, true);
|
|
bootstrap.option(ChannelOption.TCP_NODELAY, true);
|
|
bootstrap.option(ChannelOption.TCP_NODELAY, true);
|
|
- bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
|
|
|
|
+ bootstrap.option(ChannelOption.SO_KEEPALIVE, true);//false);
|
|
bootstrap.option(ChannelOption.SO_RCVBUF, 8192);
|
|
bootstrap.option(ChannelOption.SO_RCVBUF, 8192);
|
|
bootstrap.option(ChannelOption.SO_SNDBUF, 8192);
|
|
bootstrap.option(ChannelOption.SO_SNDBUF, 8192);
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
@@ -41,13 +46,17 @@ public class NettyTcpClientBootstrapFactory {
|
|
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
|
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
|
@Override
|
|
@Override
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
- ch.pipeline().addLast("tcpClientIdleHandler", new NettyTcpClientIdleHandler(0, 0, 0, TimeUnit.SECONDS));
|
|
|
|
- ch.pipeline().addLast("tcpClientEncoder", new NettyTcpClientEncoder()); // Encoding handler
|
|
|
|
- ch.pipeline().addLast("tcpClientDecoder", new NettyTcpClientDecoder()); // Decoding handler
|
|
|
|
- ch.pipeline().addLast("tcpClientInboundHandler", new NettyTcpClientInboundHandler()); // Packet Inbound handler
|
|
|
|
|
|
+ ch.pipeline().addLast("vdsClientIdleHandler", new NettyTcpClientIdleHandler(0, 0, 0, TimeUnit.SECONDS));
|
|
|
|
+ ch.pipeline().addLast("vdsClientEncoder", new NettyTcpClientEncoder()); // Encoding handler
|
|
|
|
+ ch.pipeline().addLast("vdsClientDecoder", new NettyTcpClientDecoder()); // Decoding handler
|
|
|
|
+ ch.pipeline().addLast("vdsClientInboundHandler", new NettyTcpClientInboundHandler()); // Packet Inbound handler
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
return bootstrap;
|
|
return bootstrap;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void addChannelFuture(ChannelFuture future) {
|
|
|
|
+ //this.channelFutures.add(future);
|
|
|
|
+ }
|
|
}
|
|
}
|