Browse Source

[Bug][Refactor][issue-3157]use cas to avoid thread safe problem (#3158)

Co-authored-by: lgcareer <18610854716@163.com>
pull/3/MERGE
tswstarplanet 4 years ago committed by GitHub
parent
commit
bf3cc0d00e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/NettyRemotingServer.java

69
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/NettyRemotingServer.java

@ -119,44 +119,39 @@ public class NettyRemotingServer {
* server start * server start
*/ */
public void start(){ public void start(){
if (isStarted.compareAndSet(false, true)) {
if(this.isStarted.get()){ this.serverBootstrap
return; .group(this.bossGroup, this.workGroup)
} .channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
this.serverBootstrap .option(ChannelOption.SO_BACKLOG, serverConfig.getSoBacklog())
.group(this.bossGroup, this.workGroup) .childOption(ChannelOption.SO_KEEPALIVE, serverConfig.isSoKeepalive())
.channel(NioServerSocketChannel.class) .childOption(ChannelOption.TCP_NODELAY, serverConfig.isTcpNoDelay())
.option(ChannelOption.SO_REUSEADDR, true) .childOption(ChannelOption.SO_SNDBUF, serverConfig.getSendBufferSize())
.option(ChannelOption.SO_BACKLOG, serverConfig.getSoBacklog()) .childOption(ChannelOption.SO_RCVBUF, serverConfig.getReceiveBufferSize())
.childOption(ChannelOption.SO_KEEPALIVE, serverConfig.isSoKeepalive()) .childHandler(new ChannelInitializer<NioSocketChannel>() {
.childOption(ChannelOption.TCP_NODELAY, serverConfig.isTcpNoDelay())
.childOption(ChannelOption.SO_SNDBUF, serverConfig.getSendBufferSize()) @Override
.childOption(ChannelOption.SO_RCVBUF, serverConfig.getReceiveBufferSize()) protected void initChannel(NioSocketChannel ch) throws Exception {
.childHandler(new ChannelInitializer<NioSocketChannel>() { initNettyChannel(ch);
}
@Override });
protected void initChannel(NioSocketChannel ch) throws Exception {
initNettyChannel(ch); ChannelFuture future;
} try {
}); future = serverBootstrap.bind(serverConfig.getListenPort()).sync();
} catch (Exception e) {
ChannelFuture future; logger.error("NettyRemotingServer bind fail {}, exit",e.getMessage(), e);
try { throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort()));
future = serverBootstrap.bind(serverConfig.getListenPort()).sync(); }
} catch (Exception e) { if (future.isSuccess()) {
logger.error("NettyRemotingServer bind fail {}, exit",e.getMessage(), e); logger.info("NettyRemotingServer bind success at port : {}", serverConfig.getListenPort());
throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort())); } else if (future.cause() != null) {
} throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort()), future.cause());
if (future.isSuccess()) { } else {
logger.info("NettyRemotingServer bind success at port : {}", serverConfig.getListenPort()); throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort()));
} else if (future.cause() != null) { }
throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort()), future.cause());
} else {
throw new RuntimeException(String.format("NettyRemotingServer bind %s fail", serverConfig.getListenPort()));
} }
//
isStarted.compareAndSet(false, true);
} }
/** /**

Loading…
Cancel
Save