From 7b2dc52a353b0aa5303b80d17344c0dd8f0f33dd Mon Sep 17 00:00:00 2001 From: redkale Date: Tue, 31 Jan 2023 10:59:25 +0800 Subject: [PATCH] =?UTF-8?q?ClusterAgent=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redkale/cluster/CacheClusterAgent.java | 4 ++++ src/main/java/org/redkale/cluster/ClusterAgent.java | 7 +++++-- src/main/java/org/redkale/net/sncp/Sncp.java | 12 ++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/redkale/cluster/CacheClusterAgent.java b/src/main/java/org/redkale/cluster/CacheClusterAgent.java index 6d7273341..e2a81821d 100644 --- a/src/main/java/org/redkale/cluster/CacheClusterAgent.java +++ b/src/main/java/org/redkale/cluster/CacheClusterAgent.java @@ -175,6 +175,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { protected void checkLocalHealth(final ClusterEntry entry) { AddressEntry newaddr = new AddressEntry(); newaddr.addr = entry.address; + newaddr.resname = entry.resourceName; newaddr.nodeid = this.nodeid; newaddr.time = System.currentTimeMillis(); source.hset(entry.checkName, entry.checkid, AddressEntry.class, newaddr); @@ -266,6 +267,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { ClusterEntry clusterEntry = new ClusterEntry(ns, protocol, service); AddressEntry entry = new AddressEntry(); entry.addr = clusterEntry.address; + entry.resname = clusterEntry.resourceName; entry.nodeid = this.nodeid; entry.time = System.currentTimeMillis(); source.hset(clusterEntry.serviceName, clusterEntry.serviceid, AddressEntry.class, entry); @@ -347,6 +349,8 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { public long time; + public String resname; + public AddressEntry() { } diff --git a/src/main/java/org/redkale/cluster/ClusterAgent.java b/src/main/java/org/redkale/cluster/ClusterAgent.java index 2ca724000..dbb77163d 100644 --- a/src/main/java/org/redkale/cluster/ClusterAgent.java +++ b/src/main/java/org/redkale/cluster/ClusterAgent.java @@ -377,7 +377,9 @@ public abstract class ClusterAgent { //以协议+Rest资源名为主 服务类名 public String serviceName; - public String serviceType; + public String resourceType; + + public String resourceName; public String checkid; @@ -403,7 +405,8 @@ public abstract class ClusterAgent { this.serviceName = generateServiceName(ns, protocol, service); this.checkid = generateCheckId(ns, protocol, service); this.checkName = generateCheckName(ns, protocol, service); - this.serviceType = Sncp.getResourceType(service).getName(); + this.resourceType = Sncp.getResourceType(service).getName(); + this.resourceName = Sncp.getResourceName(service); this.protocol = protocol; InetSocketAddress addr = ns.getSocketAddress(); String host = addr.getHostString(); diff --git a/src/main/java/org/redkale/net/sncp/Sncp.java b/src/main/java/org/redkale/net/sncp/Sncp.java index c2497fb76..f99b41148 100644 --- a/src/main/java/org/redkale/net/sncp/Sncp.java +++ b/src/main/java/org/redkale/net/sncp/Sncp.java @@ -153,20 +153,12 @@ public abstract class Sncp { public static String getResourceName(Service service) { Resource res = service.getClass().getAnnotation(Resource.class); - if (res != null) { - return res.name(); - } - javax.annotation.Resource res2 = service.getClass().getAnnotation(javax.annotation.Resource.class); - return res2 == null ? null : res2.name(); + return res != null ? res.name() : null; } public static Class getResourceType(Service service) { ResourceType type = service.getClass().getAnnotation(ResourceType.class); - if (type != null) { - return type.value(); - } - org.redkale.util.ResourceType rt2 = service.getClass().getAnnotation(org.redkale.util.ResourceType.class); - return rt2 == null ? service.getClass() : rt2.value(); + return type != null ? type.value() : service.getClass(); } public static Class getServiceType(Service service) {