This commit is contained in:
Redkale
2020-06-11 17:27:25 +08:00
parent 1329f6f0e1
commit 92bb0a561b
3 changed files with 41 additions and 11 deletions

View File

@@ -20,6 +20,7 @@
-->
<!--
nodeid: int 进程的节点ID用于分布式环境一个系统中节点ID必须全局唯一使用cluster时框架会进行唯一性校验
name: 进程的名称,用于监控识别,命名规则: 字母、数字、下划线
address: 本地局域网的IP地址 默认值为默认网卡的ip当不使用默认值需要指定值如192.168.1.22
port: required 程序的管理Server的端口用于关闭或者与监管系统进行数据交互
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;

View File

@@ -58,6 +58,11 @@ public final class Application {
*/
public static final String RESNAME_APP_TIME = "APP_TIME";
/**
* 当前进程的名称, 类型String
*/
public static final String RESNAME_APP_NAME = "APP_NAME";
/**
* 当前进程的根目录, 类型String、File、Path、URI
*/
@@ -111,6 +116,9 @@ public final class Application {
//本进程节点ID
final int nodeid;
//本进程节点ID
final String name;
//本地IP地址
final InetSocketAddress localAddress;
@@ -220,6 +228,11 @@ public final class Application {
this.resourceFactory.register(RESNAME_APP_NODEID, nid);
System.setProperty(RESNAME_APP_NODEID, "" + nid);
}
{
this.name = checkName(config.getValue("name", ""));
this.resourceFactory.register(RESNAME_APP_NAME, name);
System.setProperty(RESNAME_APP_NAME, name);
}
//以下是初始化日志配置
final URI logConfURI = "file".equals(confPath.getScheme()) ? new File(new File(confPath), "logging.properties").toURI()
: URI.create(confPath.toString() + (confPath.toString().endsWith("/") ? "" : "/") + "logging.properties");
@@ -433,10 +446,10 @@ public final class Application {
.addValue(TransportFactory.NAME_CHECKINTERVAL, System.getProperty("net.transport.check.interval", "30"));
this.sncpTransportFactory.init(tarnsportConf, Sncp.PING_BUFFER, Sncp.PONG_BUFFER.remaining());
if (cluster != null) {
cluster.setNodeid(this.nodeid);
cluster.setTransportFactory(this.sncpTransportFactory);
this.resourceFactory.inject(cluster);
cluster.init(cluster.getConfig());
this.resourceFactory.register(ClusterAgent.class, cluster);
}
this.clusterAgent = cluster;
if (mqs != null) {
@@ -453,6 +466,17 @@ public final class Application {
this.serverClassLoader = new RedkaleClassLoader(this.classLoader);
}
private String checkName(String name) { //不能含特殊字符
if (name.isEmpty()) return name;
if (name.charAt(0) >= '0' && name.charAt(0) <= '9') throw new RuntimeException("name only 0-9 a-z A-Z _ cannot begin 0-9");
for (char ch : name.toCharArray()) {
if (!((ch >= '0' && ch <= '9') || ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符
throw new RuntimeException("name only 0-9 a-z A-Z _ cannot begin 0-9");
}
}
return name;
}
public ResourceFactory getResourceFactory() {
return resourceFactory;
}
@@ -501,6 +525,10 @@ public final class Application {
return nodeid;
}
public String getName() {
return name;
}
public File getHome() {
return home;
}

View File

@@ -10,7 +10,9 @@ import java.net.InetSocketAddress;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Logger;
import javax.annotation.Resource;
import org.redkale.boot.*;
import static org.redkale.boot.Application.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.net.*;
import org.redkale.net.http.WebSocketNode;
@@ -32,8 +34,15 @@ public abstract class ClusterAgent {
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
@Resource(name = RESNAME_APP_NODEID)
protected int nodeid;
@Resource(name = RESNAME_APP_NAME)
protected String appName = "";
@Resource(name = RESNAME_APP_ADDR)
protected InetSocketAddress appAddress;
protected String name;
protected boolean waits;
@@ -166,11 +175,11 @@ public abstract class ClusterAgent {
}
protected String generateApplicationServiceName() {
return "application.node." + this.nodeid;
return "application" + (appName == null || appName.isEmpty() ? "" : ("." + appName)) + ".node" + this.nodeid;
}
protected String generateApplicationServiceId() { //与servicename相同
return "application.node." + this.nodeid;
return generateApplicationServiceName();
}
protected String generateApplicationCheckName() {
@@ -214,14 +223,6 @@ public abstract class ClusterAgent {
return JsonConvert.root().convertTo(this);
}
public int getNodeid() {
return nodeid;
}
public void setNodeid(int nodeid) {
this.nodeid = nodeid;
}
public TransportFactory getTransportFactory() {
return transportFactory;
}