From 69c2baae519af4ea815e379631881186cabd0f61 Mon Sep 17 00:00:00 2001 From: redkale Date: Mon, 1 Jul 2024 13:10:25 +0800 Subject: [PATCH] ClusterAgent --- .../cluster/spi/CacheClusterAgent.java | 10 ++--- .../org/redkale/cluster/spi/ClusterAgent.java | 24 ++++++------ .../redkale/scheduled/spi/CronExpression.java | 38 +++++++++---------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/redkale/cluster/spi/CacheClusterAgent.java b/src/main/java/org/redkale/cluster/spi/CacheClusterAgent.java index af62da3c5..d17bab915 100644 --- a/src/main/java/org/redkale/cluster/spi/CacheClusterAgent.java +++ b/src/main/java/org/redkale/cluster/spi/CacheClusterAgent.java @@ -203,7 +203,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { newaddr.resname = entry.resourceName; newaddr.nodeid = this.nodeid; newaddr.time = System.currentTimeMillis(); - source.hset(entry.checkName, entry.checkid, AddressEntry.class, newaddr); + source.hset(entry.checkName, entry.checkId, AddressEntry.class, newaddr); } @Override // 获取SNCP远程服务的可用ip列表 @@ -309,7 +309,7 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { entry.resname = clusterEntry.resourceName; entry.nodeid = this.nodeid; entry.time = System.currentTimeMillis(); - source.hset(clusterEntry.serviceName, clusterEntry.serviceid, AddressEntry.class, entry); + source.hset(clusterEntry.serviceName, clusterEntry.serviceId, AddressEntry.class, entry); return clusterEntry; } @@ -320,14 +320,14 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable { protected void deregister(NodeServer ns, String protocol, Service service, boolean realCanceled) { String serviceName = generateServiceName(ns, protocol, service); - String serviceid = generateServiceId(ns, protocol, service); + String serviceId = generateServiceId(ns, protocol, service); Predicate predicate = - entry -> Objects.equals(entry.serviceName, serviceName) && Objects.equals(entry.serviceid, serviceid); + entry -> Objects.equals(entry.serviceName, serviceName) && Objects.equals(entry.serviceId, serviceId); ClusterEntry currEntry = Utility.find(localEntrys.values(), predicate); if (currEntry == null) { currEntry = Utility.find(remoteEntrys.values(), predicate); } - source.hdel(serviceName, serviceid); + source.hdel(serviceName, serviceId); if (realCanceled && currEntry != null) { currEntry.canceled = true; } diff --git a/src/main/java/org/redkale/cluster/spi/ClusterAgent.java b/src/main/java/org/redkale/cluster/spi/ClusterAgent.java index bef9811c1..b80f1b5af 100644 --- a/src/main/java/org/redkale/cluster/spi/ClusterAgent.java +++ b/src/main/java/org/redkale/cluster/spi/ClusterAgent.java @@ -61,10 +61,10 @@ public abstract class ClusterAgent { protected Set tags; - // key: serviceid + // key: serviceId protected final ConcurrentHashMap localEntrys = new ConcurrentHashMap<>(); - // key: serviceid + // key: serviceId protected final ConcurrentHashMap remoteEntrys = new ConcurrentHashMap<>(); public void init(AnyValue config) { @@ -75,7 +75,7 @@ public abstract class ClusterAgent { this.protocols = Utility.isEmpty(ps) ? null : ps.split(";"); String ts = config.getValue("ports", ""); - if (ts != null && !ts.isEmpty()) { + if (Utility.isNotEmpty(ts)) { String[] its = ts.split(";"); List list = new ArrayList<>(); for (String str : its) { @@ -152,14 +152,14 @@ public abstract class ClusterAgent { continue; } ClusterEntry htentry = register(ns, protocol, service); - localEntrys.put(htentry.serviceid, htentry); + localEntrys.put(htentry.serviceId, htentry); } // 远程模式加载IP列表, 只支持SNCP协议 if (ns.isSNCP()) { for (Service service : remoteServices) { ClusterEntry entry = new ClusterEntry(ns, protocol, service); updateSncpAddress(entry); - remoteEntrys.put(entry.serviceid, entry); + remoteEntrys.put(entry.serviceId, entry); } } } @@ -248,7 +248,7 @@ public abstract class ClusterAgent { try { Set addrs = ClusterAgent.this.queryAddress(entry).join(); SncpRpcGroups rpcGroups = application.getSncpRpcGroups(); - rpcGroups.putClusterAddress(entry.resourceid, addrs); + rpcGroups.putClusterAddress(entry.resourceId, addrs); } catch (Exception e) { logger.log(Level.SEVERE, entry + " updateSncpAddress error", e); } @@ -368,7 +368,7 @@ public abstract class ClusterAgent { public class ClusterEntry { // serviceName+nodeid为主 服务的单个实例 - public String serviceid; + public String serviceId; // 以协议+Rest资源名为主 服务类名 public String serviceName; @@ -377,9 +377,9 @@ public abstract class ClusterAgent { public final String resourceName; - public final String resourceid; + public final String resourceId; - public String checkid; + public String checkId; public String checkName; @@ -397,14 +397,14 @@ public abstract class ClusterAgent { public boolean canceled; public ClusterEntry(NodeServer ns, String protocol, Service service) { - this.serviceid = generateServiceId(ns, protocol, service); + this.serviceId = generateServiceId(ns, protocol, service); this.serviceName = generateServiceName(ns, protocol, service); - this.checkid = generateCheckId(ns, protocol, service); + this.checkId = generateCheckId(ns, protocol, service); this.checkName = generateCheckName(ns, protocol, service); Class restype = Sncp.getResourceType(service); this.resourceType = restype.getName(); this.resourceName = Sncp.getResourceName(service); - this.resourceid = Sncp.resourceid(resourceName, restype); + this.resourceId = Sncp.resourceid(resourceName, restype); this.protocol = protocol; InetSocketAddress addr = ns.getSocketAddress(); String host = addr.getHostString(); diff --git a/src/main/java/org/redkale/scheduled/spi/CronExpression.java b/src/main/java/org/redkale/scheduled/spi/CronExpression.java index 03bf722d6..529620597 100644 --- a/src/main/java/org/redkale/scheduled/spi/CronExpression.java +++ b/src/main/java/org/redkale/scheduled/spi/CronExpression.java @@ -181,9 +181,9 @@ public class CronExpression { private static final String[] DAYS = new String[] {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; - private final Type type; + private final CronType type; - protected CronField(Type type) { + protected CronField(CronType type) { this.type = type; } @@ -310,7 +310,7 @@ public class CronExpression { @Nullable public abstract > T nextOrSame(T temporal); - protected Type type() { + protected CronType type() { return this.type; } @@ -319,7 +319,7 @@ public class CronExpression { return (T) temporal; } - protected enum Type { + protected enum CronType { NANO(ChronoField.NANO_OF_SECOND, ChronoUnit.SECONDS), SECOND(ChronoField.SECOND_OF_MINUTE, ChronoUnit.MINUTES, ChronoField.NANO_OF_SECOND), MINUTE( @@ -362,7 +362,7 @@ public class CronExpression { private final ChronoField[] lowerOrders; - Type(ChronoField field, ChronoUnit higherOrder, ChronoField... lowerOrders) { + CronType(ChronoField field, ChronoUnit higherOrder, ChronoField... lowerOrders) { this.field = field; this.higherOrder = higherOrder; this.lowerOrders = lowerOrders; @@ -438,13 +438,13 @@ public class CronExpression { // we store at most 60 bits, for seconds and minutes, so a 64-bit long suffices private long bits; - private BitsCronField(Type type) { + private BitsCronField(CronType type) { super(type); } public static BitsCronField zeroNanos() { if (zeroNanos == null) { - BitsCronField field = new BitsCronField(Type.NANO); + BitsCronField field = new BitsCronField(CronType.NANO); field.setBit(0); zeroNanos = field; } @@ -452,27 +452,27 @@ public class CronExpression { } public static BitsCronField parseSeconds(String value) { - return parseField(value, Type.SECOND); + return parseField(value, CronType.SECOND); } public static BitsCronField parseMinutes(String value) { - return BitsCronField.parseField(value, Type.MINUTE); + return BitsCronField.parseField(value, CronType.MINUTE); } public static BitsCronField parseHours(String value) { - return BitsCronField.parseField(value, Type.HOUR); + return BitsCronField.parseField(value, CronType.HOUR); } public static BitsCronField parseDaysOfMonth(String value) { - return parseDate(value, Type.DAY_OF_MONTH); + return parseDate(value, CronType.DAY_OF_MONTH); } public static BitsCronField parseMonth(String value) { - return BitsCronField.parseField(value, Type.MONTH); + return BitsCronField.parseField(value, CronType.MONTH); } public static BitsCronField parseDaysOfWeek(String value) { - BitsCronField result = parseDate(value, Type.DAY_OF_WEEK); + BitsCronField result = parseDate(value, CronType.DAY_OF_WEEK); if (result.getBit(0)) { // cron supports 0 for Sunday; we use 7 like java.time result.setBit(7); @@ -481,14 +481,14 @@ public class CronExpression { return result; } - private static BitsCronField parseDate(String value, BitsCronField.Type type) { + private static BitsCronField parseDate(String value, CronType type) { if (value.equals("?")) { value = "*"; } return BitsCronField.parseField(value, type); } - private static BitsCronField parseField(String value, Type type) { + private static BitsCronField parseField(String value, CronType type) { if (Utility.isBlank(value)) { throw new RedkaleException("Value must not be empty"); } @@ -525,7 +525,7 @@ public class CronExpression { } } - private static ValueRange parseRange(String value, Type type) { + private static ValueRange parseRange(String value, CronType type) { if (value.equals("*")) { return type.range(); } else { @@ -538,7 +538,7 @@ public class CronExpression { int max = Integer.parseInt(value, hyphenPos + 1, value.length(), 10); min = type.checkValidValue(min); max = type.checkValidValue(max); - if (type == Type.DAY_OF_WEEK && min == 7) { + if (type == CronType.DAY_OF_WEEK && min == 7) { // If used as a minimum in a range, Sunday means 0 (not 7) min = 0; } @@ -660,13 +660,13 @@ public class CronExpression { private final String value; - private CompositeCronField(Type type, CronField[] fields, String value) { + private CompositeCronField(CronType type, CronField[] fields, String value) { super(type); this.fields = fields; this.value = value; } - public static CronField compose(CronField[] fields, Type type, String value) { + public static CronField compose(CronField[] fields, CronType type, String value) { if (fields == null || fields.length < 1) { throw new RedkaleException("Fields must not be empty"); }