This commit is contained in:
crusader 2018-04-24 02:09:12 +09:00
parent 68763a3c73
commit 414c2cdb2f

View File

@ -67,20 +67,26 @@ public abstract class Server {
this.init();
ChannelFuture f = serverBootstrap.bind(address).sync();
ChannelFuture cf = this.bind(serverBootstrap);
cf.sync();
this.onStart();
f.channel().closeFuture().sync();
cf.channel().closeFuture().sync();
this.onStop();
} catch (Exception e) {
logger.error("Server", e);
} finally {
this.onStop();
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
this.destroy();
}
}
protected ChannelFuture bind(ServerBootstrap serverBootstrap) throws Exception {
return serverBootstrap.bind(address);
}
protected abstract void init() throws Exception;
protected abstract void onStart() throws Exception;
protected abstract void onStop() throws Exception;