This commit is contained in:
@@ -19,10 +19,9 @@
|
|||||||
serviceid1_name1 serviceid1_name2 serviceid2_name1 serviceid2_name2
|
serviceid1_name1 serviceid1_name2 serviceid2_name1 serviceid2_name2
|
||||||
-->
|
-->
|
||||||
<!--
|
<!--
|
||||||
nodeid: 进程的节点ID,一个系统中进程节点ID最好不要重复。
|
nodeid: int 进程的节点ID,用于分布式环境,一个系统中节点ID必须全局唯一,使用cluster时框架会进行唯一性校验
|
||||||
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 nodeid="1000" port="6560" lib="">
|
<application nodeid="1000" port="6560" lib="">
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public final class Application {
|
|||||||
public static final String RESNAME_APP_NODEID = "APP_NODEID";
|
public static final String RESNAME_APP_NODEID = "APP_NODEID";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前进程节点的IP地址, 类型:InetAddress、String
|
* 当前进程节点的IP地址, 类型:InetSocketAddress、InetAddress、String
|
||||||
*/
|
*/
|
||||||
public static final String RESNAME_APP_ADDR = "APP_ADDR";
|
public static final String RESNAME_APP_ADDR = "APP_ADDR";
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ public final class Application {
|
|||||||
final int nodeid;
|
final int nodeid;
|
||||||
|
|
||||||
//本地IP地址
|
//本地IP地址
|
||||||
final InetAddress localAddress;
|
final InetSocketAddress localAddress;
|
||||||
|
|
||||||
//CacheSource 资源
|
//CacheSource 资源
|
||||||
final List<CacheSource> cacheSources = new CopyOnWriteArrayList<>();
|
final List<CacheSource> cacheSources = new CopyOnWriteArrayList<>();
|
||||||
@@ -208,9 +208,12 @@ public final class Application {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
String localaddr = config.getValue("address", "").trim();
|
String localaddr = config.getValue("address", "").trim();
|
||||||
this.localAddress = localaddr.isEmpty() ? Utility.localInetAddress() : new InetSocketAddress(localaddr, config.getIntValue("port")).getAddress();
|
InetAddress addr = localaddr.isEmpty() ? Utility.localInetAddress() : new InetSocketAddress(localaddr, config.getIntValue("port")).getAddress();
|
||||||
this.resourceFactory.register(RESNAME_APP_ADDR, this.localAddress.getHostAddress());
|
this.localAddress = new InetSocketAddress(addr, config.getIntValue("port"));
|
||||||
this.resourceFactory.register(RESNAME_APP_ADDR, InetAddress.class, this.localAddress);
|
this.resourceFactory.register(RESNAME_APP_ADDR, addr.getHostAddress());
|
||||||
|
this.resourceFactory.register(RESNAME_APP_ADDR, InetAddress.class, addr);
|
||||||
|
this.resourceFactory.register(RESNAME_APP_ADDR, InetSocketAddress.class, this.localAddress);
|
||||||
|
|
||||||
{
|
{
|
||||||
int nid = config.getIntValue("nodeid", 0);
|
int nid = config.getIntValue("nodeid", 0);
|
||||||
this.nodeid = nid;
|
this.nodeid = nid;
|
||||||
@@ -541,7 +544,7 @@ public final class Application {
|
|||||||
pidstr = "APP_PID = " + pid + "\r\n";
|
pidstr = "APP_PID = " + pid + "\r\n";
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
}
|
}
|
||||||
logger.log(Level.INFO, pidstr + "APP_JAVA = " + System.getProperty("java.version") + "\r\n" + RESNAME_APP_NODEID + " = " + this.nodeid + "\r\n" + RESNAME_APP_ADDR + " = " + this.localAddress.getHostAddress() + "\r\n" + RESNAME_APP_HOME + " = " + homepath + "\r\n" + RESNAME_APP_CONF + " = " + confpath);
|
logger.log(Level.INFO, pidstr + "APP_JAVA = " + System.getProperty("java.version") + "\r\n" + RESNAME_APP_NODEID + " = " + this.nodeid + "\r\n" + RESNAME_APP_ADDR + " = " + this.localAddress.getHostString() + ":" + this.localAddress.getPort() + "\r\n" + RESNAME_APP_HOME + " = " + homepath + "\r\n" + RESNAME_APP_CONF + " = " + confpath);
|
||||||
String lib = config.getValue("lib", "${APP_HOME}/libs/*").trim().replace("${APP_HOME}", homepath);
|
String lib = config.getValue("lib", "${APP_HOME}/libs/*").trim().replace("${APP_HOME}", homepath);
|
||||||
lib = lib.isEmpty() ? confpath : (lib + ";" + confpath);
|
lib = lib.isEmpty() ? confpath : (lib + ";" + confpath);
|
||||||
Server.loadLib(classLoader, logger, lib);
|
Server.loadLib(classLoader, logger, lib);
|
||||||
@@ -802,6 +805,9 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
|
if (!singletonrun && this.clusterAgent != null) {
|
||||||
|
this.clusterAgent.register(this);
|
||||||
|
}
|
||||||
final AnyValue[] entrys = config.getAnyValues("server");
|
final AnyValue[] entrys = config.getAnyValues("server");
|
||||||
CountDownLatch timecd = new CountDownLatch(entrys.length);
|
CountDownLatch timecd = new CountDownLatch(entrys.length);
|
||||||
final List<AnyValue> sncps = new ArrayList<>();
|
final List<AnyValue> sncps = new ArrayList<>();
|
||||||
@@ -1081,6 +1087,7 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (clusterAgent != null) {
|
if (clusterAgent != null) {
|
||||||
|
clusterAgent.deregister(this);
|
||||||
clusterAgent.destroy(clusterAgent.getConfig());
|
clusterAgent.destroy(clusterAgent.getConfig());
|
||||||
}
|
}
|
||||||
if (this.messageAgents != null) {
|
if (this.messageAgents != null) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ public abstract class NodeServer {
|
|||||||
this.serverConf = config == null ? AnyValue.create() : config;
|
this.serverConf = config == null ? AnyValue.create() : config;
|
||||||
if (isSNCP()) { // SNCP协议
|
if (isSNCP()) { // SNCP协议
|
||||||
String host = this.serverConf.getValue("host", isWATCH() ? "127.0.0.1" : "0.0.0.0").replace("0.0.0.0", "");
|
String host = this.serverConf.getValue("host", isWATCH() ? "127.0.0.1" : "0.0.0.0").replace("0.0.0.0", "");
|
||||||
this.sncpAddress = new InetSocketAddress(host.isEmpty() ? application.localAddress.getHostAddress() : host, this.serverConf.getIntValue("port"));
|
this.sncpAddress = new InetSocketAddress(host.isEmpty() ? application.localAddress.getAddress().getHostAddress() : host, this.serverConf.getIntValue("port"));
|
||||||
this.sncpGroup = application.sncpTransportFactory.findGroupName(this.sncpAddress);
|
this.sncpGroup = application.sncpTransportFactory.findGroupName(this.sncpAddress);
|
||||||
//单向SNCP服务不需要对等group
|
//单向SNCP服务不需要对等group
|
||||||
//if (this.sncpGroup == null) throw new RuntimeException("Server (" + String.valueOf(config).replaceAll("\\s+", " ") + ") not found <group> info");
|
//if (this.sncpGroup == null) throw new RuntimeException("Server (" + String.valueOf(config).replaceAll("\\s+", " ") + ") not found <group> info");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ 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 org.redkale.boot.NodeServer;
|
import org.redkale.boot.*;
|
||||||
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;
|
||||||
@@ -87,6 +87,10 @@ public abstract class ClusterAgent {
|
|||||||
return Utility.contains(ports, port);
|
return Utility.contains(ports, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract void register(Application application);
|
||||||
|
|
||||||
|
public abstract void deregister(Application application);
|
||||||
|
|
||||||
//注册服务, 在NodeService调用Service.init方法之前调用
|
//注册服务, 在NodeService调用Service.init方法之前调用
|
||||||
public void register(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices) {
|
public void register(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices) {
|
||||||
if (localServices.isEmpty()) return;
|
if (localServices.isEmpty()) return;
|
||||||
@@ -161,6 +165,22 @@ public abstract class ClusterAgent {
|
|||||||
Sncp.updateTransport(service, transportFactory, Sncp.getResourceType(service).getName() + "-" + Sncp.getResourceName(service), entry.netprotocol, entry.address, null, addrs);
|
Sncp.updateTransport(service, transportFactory, Sncp.getResourceType(service).getName() + "-" + Sncp.getResourceName(service), entry.netprotocol, entry.address, null, addrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String generateApplicationServiceName() {
|
||||||
|
return "application.node." + this.nodeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String generateApplicationServiceId() { //与servicename相同
|
||||||
|
return "application.node." + this.nodeid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String generateApplicationCheckName() {
|
||||||
|
return "check-" + generateApplicationServiceName();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String generateApplicationCheckId() {
|
||||||
|
return "check-" + generateApplicationServiceId();
|
||||||
|
}
|
||||||
|
|
||||||
//格式: protocol:classtype-resourcename
|
//格式: protocol:classtype-resourcename
|
||||||
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
||||||
if (!Sncp.isSncpDyn(service)) return protocol.toLowerCase() + ":" + service.getClass().getName();
|
if (!Sncp.isSncpDyn(service)) return protocol.toLowerCase() + ":" + service.getClass().getName();
|
||||||
|
|||||||
Reference in New Issue
Block a user