Optimized code
This commit is contained in:
parent
e06dcecd75
commit
ed67a45915
@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user