This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
-->
|
-->
|
||||||
<!--
|
<!--
|
||||||
nodeid: int 进程的节点ID,用于分布式环境,一个系统中节点ID必须全局唯一,使用cluster时框架会进行唯一性校验
|
nodeid: int 进程的节点ID,用于分布式环境,一个系统中节点ID必须全局唯一,使用cluster时框架会进行唯一性校验
|
||||||
|
name: 进程的名称,用于监控识别,命名规则: 字母、数字、下划线
|
||||||
address: 本地局域网的IP地址, 默认值为默认网卡的ip,当不使用默认值需要指定值,如192.168.1.22
|
address: 本地局域网的IP地址, 默认值为默认网卡的ip,当不使用默认值需要指定值,如192.168.1.22
|
||||||
port: required 程序的管理Server的端口,用于关闭或者与监管系统进行数据交互
|
port: required 程序的管理Server的端口,用于关闭或者与监管系统进行数据交互
|
||||||
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
|
lib: 加上额外的lib路径,多个路径用分号;隔开; 默认为空。 例如: ${APP_HOME}/lib/a.jar;${APP_HOME}/lib2/b.jar;
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ public final class Application {
|
|||||||
*/
|
*/
|
||||||
public static final String RESNAME_APP_TIME = "APP_TIME";
|
public static final String RESNAME_APP_TIME = "APP_TIME";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前进程的名称, 类型:String
|
||||||
|
*/
|
||||||
|
public static final String RESNAME_APP_NAME = "APP_NAME";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前进程的根目录, 类型:String、File、Path、URI
|
* 当前进程的根目录, 类型:String、File、Path、URI
|
||||||
*/
|
*/
|
||||||
@@ -111,6 +116,9 @@ public final class Application {
|
|||||||
//本进程节点ID
|
//本进程节点ID
|
||||||
final int nodeid;
|
final int nodeid;
|
||||||
|
|
||||||
|
//本进程节点ID
|
||||||
|
final String name;
|
||||||
|
|
||||||
//本地IP地址
|
//本地IP地址
|
||||||
final InetSocketAddress localAddress;
|
final InetSocketAddress localAddress;
|
||||||
|
|
||||||
@@ -220,6 +228,11 @@ public final class Application {
|
|||||||
this.resourceFactory.register(RESNAME_APP_NODEID, nid);
|
this.resourceFactory.register(RESNAME_APP_NODEID, nid);
|
||||||
System.setProperty(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()
|
final URI logConfURI = "file".equals(confPath.getScheme()) ? new File(new File(confPath), "logging.properties").toURI()
|
||||||
: URI.create(confPath.toString() + (confPath.toString().endsWith("/") ? "" : "/") + "logging.properties");
|
: 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"));
|
.addValue(TransportFactory.NAME_CHECKINTERVAL, System.getProperty("net.transport.check.interval", "30"));
|
||||||
this.sncpTransportFactory.init(tarnsportConf, Sncp.PING_BUFFER, Sncp.PONG_BUFFER.remaining());
|
this.sncpTransportFactory.init(tarnsportConf, Sncp.PING_BUFFER, Sncp.PONG_BUFFER.remaining());
|
||||||
if (cluster != null) {
|
if (cluster != null) {
|
||||||
cluster.setNodeid(this.nodeid);
|
|
||||||
cluster.setTransportFactory(this.sncpTransportFactory);
|
cluster.setTransportFactory(this.sncpTransportFactory);
|
||||||
this.resourceFactory.inject(cluster);
|
this.resourceFactory.inject(cluster);
|
||||||
cluster.init(cluster.getConfig());
|
cluster.init(cluster.getConfig());
|
||||||
|
this.resourceFactory.register(ClusterAgent.class, cluster);
|
||||||
}
|
}
|
||||||
this.clusterAgent = cluster;
|
this.clusterAgent = cluster;
|
||||||
if (mqs != null) {
|
if (mqs != null) {
|
||||||
@@ -453,6 +466,17 @@ public final class Application {
|
|||||||
this.serverClassLoader = new RedkaleClassLoader(this.classLoader);
|
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() {
|
public ResourceFactory getResourceFactory() {
|
||||||
return resourceFactory;
|
return resourceFactory;
|
||||||
}
|
}
|
||||||
@@ -501,6 +525,10 @@ public final class Application {
|
|||||||
return nodeid;
|
return nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public File getHome() {
|
public File getHome() {
|
||||||
return home;
|
return home;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import java.net.InetSocketAddress;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import javax.annotation.Resource;
|
||||||
import org.redkale.boot.*;
|
import org.redkale.boot.*;
|
||||||
|
import static org.redkale.boot.Application.*;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.net.*;
|
import org.redkale.net.*;
|
||||||
import org.redkale.net.http.WebSocketNode;
|
import org.redkale.net.http.WebSocketNode;
|
||||||
@@ -32,8 +34,15 @@ public abstract class ClusterAgent {
|
|||||||
|
|
||||||
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||||
|
|
||||||
|
@Resource(name = RESNAME_APP_NODEID)
|
||||||
protected int nodeid;
|
protected int nodeid;
|
||||||
|
|
||||||
|
@Resource(name = RESNAME_APP_NAME)
|
||||||
|
protected String appName = "";
|
||||||
|
|
||||||
|
@Resource(name = RESNAME_APP_ADDR)
|
||||||
|
protected InetSocketAddress appAddress;
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
protected boolean waits;
|
protected boolean waits;
|
||||||
@@ -166,11 +175,11 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationServiceName() {
|
protected String generateApplicationServiceName() {
|
||||||
return "application.node." + this.nodeid;
|
return "application" + (appName == null || appName.isEmpty() ? "" : ("." + appName)) + ".node" + this.nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationServiceId() { //与servicename相同
|
protected String generateApplicationServiceId() { //与servicename相同
|
||||||
return "application.node." + this.nodeid;
|
return generateApplicationServiceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationCheckName() {
|
protected String generateApplicationCheckName() {
|
||||||
@@ -214,14 +223,6 @@ public abstract class ClusterAgent {
|
|||||||
return JsonConvert.root().convertTo(this);
|
return JsonConvert.root().convertTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNodeid() {
|
|
||||||
return nodeid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeid(int nodeid) {
|
|
||||||
this.nodeid = nodeid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransportFactory getTransportFactory() {
|
public TransportFactory getTransportFactory() {
|
||||||
return transportFactory;
|
return transportFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user