Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Polish #6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection * Polish #6296 : Adding the new methods into MetadataReport to manipulate the exported URLs for service introspection * Polish #6171 : [Feature] Introducing the composite implementation of MetadataService * Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)" This reverts commit 91989ca. * Revert "fix wrong check of InvokerListener when export a service (fix issue_6269) (#6271)" This reverts commit 91989ca. * Revert the MetadataReport * Polish #6305 : [Refactor] ServiceConfig and ReferenceConfig publish the ServiceDefinition based on the Dubbo Event * Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish #6310 : Refactoring MetadataReport's methods * Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish #6198 : [Issue] Fixing NacosDynamicConfiguration#publishConfig bug * Polish #6315 : [Refactor] Refactoring the implementation of MetadataReport based on The Config-Center infrastructure Deprecated List : - NacosMetadataReport - ZookeeperMetadataReport * Polish #6315 : Refactoring by TreePathDynamicConfiguration * Polish #6315 : Refactoring ConsulDynamicConfiguration by TreePathDynamicConfiguration * Polish #6315 : Reset the config base path to be "metadata" for ConfigCenterBasedMetadataReportFactory * Polish #6315 : Bugfix * Polish #6315 : Bugfix
- Loading branch information
1 parent
2a0d015
commit dd7b880
Showing
36 changed files
with
1,432 additions
and
755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
...c/main/java/org/apache/dubbo/common/config/configcenter/TreePathDynamicConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.common.config.configcenter; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.config.configcenter.file.FileSystemDynamicConfiguration; | ||
import org.apache.dubbo.common.utils.PathUtils; | ||
import org.apache.dubbo.common.utils.StringUtils; | ||
|
||
import java.util.Collection; | ||
import java.util.SortedSet; | ||
import java.util.TreeSet; | ||
|
||
import static java.util.Collections.emptySortedSet; | ||
import static java.util.Collections.unmodifiableSortedSet; | ||
import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY; | ||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; | ||
import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty; | ||
import static org.apache.dubbo.common.utils.PathUtils.buildPath; | ||
|
||
/** | ||
* An abstract implementation of {@link DynamicConfiguration} is like "tree-structure" path : | ||
* <ul> | ||
* <li>{@link FileSystemDynamicConfiguration "file"}</li> | ||
* <li>{@link org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration "zookeeper"}</li> | ||
* <li>{@link org.apache.dubbo.configcenter.consul.ConsulDynamicConfiguration "consul"}</li> | ||
* </ul> | ||
* | ||
* @see DynamicConfiguration | ||
* @see AbstractDynamicConfiguration | ||
* @since 2.7.8 | ||
*/ | ||
public abstract class TreePathDynamicConfiguration extends AbstractDynamicConfiguration { | ||
|
||
/** | ||
* The parameter name of URL for the config base path | ||
*/ | ||
public static final String CONFIG_BASE_PATH_PARAM_NAME = PARAM_NAME_PREFIX + "base-path"; | ||
|
||
/** | ||
* The default value of parameter of URL for the config base path | ||
*/ | ||
public static final String DEFAULT_CONFIG_BASE_PATH = "/config"; | ||
|
||
private final String rootPath; | ||
|
||
public TreePathDynamicConfiguration(URL url) { | ||
super(url); | ||
this.rootPath = getRootPath(url); | ||
} | ||
|
||
public TreePathDynamicConfiguration(String rootPath, | ||
String threadPoolPrefixName, | ||
int threadPoolSize, | ||
long keepAliveTime, | ||
String group, | ||
long timeout) { | ||
super(threadPoolPrefixName, threadPoolSize, keepAliveTime, group, timeout); | ||
this.rootPath = rootPath; | ||
} | ||
|
||
@Override | ||
protected final String doGetConfig(String key, String group) throws Exception { | ||
String pathKey = buildPathKey(group, key); | ||
return doGetConfig(pathKey); | ||
} | ||
|
||
@Override | ||
public final boolean publishConfig(String key, String group, String content) { | ||
String pathKey = buildPathKey(group, key); | ||
return execute(() -> doPublishConfig(pathKey, content), getDefaultTimeout()); | ||
} | ||
|
||
@Override | ||
protected final boolean doRemoveConfig(String key, String group) throws Exception { | ||
String pathKey = buildPathKey(group, key); | ||
return doRemoveConfig(pathKey); | ||
} | ||
|
||
@Override | ||
public final void addListener(String key, String group, ConfigurationListener listener) { | ||
String pathKey = buildPathKey(group, key); | ||
doAddListener(pathKey, listener); | ||
} | ||
|
||
@Override | ||
public final void removeListener(String key, String group, ConfigurationListener listener) { | ||
String pathKey = buildPathKey(group, key); | ||
doRemoveListener(pathKey, listener); | ||
} | ||
|
||
@Override | ||
public final SortedSet<String> getConfigKeys(String group) throws UnsupportedOperationException { | ||
String groupPath = buildGroupPath(group); | ||
Collection<String> configKeys = doGetConfigKeys(groupPath); | ||
return isEmpty(configKeys) ? emptySortedSet() : unmodifiableSortedSet(new TreeSet<>(configKeys)); | ||
} | ||
|
||
protected abstract boolean doPublishConfig(String pathKey, String content) throws Exception; | ||
|
||
protected abstract String doGetConfig(String pathKey) throws Exception; | ||
|
||
protected abstract boolean doRemoveConfig(String pathKey) throws Exception; | ||
|
||
protected abstract Collection<String> doGetConfigKeys(String groupPath); | ||
|
||
protected abstract void doAddListener(String pathKey, ConfigurationListener listener); | ||
|
||
protected abstract void doRemoveListener(String pathKey, ConfigurationListener listener); | ||
|
||
protected String buildGroupPath(String group) { | ||
return buildPath(rootPath, group); | ||
} | ||
|
||
protected String buildPathKey(String group, String key) { | ||
return buildPath(buildGroupPath(group), key); | ||
} | ||
|
||
/** | ||
* Get the root path from the specified {@link URL connection URl} | ||
* | ||
* @param url the specified {@link URL connection URl} | ||
* @return non-null | ||
*/ | ||
protected String getRootPath(URL url) { | ||
String rootPath = PATH_SEPARATOR + getConfigNamespace(url) + getConfigBasePath(url); | ||
rootPath = PathUtils.normalize(rootPath); | ||
if (rootPath.endsWith(PATH_SEPARATOR)) { | ||
rootPath = rootPath.substring(0, rootPath.length() - 1); | ||
} | ||
return rootPath; | ||
} | ||
|
||
/** | ||
* Get the namespace from the specified {@link URL connection URl} | ||
* | ||
* @param url the specified {@link URL connection URl} | ||
* @return non-null | ||
*/ | ||
protected String getConfigNamespace(URL url) { | ||
return url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP); | ||
} | ||
|
||
/** | ||
* Get the config base path from the specified {@link URL connection URl} | ||
* | ||
* @param url the specified {@link URL connection URl} | ||
* @return non-null | ||
*/ | ||
protected String getConfigBasePath(URL url) { | ||
String configBasePath = url.getParameter(CONFIG_BASE_PATH_PARAM_NAME, DEFAULT_CONFIG_BASE_PATH); | ||
if (StringUtils.isNotEmpty(configBasePath) && !configBasePath.startsWith(PATH_SEPARATOR)) { | ||
configBasePath = PATH_SEPARATOR + configBasePath; | ||
} | ||
return configBasePath; | ||
} | ||
} |
Oops, something went wrong.