|
@@ -1,48 +1,48 @@
|
|
|
package com.sig.comm.server.tcp.initializer;
|
|
|
|
|
|
import com.sig.app.common.app.AppUtils;
|
|
|
+import com.sig.comm.server.common.SpringUtils;
|
|
|
import com.sig.comm.server.config.ApplicationConfig;
|
|
|
-import com.sig.comm.server.tcp.codec.SigRecvByteBufMessageDecoder;
|
|
|
import com.sig.comm.server.tcp.codec.SigSendByteBufMessageEncoder;
|
|
|
+import com.sig.comm.server.tcp.handler.SigCommReceivePacketHandler;
|
|
|
import com.sig.comm.server.tcp.handler.SigServerInboundMessageHandler;
|
|
|
import com.sig.comm.server.tcp.protocol.SigProtocolConst;
|
|
|
import io.netty.channel.Channel;
|
|
|
import io.netty.channel.ChannelInitializer;
|
|
|
import io.netty.channel.ChannelPipeline;
|
|
|
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
|
|
+import io.netty.handler.logging.LogLevel;
|
|
|
+import io.netty.handler.logging.LoggingHandler;
|
|
|
import io.netty.handler.timeout.IdleStateHandler;
|
|
|
|
|
|
public class SigCommServerInitializer extends ChannelInitializer<Channel> {
|
|
|
|
|
|
- //private CvimServerIdleHandler cvimServerIdleHandler;
|
|
|
- private SigRecvByteBufMessageDecoder sigRecvByteBufMessageDecoder;
|
|
|
- private SigServerInboundMessageHandler sigServerInboundMessageHandler;
|
|
|
- private SigSendByteBufMessageEncoder sigSendByteBufMessageEncoder;
|
|
|
- private ApplicationConfig config;
|
|
|
+ private final SigServerInboundMessageHandler sigServerInboundMessageHandler;
|
|
|
+ private final SigCommReceivePacketHandler sigCommReceivePacketHandler;
|
|
|
+ private final SigSendByteBufMessageEncoder sigSendByteBufMessageEncoder;
|
|
|
+ private final ApplicationConfig config;
|
|
|
|
|
|
public SigCommServerInitializer(ApplicationConfig config) {
|
|
|
- //this.cvimServerIdleHandler = (CvimServerIdleHandler) AppUtils.getBean(CvimServerIdleHandler.class);
|
|
|
- this.sigRecvByteBufMessageDecoder = (SigRecvByteBufMessageDecoder) AppUtils.getBean(SigRecvByteBufMessageDecoder.class);
|
|
|
+ this.config = config;
|
|
|
this.sigServerInboundMessageHandler = (SigServerInboundMessageHandler) AppUtils.getBean(SigServerInboundMessageHandler.class);
|
|
|
+ this.sigCommReceivePacketHandler = SpringUtils.getBean(SigCommReceivePacketHandler.class);
|
|
|
this.sigSendByteBufMessageEncoder = (SigSendByteBufMessageEncoder) AppUtils.getBean(SigSendByteBufMessageEncoder.class);
|
|
|
- this.config = config;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void initChannel(Channel channel) throws Exception {
|
|
|
- //IdleStateHandler idleStateHandler = new IdleStateHandler(this.config.getReaderIdleTimeSeconds(), this.config.getWriterIdleTimeSeconds(), this.config.getAllIdleTimeSeconds());
|
|
|
IdleStateHandler idleStateHandler = new IdleStateHandler(this.config.getReaderIdleTimeSeconds(), 0, 0);
|
|
|
ChannelPipeline pipeline = channel.pipeline();
|
|
|
+ pipeline.addLast(new LoggingHandler(LogLevel.INFO));
|
|
|
pipeline.addLast("idleStateHandler", idleStateHandler);
|
|
|
- //pipeline.addLast("cvimServerIdleHandler", this.cvimServerIdleHandler);
|
|
|
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(
|
|
|
SigProtocolConst.SIG_MAX_PACKET,
|
|
|
SigProtocolConst.SIG_PACKET_LENGTH_FIELD_OFFSET, /* 패킷 에서 길이 필드의 시작 위치 */
|
|
|
SigProtocolConst.SIG_PACKET_LENGTH_FIELD_SIZE, /* 길이 필드의 크기 */
|
|
|
SigProtocolConst.SIG_PACKET_LENGTH_ADJUSTMENTS, /* 길이 필드 값에 +-해서 길이 필드 이후의 전체 길이를 구한다 */
|
|
|
0));
|
|
|
- pipeline.addLast("packetDecoder", this.sigRecvByteBufMessageDecoder);
|
|
|
- pipeline.addLast("packetInboundHandler", this.sigServerInboundMessageHandler);
|
|
|
+// pipeline.addLast("packetInboundHandler", this.sigServerInboundMessageHandler);
|
|
|
+ pipeline.addLast("packetInboundHandler", this.sigCommReceivePacketHandler);
|
|
|
pipeline.addLast("frameEncoder", this.sigSendByteBufMessageEncoder);
|
|
|
}
|
|
|
}
|