This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new a9fedd5ecb feat: Support disable Curator EnsembleTracker (#14597)
a9fedd5ecb is described below

commit a9fedd5ecb2c1c3bcdb429f83f3ac00b8d4aea3a
Author: aofall <[email protected]>
AuthorDate: Thu Aug 29 10:39:37 2024 +0800

    feat: Support disable Curator EnsembleTracker (#14597)
    
    * feat: Support disable Curator EnsembleTracker
    
    Support disable Curator EnsembleTracker and compatible with curator4
    
    * Use Throwable instead detail Exception
---
 .../registry/zookeeper/util/CuratorFrameworkUtils.java      | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git 
a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java
 
b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java
index 83b47fc1c1..c373e2983a 100644
--- 
a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java
+++ 
b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java
@@ -24,6 +24,7 @@ import org.apache.dubbo.registry.zookeeper.ZookeeperInstance;
 import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
 import org.apache.dubbo.rpc.model.ScopeModelUtil;
 
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +33,7 @@ import java.util.stream.Collectors;
 import org.apache.curator.RetryPolicy;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
 import org.apache.curator.framework.api.ACLProvider;
 import org.apache.curator.framework.imps.CuratorFrameworkState;
 import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -43,6 +45,7 @@ import org.apache.zookeeper.data.ACL;
 
 import static org.apache.curator.x.discovery.ServiceInstance.builder;
 import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
+import static 
org.apache.dubbo.common.constants.CommonConstants.ZOOKEEPER_ENSEMBLE_TRACKER_KEY;
 import static 
org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.DEFAULT_GROUP;
 import static 
org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BASE_SLEEP_TIME;
 import static 
org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BLOCK_UNTIL_CONNECTED_UNIT;
@@ -72,6 +75,16 @@ public abstract class CuratorFrameworkUtils {
         CuratorFrameworkFactory.Builder builder = 
CuratorFrameworkFactory.builder()
                 .connectString(connectionURL.getBackupAddress())
                 .retryPolicy(buildRetryPolicy(connectionURL));
+        try {
+            // use reflect to check method exist to compatibility with 
curator4, can remove in dubbo3.3 and direct call
+            // the method because 3.3 only supported curator5
+            Class<? extends Builder> builderClass = builder.getClass();
+            Method ignore = builderClass.getMethod("ensembleTracker", 
boolean.class);
+            boolean ensembleTrackerFlag = 
connectionURL.getParameter(ZOOKEEPER_ENSEMBLE_TRACKER_KEY, true);
+            builder.ensembleTracker(ensembleTrackerFlag);
+        } catch (Throwable ignore) {
+        }
+
         String userInformation = connectionURL.getUserInformation();
         if (StringUtils.isNotEmpty(userInformation)) {
             builder = builder.authorization("digest", 
userInformation.getBytes());

Reply via email to