Application加入nodeid属性
This commit is contained in:
@@ -21,9 +21,10 @@
|
|||||||
<!--
|
<!--
|
||||||
address: 本地局域网的IP地址, 默认值为默认网卡的ip,当不使用默认值需要指定值,如192.168.1.22
|
address: 本地局域网的IP地址, 默认值为默认网卡的ip,当不使用默认值需要指定值,如192.168.1.22
|
||||||
port: required 程序的管理Server的端口,用于关闭或者与监管系统进行数据交互
|
port: required 程序的管理Server的端口,用于关闭或者与监管系统进行数据交互
|
||||||
|
nodeid: int 进程节点ID值,默认0,一般用于分布式环境
|
||||||
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
|
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
|
||||||
-->
|
-->
|
||||||
<application port="6560" lib="">
|
<application nodeid="10" port="6560" lib="">
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
【节点全局唯一】
|
【节点全局唯一】
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ public final class Application {
|
|||||||
public static final String RESNAME_APP_GRES = "APP_GRES";
|
public static final String RESNAME_APP_GRES = "APP_GRES";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前进程节点的name, 类型:String
|
* 当前进程节点的nodeid, 类型:int
|
||||||
*/
|
*/
|
||||||
public static final String RESNAME_APP_NODE = "APP_NODE";
|
public static final String RESNAME_APP_NODEID = "APP_NODEID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前进程节点的IP地址, 类型:InetAddress、String
|
* 当前进程节点的IP地址, 类型:InetAddress、String
|
||||||
@@ -106,6 +106,9 @@ public final class Application {
|
|||||||
*/
|
*/
|
||||||
public static final String RESNAME_SERVER_RESFACTORY = Server.RESNAME_SERVER_RESFACTORY;
|
public static final String RESNAME_SERVER_RESFACTORY = Server.RESNAME_SERVER_RESFACTORY;
|
||||||
|
|
||||||
|
//本进程节点ID
|
||||||
|
final int nodeid;
|
||||||
|
|
||||||
//本地IP地址
|
//本地IP地址
|
||||||
final InetAddress localAddress;
|
final InetAddress localAddress;
|
||||||
|
|
||||||
@@ -196,20 +199,10 @@ public final class Application {
|
|||||||
this.resourceFactory.register(RESNAME_APP_ADDR, this.localAddress.getHostAddress());
|
this.resourceFactory.register(RESNAME_APP_ADDR, this.localAddress.getHostAddress());
|
||||||
this.resourceFactory.register(RESNAME_APP_ADDR, InetAddress.class, this.localAddress);
|
this.resourceFactory.register(RESNAME_APP_ADDR, InetAddress.class, this.localAddress);
|
||||||
{
|
{
|
||||||
String node = config.getValue("node", "").trim();
|
int nid = config.getIntValue("nodeid", 0);
|
||||||
if (node.isEmpty()) {
|
this.nodeid = nid;
|
||||||
StringBuilder sb = new StringBuilder();
|
this.resourceFactory.register(RESNAME_APP_NODEID, nid);
|
||||||
byte[] bs = this.localAddress.getAddress();
|
System.setProperty(RESNAME_APP_NODEID, "" + nid);
|
||||||
int v1 = bs[bs.length - 2] & 0xff;
|
|
||||||
int v2 = bs[bs.length - 1] & 0xff;
|
|
||||||
if (v1 <= 0xf) sb.append('0');
|
|
||||||
sb.append(Integer.toHexString(v1));
|
|
||||||
if (v2 <= 0xf) sb.append('0');
|
|
||||||
sb.append(Integer.toHexString(v2));
|
|
||||||
node = sb.toString();
|
|
||||||
}
|
|
||||||
this.resourceFactory.register(RESNAME_APP_NODE, node);
|
|
||||||
System.setProperty(RESNAME_APP_NODE, node);
|
|
||||||
}
|
}
|
||||||
//以下是初始化日志配置
|
//以下是初始化日志配置
|
||||||
final URI logConfURI = "file".equals(confPath.getScheme()) ? new File(new File(confPath), "logging.properties").toURI()
|
final URI logConfURI = "file".equals(confPath.getScheme()) ? new File(new File(confPath), "logging.properties").toURI()
|
||||||
@@ -375,6 +368,10 @@ public final class Application {
|
|||||||
return new ArrayList<>(cacheSources);
|
return new ArrayList<>(cacheSources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNodeid() {
|
||||||
|
return nodeid;
|
||||||
|
}
|
||||||
|
|
||||||
public File getHome() {
|
public File getHome() {
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user