Application加入nodeid属性

This commit is contained in:
Redkale
2020-05-15 14:38:53 +08:00
parent e4bb75dd8e
commit 9a51c1de1d
2 changed files with 15 additions and 17 deletions

View File

@@ -21,9 +21,10 @@
<!--
address: 本地局域网的IP地址 默认值为默认网卡的ip当不使用默认值需要指定值如192.168.1.22
port: required 程序的管理Server的端口用于关闭或者与监管系统进行数据交互
nodeid: int 进程节点ID值默认0一般用于分布式环境
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
-->
<application port="6560" lib="">
<application nodeid="10" port="6560" lib="">
<!--
【节点全局唯一】

View File

@@ -72,9 +72,9 @@ public final class Application {
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
@@ -106,6 +106,9 @@ public final class Application {
*/
public static final String RESNAME_SERVER_RESFACTORY = Server.RESNAME_SERVER_RESFACTORY;
//本进程节点ID
final int nodeid;
//本地IP地址
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, InetAddress.class, this.localAddress);
{
String node = config.getValue("node", "").trim();
if (node.isEmpty()) {
StringBuilder sb = new StringBuilder();
byte[] bs = this.localAddress.getAddress();
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);
int nid = config.getIntValue("nodeid", 0);
this.nodeid = nid;
this.resourceFactory.register(RESNAME_APP_NODEID, nid);
System.setProperty(RESNAME_APP_NODEID, "" + nid);
}
//以下是初始化日志配置
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);
}
public int getNodeid() {
return nodeid;
}
public File getHome() {
return home;
}