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(); this.init();
ChannelFuture f = serverBootstrap.bind(address).sync(); ChannelFuture cf = this.bind(serverBootstrap);
cf.sync();
this.onStart(); this.onStart();
f.channel().closeFuture().sync(); cf.channel().closeFuture().sync();
this.onStop();
} catch (Exception e) { } catch (Exception e) {
logger.error("Server", e); logger.error("Server", e);
} finally { } finally {
this.onStop();
bossGroup.shutdownGracefully(); bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully(); workerGroup.shutdownGracefully();
this.destroy(); this.destroy();
} }
} }
protected ChannelFuture bind(ServerBootstrap serverBootstrap) throws Exception {
return serverBootstrap.bind(address);
}
protected abstract void init() throws Exception; protected abstract void init() throws Exception;
protected abstract void onStart() throws Exception; protected abstract void onStart() throws Exception;
protected abstract void onStop() throws Exception; protected abstract void onStop() throws Exception;