This commit is contained in:
redkale
2023-10-07 08:45:28 +08:00
parent 4351b74a91
commit 89ff54a15e
2 changed files with 16 additions and 20 deletions

View File

@@ -41,10 +41,10 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
protected ScheduledFuture taskFuture;
//可能被HttpMessageClient用到的服务 key: serviceName
//可能被HttpMessageClient用到的服务 key: serviceName,例如: cluster.service.http.user
protected final ConcurrentHashMap<String, Set<InetSocketAddress>> httpAddressMap = new ConcurrentHashMap<>();
//可能被sncp用到的服务 key: serviceName
//可能被sncp用到的服务 key: serviceName, 例如: cluster.service.sncp.user
protected final ConcurrentHashMap<String, Set<InetSocketAddress>> sncpAddressMap = new ConcurrentHashMap<>();
@Override

View File

@@ -131,6 +131,13 @@ public abstract class ClusterAgent {
return Utility.contains(ports, port);
}
public void start() {
}
public int intervalCheckSeconds() {
return 10;
}
public abstract void register(Application application);
public abstract void deregister(Application application);
@@ -191,15 +198,12 @@ public abstract class ClusterAgent {
}
}
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
if (entry.serviceName.trim().endsWith(serviceSeparator())) {
if (entry.serviceName.trim().endsWith(".")) {
return false;
}
return true;
}
public void start() {
}
protected void afterDeregister(NodeServer ns, String protocol) {
if (!this.waits) {
return;
@@ -214,10 +218,6 @@ public abstract class ClusterAgent {
}
}
public int intervalCheckSeconds() {
return 10;
}
//获取HTTP远程服务的可用ip列表
public abstract CompletableFuture<Set<InetSocketAddress>> queryHttpAddress(String protocol, String module, String resname);
@@ -283,17 +283,13 @@ public abstract class ClusterAgent {
return this.appAddress.getPort();
}
protected String serviceSeparator() {
return ".";
}
public String generateSncpServiceName(String protocol, String restype, String resname) {
return protocol.toLowerCase() + serviceSeparator() + restype + (resname == null || resname.isEmpty() ? "" : ("-" + resname));
return protocol.toLowerCase() + "." + restype + (resname == null || resname.isEmpty() ? "" : ("-" + resname));
}
//也会提供给HttpMessageClusterAgent适用
public String generateHttpServiceName(String protocol, String module, String resname) {
return protocol.toLowerCase() + serviceSeparator() + module + (resname == null || resname.isEmpty() ? "" : ("-" + resname));
return protocol.toLowerCase() + "." + module + (resname == null || resname.isEmpty() ? "" : ("-" + resname));
}
//格式: protocol:classtype-resourcename
@@ -301,18 +297,18 @@ public abstract class ClusterAgent {
if (protocol.toLowerCase().startsWith("http")) { //HTTP使用RestService.name方式是为了与MessageClient中的module保持一致, 因为HTTP依靠的url中的module无法知道Service类名
String resname = Sncp.getResourceName(service);
String module = Rest.getRestModule(service).toLowerCase();
return protocol.toLowerCase() + serviceSeparator() + module + (resname.isEmpty() ? "" : ("-" + resname));
return protocol.toLowerCase() + "." + module + (resname.isEmpty() ? "" : ("-" + resname));
}
if (!Sncp.isSncpDyn(service)) {
return protocol.toLowerCase() + serviceSeparator() + service.getClass().getName();
return protocol.toLowerCase() + "." + service.getClass().getName();
}
String resname = Sncp.getResourceName(service);
return protocol.toLowerCase() + serviceSeparator() + Sncp.getResourceType(service).getName() + (resname.isEmpty() ? "" : ("-" + resname));
return protocol.toLowerCase() + "." + Sncp.getResourceType(service).getName() + (resname.isEmpty() ? "" : ("-" + resname));
}
//格式: protocol:classtype-resourcename:nodeid
protected String generateServiceId(NodeServer ns, String protocol, Service service) {
return generateServiceName(ns, protocol, service) + serviceSeparator() + this.nodeid;
return generateServiceName(ns, protocol, service) + "." + this.nodeid;
}
protected String generateCheckName(NodeServer ns, String protocol, Service service) {