You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/06/17 10:45:16 UTC
[incubator-shenyu] branch master updated: [ISSUE #3556] downgrade curator version to 4.3.0 to compatible with some plugin like sofa (#3569)
This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 8c7c796c0 [ISSUE #3556] downgrade curator version to 4.3.0 to compatible with some plugin like sofa (#3569)
8c7c796c0 is described below
commit 8c7c796c06cddbdaf73f95d0ec98626ba4431a3f
Author: Han Gao <dh...@hotmail.com>
AuthorDate: Fri Jun 17 18:45:10 2022 +0800
[ISSUE #3556] downgrade curator version to 4.3.0 to compatible with some plugin like sofa (#3569)
* downgrade curator to 4.3.0 for all shenyu modules
* udpate for LICENSE files
---
pom.xml | 9 +---
.../listener/zookeeper/HttpServiceDiscovery.java | 12 ++---
shenyu-bootstrap/pom.xml | 20 -------
.../src/main/release-docs/LICENSE | 10 ++--
.../src/main/release-docs/LICENSE | 10 ++--
.../shenyu-examples-sofa-service/pom.xml | 32 ++++++------
.../client/server/zookeeper/ZookeeperClient.java | 38 ++++++++------
.../ZookeeperClientServerRegisterRepository.java | 61 +++++++++++++++++-----
.../server/zookeeper/ZookeeperClientTest.java | 20 +++----
.../shenyu-register-client-zookeeper/pom.xml | 3 +-
.../register/client/zookeeper/ZookeeperClient.java | 38 ++++++++------
.../client/zookeeper/ZookeeperClientTest.java | 6 +--
.../instance/zookeeper/ZookeeperClient.java | 38 ++++++++------
.../instance/zookeeper/ZookeeperClientTest.java | 6 +--
.../shenyu-sync-data-zookeeper/pom.xml | 19 -------
15 files changed, 165 insertions(+), 157 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3050873f2..180e7d8a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,9 +107,9 @@
<tars.version>1.7.2</tars.version>
<skipTests>false</skipTests>
<undertow.version>2.2.2.Final</undertow.version>
- <curator.version>5.2.1</curator.version>
+ <curator.version>4.3.0</curator.version>
<wiremock.version>2.18.0</wiremock.version>
- <zookeeper.version>3.6.3</zookeeper.version>
+ <zookeeper.version>3.5.7</zookeeper.version>
<zkclient.version>0.10</zkclient.version>
<shiro.version>1.8.0</shiro.version>
<jwt.version>3.12.0</jwt.version>
@@ -432,11 +432,6 @@
<artifactId>curator-recipes</artifactId>
<version>${curator.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-x-async</artifactId>
- <version>${curator.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/zookeeper/HttpServiceDiscovery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/zookeeper/HttpServiceDiscovery.java
index 12ffbd214..22fe8942e 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/zookeeper/HttpServiceDiscovery.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/listener/zookeeper/HttpServiceDiscovery.java
@@ -19,8 +19,9 @@ package org.apache.shenyu.admin.listener.zookeeper;
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.StringUtils;
-import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.shenyu.admin.listener.DataChangedEvent;
import org.apache.shenyu.admin.mapper.SelectorMapper;
import org.apache.shenyu.admin.model.entity.SelectorDO;
@@ -162,11 +163,10 @@ public class HttpServiceDiscovery implements InitializingBean {
}).collect(Collectors.toList());
}
- class HttpServiceListener implements CuratorCacheListener {
+ class HttpServiceListener implements TreeCacheListener {
@Override
- public void event(final Type type, final ChildData oldData, final ChildData data) {
- String path = Objects.isNull(data) ? oldData.getPath() : data.getPath();
-
+ public void childEvent(final CuratorFramework client, final TreeCacheEvent event) throws Exception {
+ String path = event.getData().getPath();
// if not uri register path, return.
if (!PathMatchUtils.match(URI_PATH, path)) {
return;
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index b1944147c..6ef4ddd26 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -28,7 +28,6 @@
<properties>
<nacos-discovery.version>2021.0.1.0</nacos-discovery.version>
<eureka-client.version>3.1.2</eureka-client.version>
- <curator.version>4.0.1</curator.version>
</properties>
<dependencies>
@@ -461,25 +460,6 @@
<version>${project.version}</version>
</dependency>
<!--shenyu logging-rocketmq plugin end-->
-
- <!-- curator start -->
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-client</artifactId>
- <version>${curator.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>${curator.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- <version>${curator.version}</version>
- </dependency>
- <!-- curator end -->
-
</dependencies>
<profiles>
<profile>
diff --git a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
index 866d96319..740f84631 100644
--- a/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
+++ b/shenyu-dist/shenyu-admin-dist/src/main/release-docs/LICENSE
@@ -318,11 +318,11 @@ The text of each license is the standard Apache 2.0 license.
tomcat-embed-el 9.0.29: https://tomcat.apache.org, Apache 2.0
tomcat-embed-websocket 9.0.29: https://tomcat.apache.org, Apache 2.0
unbescape 1.1.6.RELEASE: http://www.unbescape.org, Apache 2.0
- zookeeper 3.6.3: https://github.com/apache/zookeeper, Apache 2.0
- zookeeper-jute 3.6.3: https://github.com/apache/zookeeper, Apache 2.0
- curator-client 5.2.1: https://github.com/apache/curator, Apache 2.0
- curator-framework 5.2.1: https://github.com/apache/curator, Apache 2.0
- curator-recipes 5.2.1: https://github.com/apache/curator, Apache 2.0
+ zookeeper 3.5.7: https://github.com/apache/zookeeper, Apache 2.0
+ zookeeper-jute 3.5.7: https://github.com/apache/zookeeper, Apache 2.0
+ curator-client 4.3.0: https://github.com/apache/curator, Apache 2.0
+ curator-framework 4.3.0: https://github.com/apache/curator, Apache 2.0
+ curator-recipes 4.3.0: https://github.com/apache/curator, Apache 2.0
========================================================================
BSD licenses
diff --git a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
index 1b708c3c0..e6cdc10bb 100644
--- a/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
+++ b/shenyu-dist/shenyu-bootstrap-dist/src/main/release-docs/LICENSE
@@ -236,9 +236,9 @@ The text of each license is the standard Apache 2.0 license.
commons-jxpath 1.3: http://commons.apache.org/jxpath/, Apache 2.0
commons-math 2.2: https://github.com/apache/commons-math, Apache 2.0
conscrypt-openjdk-uber 2.5.1: https://conscrypt.org, Apache 2.0
- curator-client 4.0.1: https://github.com/apache/curator, Apache 2.0
- curator-framework 4.0.1: https://github.com/apache/curator, Apache 2.0
- curator-recipes 4.0.1: https://github.com/apache/curator, Apache 2.0
+ curator-client 4.3.0: https://github.com/apache/curator, Apache 2.0
+ curator-framework 4.3.0: https://github.com/apache/curator, Apache 2.0
+ curator-recipes 4.3.0: https://github.com/apache/curator, Apache 2.0
dubbo 2.6.5: https://github.com/apache/dubbo, Apache 2.0
error_prone_annotations 2.5.1: https://github.com/google/error-prone, Apache 2.0
failsafe 2.3.3: https://github.com/jhalterman/failsafe, Apache 2.0
@@ -353,8 +353,8 @@ The text of each license is the standard Apache 2.0 license.
vavr 0.10.2: http://vavr.io, Apache 2.0
vavr-match 0.10.2: http://vavr.io, Apache 2.0
zkclient 0.10: https://github.com/sgroschupf/zkclient, Apache 2.0
- zookeeper 3.6.3: https://github.com/apache/zookeeper, Apache 2.0
- zookeeper-jute 3.6.3: https://github.com/apache/zookeeper, Apache 2.0
+ zookeeper 3.5.7: https://github.com/apache/zookeeper, Apache 2.0
+ zookeeper-jute 3.5.7: https://github.com/apache/zookeeper, Apache 2.0
byte-buddy 1.12.6: https://github.com/raphw/byte-buddy, Apache 2.0
byte-buddy-agent 1.12.6: https://github.com/raphw/byte-buddy, Apache 2.0
disruptor 3.4.0 https://github.com/LMAX-Exchange/disruptor, Apache 2.0
diff --git a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
index d6f37201a..8499d1d2f 100644
--- a/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
+++ b/shenyu-examples/shenyu-examples-sofa/shenyu-examples-sofa-service/pom.xml
@@ -29,7 +29,7 @@
<properties>
<rpc-sofa-boot-starter.version>3.12.1</rpc-sofa-boot-starter.version>
- <curator.version>4.0.1</curator.version>
+<!-- <curator.version>4.3.0</curator.version>-->
<micrometer.version>1.8.6</micrometer.version>
</properties>
@@ -52,21 +52,21 @@
<version>${rpc-sofa-boot-starter.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-client</artifactId>
- <version>${curator.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>${curator.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- <version>${curator.version}</version>
- </dependency>
+<!-- <dependency>-->
+<!-- <groupId>org.apache.curator</groupId>-->
+<!-- <artifactId>curator-client</artifactId>-->
+<!-- <version>${curator.version}</version>-->
+<!-- </dependency>-->
+<!-- <dependency>-->
+<!-- <groupId>org.apache.curator</groupId>-->
+<!-- <artifactId>curator-framework</artifactId>-->
+<!-- <version>${curator.version}</version>-->
+<!-- </dependency>-->
+<!-- <dependency>-->
+<!-- <groupId>org.apache.curator</groupId>-->
+<!-- <artifactId>curator-recipes</artifactId>-->
+<!-- <version>${curator.version}</version>-->
+<!-- </dependency>-->
<!--shenyu consul register center -->
<!--<dependency>
diff --git a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClient.java b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClient.java
index f3015930f..446814b49 100644
--- a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClient.java
+++ b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClient.java
@@ -21,8 +21,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.apache.shenyu.common.exception.ShenyuException;
@@ -35,7 +35,6 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class ZookeeperClient {
@@ -46,7 +45,7 @@ public class ZookeeperClient {
private final CuratorFramework client;
- private final Map<String, CuratorCache> caches = new ConcurrentHashMap<>();
+ private final Map<String, TreeCache> caches = new ConcurrentHashMap<>();
public ZookeeperClient(final ZookeeperConfig zookeeperConfig) {
this.config = zookeeperConfig;
@@ -84,7 +83,7 @@ public class ZookeeperClient {
*/
public void close() {
// close all caches
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
CloseableUtils.closeQuietly(cache.getValue());
}
// close client
@@ -136,12 +135,15 @@ public class ZookeeperClient {
* @return value.
*/
public String get(final String key) {
- CuratorCache cache = findFromcache(key);
+ TreeCache cache = findFromcache(key);
if (Objects.isNull(cache)) {
return getDirectly(key);
}
- Optional<ChildData> data = cache.get(key);
- return data.map(childData -> new String(childData.getData(), StandardCharsets.UTF_8)).orElseGet(() -> getDirectly(key));
+ ChildData data = cache.getCurrentData(key);
+ if (Objects.isNull(data)) {
+ return getDirectly(key);
+ }
+ return Objects.isNull(data.getData()) ? null : new String(data.getData(), StandardCharsets.UTF_8);
}
/**
@@ -208,7 +210,7 @@ public class ZookeeperClient {
* @param path path.
* @return cache.
*/
- public CuratorCache getCache(final String path) {
+ public TreeCache getCache(final String path) {
return caches.get(path);
}
@@ -218,15 +220,19 @@ public class ZookeeperClient {
* @param listeners listeners.
* @return cache.
*/
- public CuratorCache addCache(final String path, final CuratorCacheListener... listeners) {
- CuratorCache cache = CuratorCache.build(client, path);
+ public TreeCache addCache(final String path, final TreeCacheListener... listeners) {
+ TreeCache cache = TreeCache.newBuilder(client, path).build();
caches.put(path, cache);
if (listeners != null && listeners.length > 0) {
- for (CuratorCacheListener listener : listeners) {
- cache.listenable().addListener(listener);
+ for (TreeCacheListener listener : listeners) {
+ cache.getListenable().addListener(listener);
}
}
- cache.start();
+ try {
+ cache.start();
+ } catch (Exception e) {
+ throw new ShenyuException("failed to add curator cache.", e);
+ }
return cache;
}
@@ -235,8 +241,8 @@ public class ZookeeperClient {
* @param key key.
* @return cache.
*/
- private CuratorCache findFromcache(final String key) {
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ private TreeCache findFromcache(final String key) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
if (key.startsWith(cache.getKey())) {
return cache.getValue();
}
diff --git a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientServerRegisterRepository.java b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientServerRegisterRepository.java
index feb8c4e4f..f5a73956d 100644
--- a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientServerRegisterRepository.java
+++ b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/main/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientServerRegisterRepository.java
@@ -17,11 +17,14 @@
package org.apache.shenyu.register.client.server.zookeeper;
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.apache.shenyu.common.utils.GsonUtils;
@@ -39,7 +42,7 @@ import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
-import java.util.Objects;
+import java.util.Optional;
import java.util.Properties;
/**
@@ -103,15 +106,7 @@ public class ZookeeperClientServerRegisterRepository implements ShenyuClientServ
private void subscribeMetaData(final String rpcType) {
String contextPathParent = RegisterPathConstants.buildMetaDataContextPathParent(rpcType);
- CuratorCacheListener listener = CuratorCacheListener.builder()
- .forCreatesAndChanges((oldNode, node) -> {
- if (PathMatchUtils.match(RegisterPathConstants.REGISTER_METADATA_INSTANCE_PATH, node.getPath())) {
- String data = new String(node.getData(), StandardCharsets.UTF_8);
- publishMetadata(data);
- LOGGER.info("zookeeper register metadata success: {}", data);
- }
- }).build();
- client.addCache(contextPathParent, listener);
+ client.addCache(contextPathParent, new MetadataCacheListener());
}
private void publishMetadata(final String data) {
@@ -122,11 +117,49 @@ public class ZookeeperClientServerRegisterRepository implements ShenyuClientServ
publisher.publish(registerDTOList);
}
- class URICacheListener implements CuratorCacheListener {
+ abstract class AbstractRegisterListener implements TreeCacheListener {
@Override
- public void event(final Type type, final ChildData oldData, final ChildData data) {
- String path = Objects.isNull(data) ? oldData.getPath() : data.getPath();
+ public final void childEvent(final CuratorFramework client, final TreeCacheEvent event) {
+ ChildData childData = event.getData();
+ if (null == childData) {
+ return;
+ }
+ String path = childData.getPath();
+ if (Strings.isNullOrEmpty(path)) {
+ return;
+ }
+ event(event.getType(), path, childData);
+ }
+
+ /**
+ * data sync event.
+ *
+ * @param type tree cache event type.
+ * @param path tree cache event path.
+ * @param data tree cache event data.
+ */
+ protected abstract void event(TreeCacheEvent.Type type, String path, ChildData data);
+ }
+ class MetadataCacheListener extends AbstractRegisterListener {
+ @Override
+ public void event(final TreeCacheEvent.Type type, final String path, final ChildData data) {
+ // if not uri register path, return.
+ if (!PathMatchUtils.match(RegisterPathConstants.REGISTER_METADATA_INSTANCE_PATH, path)) {
+ return;
+ }
+ Optional.ofNullable(data)
+ .ifPresent(e -> {
+ String str = new String(data.getData(), StandardCharsets.UTF_8);
+ publishMetadata(str);
+ LOGGER.info("zookeeper register metadata success: {}", str);
+ });
+ }
+ }
+
+ class URICacheListener extends AbstractRegisterListener {
+ @Override
+ public void event(final TreeCacheEvent.Type type, final String path, final ChildData data) {
// if not uri register path, return.
if (!PathMatchUtils.match(RegisterPathConstants.REGISTER_URI_INSTANCE_PATH, path)) {
return;
diff --git a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/test/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientTest.java b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/test/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientTest.java
index 3f96cb3b1..e9bebf638 100644
--- a/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/test/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientTest.java
+++ b/shenyu-register-center/shenyu-register-client-server/shenyu-register-client-server-zookeeper/src/test/java/org/apache/shenyu/register/client/server/zookeeper/ZookeeperClientTest.java
@@ -18,8 +18,9 @@
package org.apache.shenyu.register.client.server.zookeeper;
import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.test.TestingServer;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.utils.GsonUtils;
@@ -31,7 +32,6 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -129,7 +129,7 @@ class ZookeeperClientTest {
@Test
void getCache() {
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
assertNull(cache);
client.addCache("/test");
@@ -140,14 +140,14 @@ class ZookeeperClientTest {
@Test
void addCache() throws InterruptedException {
List<String> paths = new ArrayList<>();
- CuratorCacheListener listener = CuratorCacheListener.builder()
- .forCreatesAndChanges((oldNode, node) -> {
- String path = Objects.isNull(oldNode) ? node.getPath() : oldNode.getPath();
- paths.add(path);
- }).build();
+ TreeCacheListener listener = (client, event) -> {
+ if (event.getType() == TreeCacheEvent.Type.NODE_ADDED || event.getType() == TreeCacheEvent.Type.NODE_UPDATED) {
+ paths.add(event.getData().getPath());
+ }
+ };
client.createOrUpdate("/test", "", CreateMode.PERSISTENT);
client.addCache("/test", listener);
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
Thread.sleep(500);
assertNotNull(cache);
diff --git a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/pom.xml b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/pom.xml
index c86022540..ee1fd88f9 100644
--- a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/pom.xml
+++ b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/pom.xml
@@ -16,7 +16,8 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-register-client</artifactId>
diff --git a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/main/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClient.java b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/main/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClient.java
index 4a9c874bc..1a5ca3048 100644
--- a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/main/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClient.java
+++ b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/main/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClient.java
@@ -21,8 +21,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.apache.shenyu.common.exception.ShenyuException;
@@ -35,7 +35,6 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class ZookeeperClient {
@@ -46,7 +45,7 @@ public class ZookeeperClient {
private final CuratorFramework client;
- private final Map<String, CuratorCache> caches = new ConcurrentHashMap<>();
+ private final Map<String, TreeCache> caches = new ConcurrentHashMap<>();
public ZookeeperClient(final ZookeeperConfig zookeeperConfig) {
this.config = zookeeperConfig;
@@ -84,7 +83,7 @@ public class ZookeeperClient {
*/
public void close() {
// close all caches
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
CloseableUtils.closeQuietly(cache.getValue());
}
// close client
@@ -136,12 +135,15 @@ public class ZookeeperClient {
* @return value.
*/
public String get(final String key) {
- CuratorCache cache = findFromcache(key);
+ TreeCache cache = findFromcache(key);
if (Objects.isNull(cache)) {
return getDirectly(key);
}
- Optional<ChildData> data = cache.get(key);
- return data.map(childData -> new String(childData.getData(), StandardCharsets.UTF_8)).orElseGet(() -> getDirectly(key));
+ ChildData data = cache.getCurrentData(key);
+ if (Objects.isNull(data)) {
+ return getDirectly(key);
+ }
+ return Objects.isNull(data.getData()) ? null : new String(data.getData(), StandardCharsets.UTF_8);
}
/**
@@ -208,7 +210,7 @@ public class ZookeeperClient {
* @param path path.
* @return cache.
*/
- public CuratorCache getCache(final String path) {
+ public TreeCache getCache(final String path) {
return caches.get(path);
}
@@ -218,15 +220,19 @@ public class ZookeeperClient {
* @param listeners listeners.
* @return cache.
*/
- public CuratorCache addCache(final String path, final CuratorCacheListener... listeners) {
- CuratorCache cache = CuratorCache.build(client, path);
+ public TreeCache addCache(final String path, final TreeCacheListener... listeners) {
+ TreeCache cache = TreeCache.newBuilder(client, path).build();
caches.put(path, cache);
if (listeners != null && listeners.length > 0) {
- for (CuratorCacheListener listener : listeners) {
- cache.listenable().addListener(listener);
+ for (TreeCacheListener listener : listeners) {
+ cache.getListenable().addListener(listener);
}
}
- cache.start();
+ try {
+ cache.start();
+ } catch (Exception e) {
+ throw new ShenyuException("failed to add curator cache.", e);
+ }
return cache;
}
@@ -235,8 +241,8 @@ public class ZookeeperClient {
* @param key key.
* @return cache.
*/
- private CuratorCache findFromcache(final String key) {
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ private TreeCache findFromcache(final String key) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
if (key.startsWith(cache.getKey())) {
return cache.getValue();
}
diff --git a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/test/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClientTest.java b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/test/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClientTest.java
index d72d82723..02c2c4287 100644
--- a/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/test/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClientTest.java
+++ b/shenyu-register-center/shenyu-register-client/shenyu-register-client-zookeeper/src/test/java/org/apache/shenyu/register/client/zookeeper/ZookeeperClientTest.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.register.client.zookeeper;
import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
+import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.test.TestingServer;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.utils.GsonUtils;
@@ -126,7 +126,7 @@ class ZookeeperClientTest {
@Test
void getCache() {
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
assertNull(cache);
client.addCache("/test");
@@ -137,7 +137,7 @@ class ZookeeperClientTest {
@Test
void addCache() {
client.addCache("/test");
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
assertNotNull(cache);
}
}
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClient.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClient.java
index fbc20d729..15ce67e88 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClient.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/main/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClient.java
@@ -21,8 +21,8 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.ChildData;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
-import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
+import org.apache.curator.framework.recipes.cache.TreeCache;
+import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.apache.shenyu.common.exception.ShenyuException;
@@ -35,7 +35,6 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class ZookeeperClient {
@@ -46,7 +45,7 @@ public class ZookeeperClient {
private final CuratorFramework client;
- private final Map<String, CuratorCache> caches = new ConcurrentHashMap<>();
+ private final Map<String, TreeCache> caches = new ConcurrentHashMap<>();
public ZookeeperClient(final ZookeeperConfig zookeeperConfig) {
this.config = zookeeperConfig;
@@ -84,7 +83,7 @@ public class ZookeeperClient {
*/
public void close() {
// close all caches
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
CloseableUtils.closeQuietly(cache.getValue());
}
// close client
@@ -136,12 +135,15 @@ public class ZookeeperClient {
* @return value.
*/
public String get(final String key) {
- CuratorCache cache = findFromcache(key);
+ TreeCache cache = findFromcache(key);
if (Objects.isNull(cache)) {
return getDirectly(key);
}
- Optional<ChildData> data = cache.get(key);
- return data.map(childData -> new String(childData.getData(), StandardCharsets.UTF_8)).orElseGet(() -> getDirectly(key));
+ ChildData data = cache.getCurrentData(key);
+ if (Objects.isNull(data)) {
+ return getDirectly(key);
+ }
+ return Objects.isNull(data.getData()) ? null : new String(data.getData(), StandardCharsets.UTF_8);
}
/**
@@ -208,7 +210,7 @@ public class ZookeeperClient {
* @param path path.
* @return cache.
*/
- public CuratorCache getCache(final String path) {
+ public TreeCache getCache(final String path) {
return caches.get(path);
}
@@ -218,15 +220,19 @@ public class ZookeeperClient {
* @param listeners listeners.
* @return cache.
*/
- public CuratorCache addCache(final String path, final CuratorCacheListener... listeners) {
- CuratorCache cache = CuratorCache.build(client, path);
+ public TreeCache addCache(final String path, final TreeCacheListener... listeners) {
+ TreeCache cache = TreeCache.newBuilder(client, path).build();
caches.put(path, cache);
if (listeners != null && listeners.length > 0) {
- for (CuratorCacheListener listener : listeners) {
- cache.listenable().addListener(listener);
+ for (TreeCacheListener listener : listeners) {
+ cache.getListenable().addListener(listener);
}
}
- cache.start();
+ try {
+ cache.start();
+ } catch (Exception e) {
+ throw new ShenyuException("failed to add curator cache.", e);
+ }
return cache;
}
@@ -235,8 +241,8 @@ public class ZookeeperClient {
* @param key key.
* @return cache.
*/
- private CuratorCache findFromcache(final String key) {
- for (Map.Entry<String, CuratorCache> cache : caches.entrySet()) {
+ private TreeCache findFromcache(final String key) {
+ for (Map.Entry<String, TreeCache> cache : caches.entrySet()) {
if (key.startsWith(cache.getKey())) {
return cache.getValue();
}
diff --git a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClientTest.java b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClientTest.java
index 45ae19f1c..225cb56b3 100644
--- a/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClientTest.java
+++ b/shenyu-register-center/shenyu-register-instance/shenyu-register-instance-zookeeper/src/test/java/org/apache/shenyu/register/instance/zookeeper/ZookeeperClientTest.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.register.instance.zookeeper;
import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.recipes.cache.CuratorCache;
+import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.test.TestingServer;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.utils.GsonUtils;
@@ -126,7 +126,7 @@ class ZookeeperClientTest {
@Test
void getCache() {
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
assertNull(cache);
client.addCache("/test");
@@ -137,7 +137,7 @@ class ZookeeperClientTest {
@Test
void addCache() {
client.addCache("/test");
- CuratorCache cache = client.getCache("/test");
+ TreeCache cache = client.getCache("/test");
assertNotNull(cache);
}
}
diff --git a/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml b/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
index 7cdc97b6b..b375c2162 100644
--- a/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
+++ b/shenyu-sync-data-center/shenyu-sync-data-zookeeper/pom.xml
@@ -25,11 +25,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>shenyu-sync-data-zookeeper</artifactId>
- <properties>
- <curator.version>4.0.1</curator.version>
- <zookeeper.version>3.5.5</zookeeper.version>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.shenyu</groupId>
@@ -40,29 +35,15 @@
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
- <version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
- <version>${curator.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
- <version>${curator.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- <version>${zookeeper.version}</version>
- <exclusions>
- <exclusion>
- <artifactId>log4j</artifactId>
- <groupId>log4j</groupId>
- </exclusion>
- </exclusions>
- </dependency>
</dependencies>
</project>