From 62f808cf278e6fc00e6ca740f200cbbfeaf93138 Mon Sep 17 00:00:00 2001 From: mingri31164 <3116430062@qq.com> Date: Tue, 30 Sep 2025 22:48:30 +0800 Subject: [PATCH] The client adds the protocol version --- .../hippo4j/springboot/starter/core/CacheData.java | 6 ++++-- .../springboot/starter/core/ClientWorker.java | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java index 436df96c..b935d843 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/CacheData.java @@ -18,10 +18,10 @@ package cn.hippo4j.springboot.starter.core; import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry; -import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.springboot.starter.wrapper.ManagerListenerWrapper; import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.Md5Util; +import cn.hippo4j.common.toolkit.IncrementalContentUtil; import cn.hippo4j.common.constant.Constants; import lombok.Getter; import lombok.Setter; @@ -58,7 +58,9 @@ public class CacheData { this.tenantId = tenantId; this.itemId = itemId; this.threadPoolId = threadPoolId; - this.content = ContentUtil.getPoolContent(ThreadPoolExecutorRegistry.getHolder(threadPoolId).getParameterInfo()); + this.content = IncrementalContentUtil.getIncrementalContent( + ThreadPoolExecutorRegistry.getHolder(threadPoolId).getParameterInfo(), + IncrementalContentUtil.PROTOCOL_VERSION); this.md5 = getMd5String(content); this.listeners = new CopyOnWriteArrayList<>(); } diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java index 725fa900..d413c4e6 100644 --- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java +++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/core/ClientWorker.java @@ -20,6 +20,7 @@ package cn.hippo4j.springboot.starter.core; import cn.hippo4j.common.executor.ThreadFactoryBuilder; import cn.hippo4j.common.model.Result; import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import cn.hippo4j.common.toolkit.IncrementalContentUtil; import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.GroupKey; import cn.hippo4j.common.toolkit.IdUtil; @@ -69,6 +70,7 @@ public class ClientWorker implements DisposableBean { private final long timeout; private final String identify; private final String version; + private static final int PROTOCOL_VERSION = 2; private final HttpAgent agent; private final ServerHealthCheck serverHealthCheck; @@ -156,7 +158,9 @@ public class ClientWorker implements DisposableBean { try { String content = getServerConfig(namespace, itemId, tpId, defaultTimedOut); CacheData cacheData = cacheMap.get(tpId); - String poolContent = ContentUtil.getPoolContent(JSONUtil.parseObject(content, ThreadPoolParameterInfo.class)); + ThreadPoolParameterInfo poolInfo = JSONUtil.parseObject(content, ThreadPoolParameterInfo.class); + // Use incremental content for protocol version 2+ clients + String poolContent = IncrementalContentUtil.getIncrementalContent(poolInfo, PROTOCOL_VERSION); cacheData.setContent(poolContent); } catch (Exception ignored) { log.error("Failed to get the latest thread pool configuration.", ignored); @@ -197,7 +201,7 @@ public class ClientWorker implements DisposableBean { Map params = new HashMap<>(2); params.put(LISTENING_CONFIGS, probeUpdateString); params.put(WEIGHT_CONFIGS, IdUtil.simpleUUID()); - Map headers = new HashMap<>(2); + Map headers = new HashMap<>(3); headers.put(LONG_PULLING_TIMEOUT, "" + timeout); // Confirm the identity of the client, and can be modified separately when modifying the thread pool configuration. headers.put(LONG_PULLING_CLIENT_IDENTIFICATION, identify); @@ -206,6 +210,8 @@ public class ClientWorker implements DisposableBean { headers.put(LONG_PULLING_TIMEOUT_NO_HANGUP, "true"); } headers.put(CLIENT_VERSION, version); + // Add protocol version header for incremental updates + headers.put("X-Hippo4j-Protocol-Version", String.valueOf(PROTOCOL_VERSION)); try { long readTimeoutMs = timeout + Math.round(timeout >> 1); Result result = agent.httpPostByConfig(LISTENER_PATH, headers, params, readTimeoutMs); @@ -283,7 +289,9 @@ public class ClientWorker implements DisposableBean { try { serverConfig = getServerConfig(namespace, itemId, threadPoolId, defaultTimedOut); ThreadPoolParameterInfo poolInfo = JSONUtil.parseObject(serverConfig, ThreadPoolParameterInfo.class); - cacheData.setContent(ContentUtil.getPoolContent(poolInfo)); + // Use incremental content for protocol version 2+ clients + String content = IncrementalContentUtil.getIncrementalContent(poolInfo, PROTOCOL_VERSION); + cacheData.setContent(content); } catch (Exception ex) { log.error("Cache Data Error. Service Unavailable: {}", ex.getMessage()); }