Browse Source

utic-its-common netty-server close method update

shjung 13 hours ago
parent
commit
31881e06e1

+ 32 - 13
utic-its-common/src/main/java/com/utic/its/common/xnet/server/ItsAsnCommServer.java

@@ -79,13 +79,20 @@ public abstract class ItsAsnCommServer {
 
         try {
             if (this.config.getBindingAddr().equals("0.0.0.0")) {
-                this.channelFuture = this.serverBootstrap.bind(ApplicationRepository.CENTER.getCommPort());
+                this.channelFuture = this.serverBootstrap.bind(ApplicationRepository.CENTER.getCommPort()).sync();
             }
             else {
-                this.channelFuture = this.serverBootstrap.bind(this.config.getBindingAddr(), ApplicationRepository.CENTER.getCommPort());
+                this.channelFuture = this.serverBootstrap.bind(this.config.getBindingAddr(), ApplicationRepository.CENTER.getCommPort()).sync();
             }
-        }
-        catch (Exception e) {
+            if (!this.channelFuture.isSuccess()) {
+                log.error("ItsAsnCommServer bind failed: {}", channelFuture.cause().getMessage());
+            }
+        } catch (InterruptedException ie) {
+            Thread.currentThread().interrupt();
+            log.error("ItsAsnCommServer bind InterruptedException: {}", ie.getMessage());
+            if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
+            if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
+        } catch (Exception e) {
             log.error("ItsAsnCommServer bind exception: {}", e.getMessage());
             if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
             if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
@@ -95,29 +102,41 @@ public abstract class ItsAsnCommServer {
     @PreDestroy
     public void shutdown() {
         try {
-            if (this.acceptGroups != null) {
-                this.acceptGroups.shutdownGracefully();
+            if (this.channelFuture != null && this.channelFuture.channel() != null) {
+                this.channelFuture.channel().close().sync();
+                this.channelFuture = null;
             }
         }
         catch (Exception e) {
-            log.info("ItsAsnCommServer.acceptGroups.shutdownGracefully");
+            log.info("ItsAsnCommServer.close");
         }
         try {
-            if (this.workerGroups != null) {
-                this.workerGroups.shutdownGracefully();
+            if (this.acceptGroups != null) {
+                this.acceptGroups.shutdownGracefully().sync();
+                this.acceptGroups = null;
             }
         }
         catch (Exception e) {
-            log.info("ItsAsnCommServer.workerGroups.shutdownGracefully");
+            log.info("ItsAsnCommServer.acceptGroups.shutdownGracefully");
         }
         try {
-            if (this.channelFuture != null && this.channelFuture.channel() != null) {
-                this.channelFuture.channel().closeFuture();
+            if (this.workerGroups != null) {
+                this.workerGroups.shutdownGracefully().sync();
+                this.workerGroups = null;
             }
         }
         catch (Exception e) {
-            log.info("ItsAsnCommServer.closeFuture");
+            log.info("ItsAsnCommServer.workerGroups.shutdownGracefully");
         }
+//        try {
+//            if (this.channelFuture != null && this.channelFuture.channel() != null) {
+//                this.channelFuture.channel().closeFuture();
+//                this.channelFuture = null;
+//            }
+//        }
+//        catch (Exception e) {
+//            log.info("ItsAsnCommServer.closeFuture");
+//        }
     }
 
     public ServerBootstrap createBootstrap(int clusterId, Set<String> whiteListIps, int acceptThreads, int workerThreads, int backlog, int connectTimeoutSeconds) {