diff --git a/src/main/java/com/loafle/commons/server/Server.java b/src/main/java/com/loafle/commons/server/Server.java index 4002ae7..7046226 100644 --- a/src/main/java/com/loafle/commons/server/Server.java +++ b/src/main/java/com/loafle/commons/server/Server.java @@ -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;