shjung 1 год назад
Родитель
Сommit
120f5c30c7

+ 2 - 1
conf/sig-ggits-server.yml

@@ -12,4 +12,5 @@ management:
         include: health, metrics
 
 application:
-  binding-port: 8900
+  binding-port: 8900
+  ggits-ip: 192.168.24.22

+ 8 - 4
pom.xml

@@ -55,6 +55,14 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.aspectj</groupId>-->
+<!--            <artifactId>aspectjweaver</artifactId>-->
+<!--        </dependency>-->
 
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -110,10 +118,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.aspectj</groupId>
-            <artifactId>aspectjweaver</artifactId>
-        </dependency>
 
     </dependencies>
 

+ 3 - 0
src/main/java/com/sig/app/common/xnet/NettyServerConfig.java

@@ -34,6 +34,9 @@ public abstract class NettyServerConfig {
         if (this.backlog == 0) {
             this.backlog = 1024;
         }
+        if (this.readerIdleTimeSeconds < 10) {
+            this.readerIdleTimeSeconds = 10;
+        }
         /*if (this.acceptThreads == 0) {
             if (MAX_CORE <= 8) {
                 this.acceptThreads = 4;

+ 2 - 2
src/main/java/com/sig/app/common/xnet/NettyTcpServer.java

@@ -29,10 +29,10 @@ public abstract class NettyTcpServer {
 
         try {
             if (NettyUtils.isEpollAvailable()) {
-                log.info("서버가 리눅스 EPOLL 모드에서 실행됩니다.");
+                log.info("Server Run Linux EPOLL Mode.");
             }
             else {
-                log.info("서버가 윈도우 NIO 모드에서 실행됩니다.");
+                log.info("Server Run Windows/Unix NIO Mode.");
             }
 
             this.serverBootstrap = ServerBootstrapFactory.createBootstrap(this.config, this.channelInitializer);

+ 1 - 0
src/main/java/com/sig/ggits/server/config/ApplicationConfig.java

@@ -17,6 +17,7 @@ public class ApplicationConfig extends NettyServerConfig {
     private boolean loggingThread = false;
 
     private String processId = "81010";
+    private String ggitsIp;
     private int maxConnection = 0;
     private int packetWorkers = 0;
     private int loggingWorkers = 0;

+ 2 - 2
src/main/java/com/sig/ggits/server/tcp/SigTcpCommServerService.java

@@ -32,10 +32,10 @@ public class SigTcpCommServerService extends NettyTcpServer {
             log.warn("SigTcpCommServerService.initialize: {}", Epoll.unavailabilityCause().toString());
         }
         if (NettyUtils.isEpollAvailable()) {
-            log.info("서버가 리눅스 EPOLL 모드에서 실행됩니다.");
+            log.info("Server Run Linux EPOLL Mode.");
         }
         else {
-            log.info("서버가 윈도우 NIO 모드에서 실행됩니다.");
+            log.info("Server Run Windows/Unix NIO Mode.");
         }
     }
 }

+ 7 - 7
src/main/java/com/sig/ggits/server/tcp/handler/SigCommServerInboundMessageHandler.java

@@ -70,10 +70,10 @@ public class SigCommServerInboundMessageHandler extends SimpleChannelInboundHand
         // 여기는 절대 들어 와서는 안되는 로직임....
         RegionCenter center = getCenterObject(ctx);
         if (center != null) {
-            log.error("{}.++channelActive: {}. {}.", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()), center.getRegionCd());
+            log.info("{}.++channelActive: {}. {}.", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()), center.getRegionCd());
         }
         else {
-            log.error("{}.++channelActive: {}.", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()));
+            log.warn("{}.++channelActive: Not Found Context, {}.", this.getClass().getSimpleName(), NettyUtils.getAddress(ctx.channel()));
         }
         ctx.fireChannelActive();
     }
@@ -151,11 +151,11 @@ public class SigCommServerInboundMessageHandler extends SimpleChannelInboundHand
     }
     private RegionCenter getCenterObject(ChannelHandlerContext ctx) {
         RegionCenter center = ctx.channel().attr(AppRepositoryService.SIG_REGION_ATTRIBUTE_KEY).get();
-        if (center == null) {
-            log.warn("Channel: READER_IDLE: {}, Not Found Channel Object. Will be closed.", NettyUtils.getAddress(ctx.channel()));
-            closeChannel(ctx);
-            return null;
-        }
+//        if (center == null) {
+//            log.warn("Channel: getCenterObject: {}, Not Found Channel Object. Will be closed.", NettyUtils.getAddress(ctx.channel()));
+//            closeChannel(ctx);
+//            return null;
+//        }
         return center;
     }
 }

+ 27 - 22
src/main/java/com/sig/ggits/server/tcp/initializer/SigCommServerInitializer.java

@@ -3,7 +3,6 @@ package com.sig.ggits.server.tcp.initializer;
 import com.sig.app.common.xnet.NettyUtils;
 import com.sig.ggits.server.common.SpringUtils;
 import com.sig.ggits.server.config.ApplicationConfig;
-import com.sig.ggits.server.dto.RegionCenter;
 import com.sig.ggits.server.service.AppRepositoryService;
 import com.sig.ggits.server.tcp.codec.SigSendByteBufMessageEncoder;
 import com.sig.ggits.server.tcp.handler.SigCommServerInboundMessageHandler;
@@ -12,8 +11,6 @@ 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;
 import lombok.extern.slf4j.Slf4j;
 
@@ -35,29 +32,37 @@ public class SigCommServerInitializer extends ChannelInitializer<Channel> {
     @Override
     protected void initChannel(Channel channel) throws Exception {
         String ipAddress  = NettyUtils.getRemoteIpAddress(channel);
-        RegionCenter center = this.appRepository.getIpAddrMap(ipAddress);
-        if (center == null) {
-            log.error("SigCommServerInitializer.----initChannel: {}, Unknown ip address. will be closed.", ipAddress);
-            channel.disconnect();
-            channel.close();
-            return;
-        }
-        if (center.getNetState().getChannel() != null) {
-            log.warn("SigCommServerInitializer.----initChannel: {}, {}, Already Connected. Old Connection will be closed.", ipAddress, center.getRegionCd());
-            // 이벤트 핸들러 에서 중복 처리 되지 않도록 속성 값을 제거
-            channel.attr(AppRepositoryService.SIG_REGION_ATTRIBUTE_KEY).set(null);
-            center.getNetState().disConnect();
+        log.info("SigCommServerInitializer.----initChannel: Connected From : {}", ipAddress);
+//        if (!ipAddress.equals("localhost")) {
+//            log.error("SigCommServerInitializer.----initChannel: {}, Unknown ip address. will be closed.", ipAddress);
+//            channel.disconnect();
+//            channel.close();
+//            return;
+//        }
 
-            channel.disconnect();
-            channel.close();
-        }
-
-        center.getNetState().connect(channel);
-        channel.attr(AppRepositoryService.SIG_REGION_ATTRIBUTE_KEY).set(center);
+//        RegionCenter center = this.appRepository.getIpAddrMap(ipAddress);
+//        if (center == null) {
+//            log.error("SigCommServerInitializer.----initChannel: {}, Unknown ip address. will be closed.", ipAddress);
+//            channel.disconnect();
+//            channel.close();
+//            return;
+//        }
+//        if (center.getNetState().getChannel() != null) {
+//            log.warn("SigCommServerInitializer.----initChannel: {}, {}, Already Connected. Old Connection will be closed.", ipAddress, center.getRegionCd());
+//            // 이벤트 핸들러 에서 중복 처리 되지 않도록 속성 값을 제거
+//            channel.attr(AppRepositoryService.SIG_REGION_ATTRIBUTE_KEY).set(null);
+//            center.getNetState().disConnect();
+//
+//            channel.disconnect();
+//            channel.close();
+//        }
+//
+//        center.getNetState().connect(channel);
+//        channel.attr(AppRepositoryService.SIG_REGION_ATTRIBUTE_KEY).set(center);
 
         IdleStateHandler idleStateHandler = new IdleStateHandler(this.config.getReaderIdleTimeSeconds(), 0, 0);
         ChannelPipeline pipeline = channel.pipeline();
-        pipeline.addLast(new LoggingHandler(LogLevel.INFO));
+        //pipeline.addLast(new LoggingHandler(LogLevel.INFO));
         pipeline.addLast("idleStateHandler", idleStateHandler);
         pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(
                 SigProtocolConst.SIG_MAX_PACKET,

+ 2 - 2
src/main/resources/logback-spring.xml

@@ -2,9 +2,9 @@
 <configuration scan="true" scanPeriod="60 seconds">
     <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
 
-    <property name="APP_CLASS_PATH"  value="com.sig.comm"/>
+    <property name="APP_CLASS_PATH"  value="com.sig.ggits"/>
     <property name="PROJECT_PREFIX"  value="sig"/>
-    <property name="PROJECT_NAME"    value="${PROJECT_PREFIX}-comm-server"/>
+    <property name="PROJECT_NAME"    value="${PROJECT_PREFIX}-ggits-server"/>
     <property name="ROOT_LOG_LEVEL"  value="INFO"/>
     <property name="LOG_CHARSET"     value="UTF-8" />
     <property name="LOG_PATH"        value="${user.dir}/logs/"/>