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 * @author ehlxr
*/ */
public abstract class BaseServer implements Server { public abstract class BaseServer implements Server {
protected Logger logger = LoggerFactory.getLogger(getClass()); protected Logger logger = LoggerFactory.getLogger(BaseServer.class);
protected DefaultEventLoopGroup defLoopGroup; protected DefaultEventLoopGroup defLoopGroup;
protected NioEventLoopGroup bossGroup; protected NioEventLoopGroup bossGroup;
@ -59,6 +59,7 @@ public abstract class BaseServer implements Server {
} }
bossGroup.shutdownGracefully(); bossGroup.shutdownGracefully();
workGroup.shutdownGracefully(); workGroup.shutdownGracefully();
logger.info("Server EventLoopGroup shutdown finish"); 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.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpResponseEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Http服务器使用Netty中的Http协议栈 * Http服务器使用Netty中的Http协议栈
@ -19,6 +21,8 @@ import io.netty.handler.codec.http.HttpResponseEncoder;
* @author ehlxr * @author ehlxr
*/ */
public class HttpServer extends BaseServer { public class HttpServer extends BaseServer {
protected Logger logger = LoggerFactory.getLogger(HttpServer.class);
private final SnowFlake snowFlake; private final SnowFlake snowFlake;
public HttpServer(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.ChannelOption;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* @author ehlxr * @author ehlxr
*/ */
public class SdkServer extends BaseServer { public class SdkServer extends BaseServer {
protected Logger logger = LoggerFactory.getLogger(SdkServer.class);
private final SnowFlake snowFlake; private final SnowFlake snowFlake;
public SdkServer(SnowFlake snowFlake) { public SdkServer(SnowFlake snowFlake) {