From 89ff54a15ecaee8b476fe590dcad69e0297a8de2 Mon Sep 17 00:00:00 2001 From: redkale Date: Sat, 7 Oct 2023 08:45:28 +0800 Subject: [PATCH] cluster --- .../redkale/cluster/CacheClusterAgent.java | 4 +-- .../org/redkale/cluster/ClusterAgent.java | 32 ++++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/redkale/cluster/CacheClusterAgent.java b/src/main/java/org/redkale/cluster/CacheClusterAgent.java index b7cccf807..2da0677c7 100644 --- a/src/main/java/org/redkale/cluster/CacheClusterAgent.java +++ b/src/main/java/org/redkale/cluster/CacheClusterAgent.java @@ -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> httpAddressMap = new ConcurrentHashMap<>(); - //可能被sncp用到的服务 key: serviceName + //可能被sncp用到的服务 key: serviceName, 例如: cluster.service.sncp.user protected final ConcurrentHashMap> sncpAddressMap = new ConcurrentHashMap<>(); @Override diff --git a/src/main/java/org/redkale/cluster/ClusterAgent.java b/src/main/java/org/redkale/cluster/ClusterAgent.java index 7382fb565..c476d4a7f 100644 --- a/src/main/java/org/redkale/cluster/ClusterAgent.java +++ b/src/main/java/org/redkale/cluster/ClusterAgent.java @@ -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> 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) {