Skip to content

Commit

Permalink
agent自动探测ip
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfboys committed Jun 25, 2018
1 parent 55faec8 commit 121096b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions jobx-agent/src/conf/conf/conf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ jobx.password=jobx
#jobx-agent默认启动端口
jobx.port=1577

#agent Ip,确保server可以通过此ip访问到该agent(主要实现agent自动注册)
jobx.host=127.0.0.1
#
# agent Ip,确保server可以通过此ip访问到该agent(主要实现agent自动注册)
# 程序中做了自动探测ip的功能,如存在以下两种情况请手动设置host,
# 1)agent探测出来的ip在server端连接不上
# 2)如果在多块网卡的情况下会选择一块,可能存在server连接不上
#jobx.host=127.0.0.1

#zookepper注册中心
jobx.registry=zookeeper://127.0.0.1:2181
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,16 @@ private void init() {
if (isEmpty(this.host)) {
this.host = PropertiesLoader.getProperty(Constants.PARAM_JOBX_HOST_KEY);
}
if (notEmpty(this.host) && NetUtils.isValidAddress(this.host)) {
if (isEmpty(this.host)) {
//自动探测ip
this.host = NetUtils.getLocalHost();
}

if (isEmpty(this.host)) {
throw new ExceptionInInitializerError("[JobX] agent host must be not empty.");
}

if(NetUtils.isValidAddress(this.host)){
throw new ExceptionInInitializerError("[JobX] agent host is valid");
}

Expand Down

0 comments on commit 121096b

Please sign in to comment.