提交 985c23d2 编写于 作者: K kimmking

minor refactoring for repository

上级 c203065a
......@@ -28,6 +28,16 @@ import java.util.List;
*/
public interface GovernanceRepository extends TypedSPI {
/**
* Path separator.
*/
String PATH_SEPARATOR = "/";
/**
* Dot separator.
*/
String DOT_SEPARATOR = ".";
/**
* Initialize governance center.
*
......
......@@ -44,10 +44,6 @@ import java.util.Properties;
@Slf4j
public final class ApolloRepository implements ConfigurationRepository {
private static final String DOT_SEPARATOR = ".";
private static final String PATH_SEPARATOR = "/";
private final Map<String, DataChangedEventListener> caches = new HashMap<>();
private ApolloConfigWrapper configWrapper;
......
......@@ -32,6 +32,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.shardingsphere.governance.repository.api.ConfigurationRepository;
import org.apache.shardingsphere.governance.repository.api.GovernanceRepository;
import org.apache.shardingsphere.governance.repository.api.RegistryRepository;
import org.apache.shardingsphere.governance.repository.api.config.GovernanceCenterConfiguration;
import org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
......@@ -72,7 +73,7 @@ public final class EtcdRepository implements ConfigurationRepository, RegistryRe
@SneakyThrows({InterruptedException.class, ExecutionException.class})
@Override
public List<String> getChildrenKeys(final String key) {
String prefix = key + "/";
String prefix = key + PATH_SEPARATOR;
ByteSequence prefixByteSequence = ByteSequence.from(prefix, Charsets.UTF_8);
GetOption getOption = GetOption.newBuilder().withPrefix(prefixByteSequence).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build();
List<KeyValue> keyValues = client.getKVClient().get(prefixByteSequence, getOption).get().getKvs();
......@@ -81,7 +82,7 @@ public final class EtcdRepository implements ConfigurationRepository, RegistryRe
private String getSubNodeKeyName(final String prefix, final String fullPath) {
String pathWithoutPrefix = fullPath.substring(prefix.length());
return pathWithoutPrefix.contains("/") ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf('/')) : pathWithoutPrefix;
return pathWithoutPrefix.contains(PATH_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(PATH_SEPARATOR)) : pathWithoutPrefix;
}
@SneakyThrows({InterruptedException.class, ExecutionException.class})
......
......@@ -41,10 +41,6 @@ import java.util.concurrent.Executor;
@Slf4j
public final class NacosRepository implements ConfigurationRepository {
private static final String DOT_SEPARATOR = ".";
private static final String PATH_SEPARATOR = "/";
private ConfigService configService;
private NacosProperties nacosProperties;
......
......@@ -90,7 +90,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
builder.connectionTimeoutMs(operationTimeoutMilliseconds);
}
if (!Strings.isNullOrEmpty(digest)) {
builder.authorization("digest", digest.getBytes(Charsets.UTF_8))
builder.authorization(ZookeeperPropertyKey.DIGEST.getKey(), digest.getBytes(Charsets.UTF_8))
.aclProvider(new ACLProvider() {
@Override
......@@ -229,7 +229,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
@Override
public void watch(final String key, final DataChangedEventListener listener) {
String path = key + "/";
String path = key + PATH_SEPARATOR;
if (!caches.containsKey(path)) {
addCacheData(key);
}
......@@ -253,7 +253,7 @@ public final class CuratorZookeeperRepository implements ConfigurationRepository
// CHECKSTYLE:ON
CuratorZookeeperExceptionHandler.handleException(ex);
}
caches.put(cachePath + "/", cache);
caches.put(cachePath + PATH_SEPARATOR, cache);
}
private ChangedType getChangedType(final CuratorCacheListener.Type type) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册