This commit is contained in:
crusader 2018-04-24 01:47:18 +09:00
parent 5305a64420
commit 68763a3c73

View File

@ -3,6 +3,8 @@ package com.loafle.commons.server;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -19,13 +21,15 @@ import io.netty.channel.nio.NioEventLoopGroup;
* Server * Server
*/ */
public abstract class Server { public abstract class Server {
private static final Logger logger = LoggerFactory.getLogger(Server.class);
@Value("${server.netty.thread.count.boss}") @Value("${server.netty.thread.count.boss}")
protected int threadCountBoss; protected int threadCountBoss;
@Value("${server.netty.thread.count.worker}") @Value("${server.netty.thread.count.worker}")
protected int threadCountWorker; protected int threadCountWorker;
@Autowired @Autowired
protected List<Class<ServerChannel>> channelClasses; protected List<Class<? extends ServerChannel>> channelClasses;
@Autowired @Autowired
protected List<ChannelOptionItem<?>> channelOptions; protected List<ChannelOptionItem<?>> channelOptions;
@ -45,7 +49,7 @@ public abstract class Server {
serverBootstrap.group(bossGroup, workerGroup); serverBootstrap.group(bossGroup, workerGroup);
if (null != this.channelClasses) { if (null != this.channelClasses) {
for (Class<ServerChannel> channelClass : this.channelClasses) { for (Class<? extends ServerChannel> channelClass : this.channelClasses) {
serverBootstrap.channel(channelClass); serverBootstrap.channel(channelClass);
} }
} }
@ -68,7 +72,7 @@ public abstract class Server {
f.channel().closeFuture().sync(); f.channel().closeFuture().sync();
} catch (Exception e) { } catch (Exception e) {
logger.error("Server", e);
} finally { } finally {
this.onStop(); this.onStop();
bossGroup.shutdownGracefully(); bossGroup.shutdownGracefully();