Optimized code

This commit is contained in:
ehlxr 2021-01-19 18:50:50 +08:00
parent e06dcecd75
commit ed67a45915
3 changed files with 9 additions and 10 deletions

View File

@ -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");
}
}

View File

@ -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();
}
}

View File

@ -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) {