You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2020/10/23 02:27:25 UTC

[shardingsphere] branch master updated: refactor CuratorZookeeperRepository (#7892)

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

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new c343c62  refactor CuratorZookeeperRepository (#7892)
c343c62 is described below

commit c343c62b4a87ed06c85112ac41518fd12553e5b5
Author: Serendipity <ja...@163.com>
AuthorDate: Fri Oct 23 10:26:59 2020 +0800

    refactor CuratorZookeeperRepository (#7892)
---
 .../zookeeper/CuratorZookeeperRepository.java      | 34 ++++++++++------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/govern [...]
index 5f92ca6..f87ed28 100644
--- a/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java
+++ b/shardingsphere-governance/shardingsphere-governance-repository/shardingsphere-governance-repository-provider/shardingsphere-governance-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/governance/repository/zookeeper/CuratorZookeeperRepository.java
@@ -17,8 +17,17 @@
 
 package org.apache.shardingsphere.governance.repository.zookeeper;
 
-import com.google.common.base.Charsets;
 import com.google.common.base.Strings;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.curator.framework.CuratorFramework;
@@ -42,17 +51,6 @@ import org.apache.zookeeper.KeeperException.OperationTimeoutException;
 import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.data.ACL;
 
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
 /**
  * Governance repository of ZooKeeper.
  */
@@ -90,7 +88,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
             builder.connectionTimeoutMs(operationTimeoutMilliseconds);
         }
         if (!Strings.isNullOrEmpty(digest)) {
-            builder.authorization(ZookeeperPropertyKey.DIGEST.getKey(), digest.getBytes(Charsets.UTF_8))
+            builder.authorization(ZookeeperPropertyKey.DIGEST.getKey(), digest.getBytes(StandardCharsets.UTF_8))
                 .aclProvider(new ACLProvider() {
                     
                     @Override
@@ -129,7 +127,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
         }
         Optional<ChildData> resultInCache = cache.get(key);
         if (resultInCache.isPresent()) {
-            return null == resultInCache.get().getData() ? null : new String(resultInCache.get().getData(), Charsets.UTF_8);
+            return null == resultInCache.get().getData() ? null : new String(resultInCache.get().getData(), StandardCharsets.UTF_8);
         }
         return getDirectly(key);
     }
@@ -156,7 +154,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
     public void persist(final String key, final String value) {
         try {
             if (!isExisted(key)) {
-                client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(key, value.getBytes(Charsets.UTF_8));
+                client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(key, value.getBytes(StandardCharsets.UTF_8));
             } else {
                 update(key, value);
             }
@@ -180,7 +178,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
     
     private String getDirectly(final String key) {
         try {
-            return new String(client.getData().forPath(key), Charsets.UTF_8);
+            return new String(client.getData().forPath(key), StandardCharsets.UTF_8);
             // CHECKSTYLE:OFF
         } catch (final Exception ex) {
             // CHECKSTYLE:ON
@@ -206,7 +204,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
             if (isExisted(key)) {
                 client.delete().deletingChildrenIfNeeded().forPath(key);
             }
-            client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(Charsets.UTF_8));
+            client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(StandardCharsets.UTF_8));
             // CHECKSTYLE:OFF
         } catch (final Exception ex) {
             // CHECKSTYLE:ON
@@ -239,7 +237,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
             byte[] eventDataByte = CuratorCacheListener.Type.NODE_DELETED == type ? oldData.getData() : data.getData();
             DataChangedEvent.ChangedType changedType = getChangedType(type);
             if (ChangedType.IGNORED != changedType) {
-                listener.onChange(new DataChangedEvent(eventPath, null == eventDataByte ? null : new String(eventDataByte, Charsets.UTF_8), changedType));
+                listener.onChange(new DataChangedEvent(eventPath, null == eventDataByte ? null : new String(eventDataByte, StandardCharsets.UTF_8), changedType));
             }
         });
     }