From ed67a459154d06a3b8143ec90e229231f89bc57f Mon Sep 17 00:00:00 2001 From: ehlxr Date: Tue, 19 Jan 2021 18:50:50 +0800 Subject: [PATCH] Optimized code --- .../main/java/cn/ceres/did/server/BaseServer.java | 3 ++- .../java/cn/ceres/did/server/http/HttpServer.java | 13 ++++--------- .../java/cn/ceres/did/server/sdk/SdkServer.java | 3 +++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/did-server/src/main/java/cn/ceres/did/server/BaseServer.java b/did-server/src/main/java/cn/ceres/did/server/BaseServer.java index 7a2945c..847c6a0 100644 --- a/did-server/src/main/java/cn/ceres/did/server/BaseServer.java +++ b/did-server/src/main/java/cn/ceres/did/server/BaseServer.java @@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger; * @author ehlxr */ public abstract class BaseServer implements Server { - protected Logger logger = LoggerFactory.getLogger(getClass()); + protected Logger logger = LoggerFactory.getLogger(BaseServer.class); protected DefaultEventLoopGroup defLoopGroup; protected NioEventLoopGroup bossGroup; @@ -59,6 +59,7 @@ public abstract class BaseServer implements Server { } bossGroup.shutdownGracefully(); workGroup.shutdownGracefully(); + logger.info("Server EventLoopGroup shutdown finish"); } } diff --git a/did-server/src/main/java/cn/ceres/did/server/http/HttpServer.java b/did-server/src/main/java/cn/ceres/did/server/http/HttpServer.java index c5a7df2..2ca1c18 100644 --- a/did-server/src/main/java/cn/ceres/did/server/http/HttpServer.java +++ b/did-server/src/main/java/cn/ceres/did/server/http/HttpServer.java @@ -10,6 +10,8 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Http服务器,使用Netty中的Http协议栈, @@ -19,6 +21,8 @@ import io.netty.handler.codec.http.HttpResponseEncoder; * @author ehlxr */ public class HttpServer extends BaseServer { + protected Logger logger = LoggerFactory.getLogger(HttpServer.class); + private final SnowFlake snowFlake; public HttpServer(SnowFlake snowFlake) { @@ -62,13 +66,4 @@ public class HttpServer extends BaseServer { } } - @Override - public void shutdown() { - if (defLoopGroup != null) { - defLoopGroup.shutdownGracefully(); - } - bossGroup.shutdownGracefully(); - workGroup.shutdownGracefully(); - } - } diff --git a/did-server/src/main/java/cn/ceres/did/server/sdk/SdkServer.java b/did-server/src/main/java/cn/ceres/did/server/sdk/SdkServer.java index f0170b7..fa57f73 100644 --- a/did-server/src/main/java/cn/ceres/did/server/sdk/SdkServer.java +++ b/did-server/src/main/java/cn/ceres/did/server/sdk/SdkServer.java @@ -7,11 +7,14 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author ehlxr */ public class SdkServer extends BaseServer { + protected Logger logger = LoggerFactory.getLogger(SdkServer.class); private final SnowFlake snowFlake; public SdkServer(SnowFlake snowFlake) {