Skip to content

Commit

Permalink
fix listenPort allow user defined
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly committed Jan 9, 2019
1 parent 1886b12 commit 8e642b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public abstract class AbstractRpcRemotingServer extends AbstractRpcRemoting impl
private final EventLoopGroup eventLoopGroupBoss;
private final NettyServerConfig nettyServerConfig;
private DefaultEventExecutorGroup defaultEventExecutorGroup;

private int listenPort;

public void setListenPort(int listenPort) {
Expand Down Expand Up @@ -99,7 +98,6 @@ public AbstractRpcRemotingServer(final NettyServerConfig nettyServerConfig,
if (null != handlers) {
channelHandlers = handlers;
}
this.listenPort = nettyServerConfig.getListenPort();

}

Expand All @@ -109,6 +107,9 @@ public void start() {
nettyServerConfig.getServerWorkerThreads(),
new NamedThreadFactory(nettyServerConfig.getExecutorThreadPrefix(),
nettyServerConfig.getServerWorkerThreads()));
if (listenPort == 0) {
listenPort = nettyServerConfig.getDefaultListenPort();
}
this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker)
.channel(nettyServerConfig.SERVER_CHANNEL_CLAZZ)
.option(ChannelOption.SO_BACKLOG, nettyServerConfig.getSoBackLogSize())
Expand Down Expand Up @@ -139,7 +140,7 @@ public void initChannel(SocketChannel ch) {

try {
LOGGER.info("Server starting ... ");
ChannelFuture future = this.serverBootstrap.bind(this.nettyServerConfig.getListenPort()).sync();
ChannelFuture future = this.serverBootstrap.bind(listenPort).sync();
LOGGER.info("Server started ... ");
future.channel().closeFuture().sync();
} catch (InterruptedException exx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class NettyServerConfig extends NettyBaseConfig {
private int soBackLogSize = 1024;
private int writeBufferHighWaterMark = 67108864;
private int writeBufferLowWaterMark = 1048576;
private int listenPort = 8091;
private static final int DEFAULT_LISTEN_PORT = 8091;
private static final int RPC_REQUEST_TIMEOUT = 30 * 1000;
private boolean enableServerPooledByteBufAllocator = true;
private int serverChannelMaxIdleTimeSeconds = 30;
Expand Down Expand Up @@ -216,8 +216,8 @@ public void setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
*
* @return the listen port
*/
public int getListenPort() {
return listenPort;
public int getDefaultListenPort() {
return DEFAULT_LISTEN_PORT;
}

/**
Expand Down

0 comments on commit 8e642b9

Please sign in to comment.