|
@@ -1,5 +1,6 @@
|
|
package com.its.api.xnettcp.client;
|
|
package com.its.api.xnettcp.client;
|
|
|
|
|
|
|
|
+import com.its.api.utils.NettyUtils;
|
|
import com.its.api.xnettcp.client.codec.NettyTcpClientDecoder;
|
|
import com.its.api.xnettcp.client.codec.NettyTcpClientDecoder;
|
|
import com.its.api.xnettcp.client.codec.NettyTcpClientEncoder;
|
|
import com.its.api.xnettcp.client.codec.NettyTcpClientEncoder;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientIdleHandler;
|
|
import com.its.api.xnettcp.client.handler.NettyTcpClientIdleHandler;
|
|
@@ -9,7 +10,6 @@ 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;
|
|
-import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
|
import io.netty.channel.socket.SocketChannel;
|
|
import io.netty.channel.socket.SocketChannel;
|
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -24,11 +24,10 @@ public class NettyTcpClientVdsBootstrapFactory {
|
|
private final int workerThread;
|
|
private final int workerThread;
|
|
private final int connectTimeout;
|
|
private final int connectTimeout;
|
|
private EventLoopGroup nioEventLoopGroup = null;
|
|
private EventLoopGroup nioEventLoopGroup = null;
|
|
- //private List<ChannelFuture> channelFutures = new ArrayList<>();
|
|
|
|
|
|
|
|
public Bootstrap createBootstrap() {
|
|
public Bootstrap createBootstrap() {
|
|
if (this.nioEventLoopGroup == null) {
|
|
if (this.nioEventLoopGroup == null) {
|
|
- this.nioEventLoopGroup = new NioEventLoopGroup(this.workerThread);
|
|
|
|
|
|
+ this.nioEventLoopGroup = NettyUtils.newEventLoopGroup(this.workerThread, "vdsEventGroup");//new NioEventLoopGroup(this.workerThread); //EpollEventLoopGroup
|
|
}
|
|
}
|
|
Bootstrap bootstrap = new Bootstrap();
|
|
Bootstrap bootstrap = new Bootstrap();
|
|
bootstrap.group(this.nioEventLoopGroup);
|
|
bootstrap.group(this.nioEventLoopGroup);
|
|
@@ -44,12 +43,14 @@ public class NettyTcpClientVdsBootstrapFactory {
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
bootstrap.option(ChannelOption.SO_KEEPALIVE, false);
|
|
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
|
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
|
|
|
|
+ // VDS 전송 요청을 먼저하고 데이터를 수신한다.
|
|
|
|
+ // 핸들러가 실행되는 순서는 추가된 순서에 의해 결정된다.(Inbound: head=>tail, Outbound: tail=>head, name2ctx)
|
|
@Override
|
|
@Override
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
ch.pipeline().addLast("vdsClientIdleHandler", new NettyTcpClientIdleHandler(0, 0, 0, TimeUnit.SECONDS));
|
|
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("vdsClientDecoder", new NettyTcpClientDecoder()); // Decoding handler
|
|
ch.pipeline().addLast("vdsClientInboundHandler", new NettyTcpClientInboundHandler()); // Packet Inbound handler
|
|
ch.pipeline().addLast("vdsClientInboundHandler", new NettyTcpClientInboundHandler()); // Packet Inbound handler
|
|
|
|
+ ch.pipeline().addLast("vdsClientEncoder", new NettyTcpClientEncoder()); // Encoding handler
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|