Эх сурвалжийг харах

netty close method update and disable http

shjung 15 цаг өмнө
parent
commit
9d27d18b88

+ 1 - 1
src/main/java/com/its/dsrc/config/RunningConfig.java

@@ -64,7 +64,7 @@ public class RunningConfig {
     @PostConstruct
     private void init() {
         int DEFAULT_EVENT_THREADS = Runtime.getRuntime().availableProcessors();
-        if (this.commBindingAddr.equals("")) {
+        if (this.commBindingAddr.isEmpty()) {
             this.commBindingAddr = "0.0.0.0";
         }
 

+ 26 - 7
src/main/java/com/its/dsrc/xnettcp/dsrc/DsrcTcpCommServerService.java

@@ -7,6 +7,7 @@ import com.its.dsrc.global.AppRepository;
 import com.its.dsrc.xnettcp.dsrc.codec.DsrcTcpServerEncoder;
 import com.its.dsrc.xnettcp.dsrc.handler.DsrcAsn1ServerPacketInboundHandler;
 import io.netty.bootstrap.ServerBootstrap;
+import io.netty.buffer.PooledByteBufAllocator;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
@@ -66,14 +67,22 @@ public class DsrcTcpCommServerService {
         log.info("*********************************************************************************");
 
         try {
-            if (this.runningConfig.getCommBindingAddr().equals("0.0.0.0")) {
-                this.channelFuture = serverBootstrap.bind(this.runningConfig.getCommBindingPort());
-            }
-            else {
-                this.channelFuture = serverBootstrap.bind(this.runningConfig.getCommBindingAddr(), this.runningConfig.getCommBindingPort());
+//            if (this.runningConfig.getCommBindingAddr().equals("0.0.0.0")) {
+//                this.channelFuture = serverBootstrap.bind(this.runningConfig.getCommBindingPort()).sync();
+//            }
+//            else {
+//                this.channelFuture = serverBootstrap.bind(this.runningConfig.getCommBindingAddr(), this.runningConfig.getCommBindingPort()).sync();
+//            }
+            this.channelFuture = serverBootstrap.bind("0.0.0.0", this.runningConfig.getCommBindingPort()).sync();
+            if (!this.channelFuture.isSuccess()) {
+                log.error("DsrcTcpCommServerService bind failed: {}", channelFuture.cause().getMessage());
             }
-        }
-        catch (Exception e) {
+        } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            log.error("DsrcTcpCommServerService bind InterruptedException: {}", ie.getMessage());
+            if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
+            if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
+        } catch (Exception e) {
             log.error("DsrcTcpCommServerService bind exception: {}", e.getMessage());
             if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
             if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
@@ -82,14 +91,21 @@ public class DsrcTcpCommServerService {
 
     public void stop() {
         try {
+            if (this.channelFuture != null && this.channelFuture.channel() != null) {
+                this.channelFuture.channel().close().sync();
+                this.channelFuture = null;
+            }
             if (this.acceptGroups != null) {
                 this.acceptGroups.shutdownGracefully().sync();
+                this.acceptGroups = null;
             }
             if (this.workerGroups != null) {
                 this.workerGroups.shutdownGracefully().sync();
+                this.workerGroups = null;
             }
 //            if (this.channelFuture != null && this.channelFuture.channel() != null) {
 //                this.channelFuture.channel().closeFuture().sync();
+//                this.channelFuture = null;
 //            }
         }
         catch (InterruptedException e) {
@@ -120,6 +136,9 @@ public class DsrcTcpCommServerService {
         serverBootstrap.option(ChannelOption.SO_REUSEADDR, true);
         serverBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, this.runningConfig.getCommConnectTimeoutSeconds()*1000);
 
+        serverBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+        serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
+
         serverBootstrap.childOption(ChannelOption.SO_LINGER, 0);           // 4way-handshake 비활성
         serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, false);    // KEEPALIVE 비활성(활성: true)
         serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, true);     // 소켓 재사용

+ 1 - 1
src/main/resources/application.yml

@@ -4,7 +4,7 @@ spring:
   profiles:
     active: prod
   main:
-    #web-application-type: none
+    web-application-type: none
     log-startup-info: true
     banner-mode: off
   mvc:

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

@@ -138,7 +138,7 @@
         </rollingPolicy>
     </appender>
 
-    <logger name="${APP_CLASS_PATH}.xnettcp" level="INFO" additivity="true">
+    <logger name="${APP_CLASS_PATH}.xnettcp.dsrc.handler" level="INFO" additivity="true">
         <appender-ref ref="FILE_SESSION"/>
         <appender-ref ref="FILE_ERROR"/>
     </logger>