|
|
@@ -36,9 +36,13 @@ public abstract class NettyTcpServer {
|
|
|
}
|
|
|
|
|
|
this.serverBootstrap = ServerBootstrapFactory.createBootstrap(this.config, this.channelInitializer);
|
|
|
+ this.acceptGroups = this.serverBootstrap.config().group();
|
|
|
+ this.workerGroups = this.serverBootstrap.config().childGroup();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("NettyTcpServer createBootstrap exception: {}", e.getMessage());
|
|
|
+ log.error("NettyTcpServer cannot be started. It will be terminated. *************************************");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
log.info(" bindAddress: {}", this.config.getBindingAddr());
|
|
|
@@ -57,19 +61,26 @@ public abstract class NettyTcpServer {
|
|
|
}
|
|
|
catch (Exception e) {
|
|
|
log.error("NettyTcpServer bind exception: {}", e.getMessage());
|
|
|
- this.acceptGroups.shutdownGracefully();
|
|
|
- this.workerGroups.shutdownGracefully();
|
|
|
+ if (this.acceptGroups != null) this.acceptGroups.shutdownGracefully();
|
|
|
+ if (this.workerGroups != null) this.workerGroups.shutdownGracefully();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void stop() {
|
|
|
try {
|
|
|
- this.acceptGroups.shutdownGracefully().sync();
|
|
|
- this.workerGroups.shutdownGracefully().sync();
|
|
|
- this.channelFuture.channel().closeFuture().sync();
|
|
|
+ if (this.acceptGroups != null) {
|
|
|
+ this.acceptGroups.shutdownGracefully().sync();
|
|
|
+ }
|
|
|
+ if (this.workerGroups != null) {
|
|
|
+ this.workerGroups.shutdownGracefully().sync();
|
|
|
+ }
|
|
|
+// if (this.channelFuture != null && this.channelFuture.channel() != null) {
|
|
|
+// this.channelFuture.channel().closeFuture().sync();
|
|
|
+// }
|
|
|
}
|
|
|
catch (InterruptedException e) {
|
|
|
log.error("NettyTcpServer stop interrupt: {}", e.getMessage());
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
}
|
|
|
}
|
|
|
}
|