Split the Environment into two parts: Environment in Common and ConfigurationUtils in ConfigCenter
This commit is contained in:
parent
c880720724
commit
51146f726d
|
|
@ -58,11 +58,9 @@ public class ConfigConditionRouter extends AbstractRouter implements Configurati
|
|||
this.configuration = configuration;
|
||||
this.force = false;
|
||||
this.url = url;
|
||||
String app = this.url.getParameter(Constants.APPLICATION_KEY);
|
||||
String serviceKey = this.url.getServiceKey();
|
||||
try {
|
||||
String rawRule = this.configuration.getConfig(serviceKey + Constants.ROUTERS_SUFFIX, this);
|
||||
String appRawRule = this.configuration.getConfig(app + Constants.ROUTERS_SUFFIX, this);
|
||||
String rawRule = this.configuration.getConfig(url.getEncodedServiceKey() + Constants.ROUTERS_SUFFIX, this);
|
||||
String appRawRule = this.configuration.getConfig(url.getParameter(Constants.APPLICATION_KEY) + Constants.ROUTERS_SUFFIX, this);
|
||||
if (!StringUtils.isEmpty(rawRule)) {
|
||||
try {
|
||||
routerRule = ConditionRuleParser.parse(rawRule);
|
||||
|
|
@ -81,7 +79,7 @@ public class ConfigConditionRouter extends AbstractRouter implements Configurati
|
|||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to init the condition router for service " + serviceKey + ", application " + app, e);
|
||||
throw new IllegalStateException("Failed to init the condition router for service " + url.getServiceKey() + ", application " + url.getParameter(Constants.APPLICATION_KEY), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1285,6 +1285,12 @@ public /**final**/ class URL implements Serializable {
|
|||
return new InetSocketAddress(host, port);
|
||||
}
|
||||
|
||||
public String getEncodedServiceKey() {
|
||||
String serviceKey = this.getServiceKey();
|
||||
serviceKey = serviceKey.replaceFirst("/", "*");
|
||||
return serviceKey;
|
||||
}
|
||||
|
||||
public String getServiceKey() {
|
||||
String inf = getServiceInterface();
|
||||
if (inf == null) {
|
||||
|
|
|
|||
|
|
@ -14,24 +14,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.context;
|
||||
package org.apache.dubbo.common.config;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.CompositeConfiguration;
|
||||
import org.apache.dubbo.common.config.EnvironmentConfiguration;
|
||||
import org.apache.dubbo.common.config.InmemoryConfiguration;
|
||||
import org.apache.dubbo.common.config.PropertiesConfiguration;
|
||||
import org.apache.dubbo.common.config.SystemConfiguration;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.ConfigCenterConfig;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
|
|
@ -46,12 +35,8 @@ public class Environment {
|
|||
private volatile Map<String, InmemoryConfiguration> externalConfsHolder = new ConcurrentHashMap<>();
|
||||
private volatile Map<String, InmemoryConfiguration> appExternalConfsHolder = new ConcurrentHashMap<>();
|
||||
private volatile Map<String, CompositeConfiguration> startupCompositeConfsHolder = new ConcurrentHashMap<>();
|
||||
private volatile Map<String, CompositeConfiguration> runtimeCompositeConfsHolder = new ConcurrentHashMap<>();
|
||||
|
||||
private volatile DynamicConfiguration dynamicConfiguration;
|
||||
|
||||
private volatile boolean isConfigCenterFirst = true;
|
||||
private volatile ConfigCenterConfig configCenter;
|
||||
|
||||
private Map<String, String> externalConfigurationMap = new HashMap<>();
|
||||
private Map<String, String> appExternalConfigurationMap = new HashMap<>();
|
||||
|
|
@ -88,24 +73,12 @@ public class Environment {
|
|||
return environmentConfsHolder.computeIfAbsent(toKey(prefix, id), k -> new EnvironmentConfiguration(prefix, id));
|
||||
}
|
||||
|
||||
public void setConfigCenter(ConfigCenterConfig configCenter) {
|
||||
this.configCenter = configCenter;
|
||||
}
|
||||
|
||||
public synchronized void setExternalConfiguration(Map<String, String> externalConfiguration) {
|
||||
this.externalConfigurationMap = externalConfiguration;
|
||||
if (configCenter == null) {
|
||||
configCenter = new ConfigCenterConfig();
|
||||
}
|
||||
configCenter.init();
|
||||
}
|
||||
|
||||
public synchronized void setAppExternalConfiguration(Map<String, String> appExternalConfiguration) {
|
||||
this.appExternalConfigurationMap = appExternalConfiguration;
|
||||
if (configCenter == null) {
|
||||
configCenter = new ConfigCenterConfig();
|
||||
}
|
||||
configCenter.init();
|
||||
}
|
||||
|
||||
public void updateExternalConfigurationMap(Map<String, String> externalMap) {
|
||||
|
|
@ -127,41 +100,6 @@ public class Environment {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME This method will recreate Configuration for each RPC, how much latency affect will this action has on performance?
|
||||
*
|
||||
* @param url, the url metadata.
|
||||
* @param method, the method name the RPC is trying to invoke.
|
||||
* @return
|
||||
*/
|
||||
public CompositeConfiguration getRuntimeCompositeConf(URL url, String method) {
|
||||
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
|
||||
|
||||
String app = url.getParameter(Constants.APPLICATION_KEY);
|
||||
String service = url.getServiceKey();
|
||||
compositeConfiguration.addConfiguration(new ConfigurationWrapper(app, service, method, getDynamicConfiguration()));
|
||||
|
||||
compositeConfiguration.addConfiguration(url.toConfiguration());
|
||||
compositeConfiguration.addConfiguration(this.getSystemConf(null, null));
|
||||
compositeConfiguration.addConfiguration(this.getPropertiesConf(null, null));
|
||||
return compositeConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* If user opens DynamicConfig, the extension instance must has been created during the initialization of ConfigCenterConfig with the right extension type user specified.
|
||||
* If no DynamicConfig presents, NopDynamicConfiguration will be used.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DynamicConfiguration getDynamicConfiguration() {
|
||||
Set<Object> configurations = ExtensionLoader.getExtensionLoader(DynamicConfiguration.class).getLoadedExtensionInstances();
|
||||
if (CollectionUtils.isEmpty(configurations)) {
|
||||
return ExtensionLoader.getExtensionLoader(DynamicConfiguration.class).getDefaultExtension();
|
||||
} else {
|
||||
return (DynamicConfiguration) configurations.iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
private static String toKey(String keypart1, String keypart2) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (StringUtils.isNotEmpty(keypart1)) {
|
||||
|
|
@ -304,29 +304,4 @@ public class ConfigUtils {
|
|||
}
|
||||
return PID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int getServerShutdownTimeout() {
|
||||
int timeout = Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
String value = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
|
||||
if (value != null && value.length() > 0) {
|
||||
try {
|
||||
timeout = Integer.parseInt(value);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
value = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
|
||||
if (value != null && value.length() > 0) {
|
||||
try {
|
||||
timeout = Integer.parseInt(value) * 1000;
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,31 +256,4 @@ public class ConfigUtilsTest {
|
|||
public void testGetPid() throws Exception {
|
||||
assertThat(ConfigUtils.getPid(), greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerShutdownTimeoutFromShutdownWait() throws Exception {
|
||||
System.setProperty(Constants.SHUTDOWN_WAIT_KEY, "1234");
|
||||
try {
|
||||
assertThat(ConfigUtils.getServerShutdownTimeout(), equalTo(1234));
|
||||
} finally {
|
||||
System.clearProperty(Constants.SHUTDOWN_WAIT_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerShutdownTimeoutFromShutdownWaitSeconds() throws Exception {
|
||||
System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, "1234");
|
||||
try {
|
||||
assertThat(ConfigUtils.getServerShutdownTimeout(), equalTo(1234 * 1000));
|
||||
} finally {
|
||||
System.clearProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetServerShutdownTimeoutFromDefault() throws Exception {
|
||||
System.clearProperty(Constants.SHUTDOWN_WAIT_KEY);
|
||||
System.clearProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
|
||||
assertThat(ConfigUtils.getServerShutdownTimeout(), equalTo(Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT));
|
||||
}
|
||||
}
|
||||
|
|
@ -20,13 +20,13 @@ import org.apache.dubbo.common.Constants;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.CompositeConfiguration;
|
||||
import org.apache.dubbo.common.config.Configuration;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.ReflectUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.context.Environment;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
import org.apache.dubbo.config.utils.ConfigConverter;
|
||||
import org.apache.dubbo.rpc.model.ConsumerMethodModel;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.config;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.Version;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
|
|
@ -26,7 +27,6 @@ import org.apache.dubbo.common.utils.NetUtils;
|
|||
import org.apache.dubbo.common.utils.ReflectUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.common.utils.UrlUtils;
|
||||
import org.apache.dubbo.config.context.Environment;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
import org.apache.dubbo.metadata.integration.MetadataReportService;
|
||||
|
|
@ -154,14 +154,16 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
}
|
||||
}
|
||||
|
||||
// For compatibility purpose, use registry as the default config center if there's no one specified explicitly.
|
||||
// For compatibility purpose, use registry as the default config center if the registry protocol is zookeeper and there's no config center specified explicitly.
|
||||
RegistryConfig registry = registries.get(0);
|
||||
if (registry.isZookeeperProtocol()) {
|
||||
Set<Object> loadedConfigurations = ExtensionLoader.getExtensionLoader(DynamicConfiguration.class).getLoadedExtensionInstances();
|
||||
// we use the loading status of DynamicConfiguration to decide whether ConfigCenter has been initiated.
|
||||
if (CollectionUtils.isEmpty(loadedConfigurations)) {
|
||||
ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
|
||||
configCenterConfig.setProtocol(registry.getProtocol());
|
||||
configCenterConfig.setAddress(registry.getAddress());
|
||||
configCenterConfig.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ package org.apache.dubbo.config;
|
|||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.common.utils.UrlUtils;
|
||||
import org.apache.dubbo.config.context.Environment;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
|
||||
|
|
|
|||
|
|
@ -335,7 +335,11 @@ public class RegistryConfig extends AbstractConfig {
|
|||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@Parameter(excluded = true)
|
||||
public boolean isZookeeperProtocol() {
|
||||
if (!isValid()) {
|
||||
return false;
|
||||
}
|
||||
boolean isZookeeper = StringUtils.isNotEmpty(this.getProtocol()) && this.getProtocol().equals("zookeeper");
|
||||
if (!isZookeeper) {
|
||||
String address = this.getAddress();
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ import org.apache.dubbo.common.Constants;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.Version;
|
||||
import org.apache.dubbo.common.bytecode.Wrapper;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.ClassHelper;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.apache.dubbo.config.context.Environment;
|
||||
import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker;
|
||||
import org.apache.dubbo.config.support.Parameter;
|
||||
import org.apache.dubbo.metadata.integration.MetadataReportService;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class ConfigCenterBean extends ConfigCenterConfig implements Initializing
|
|||
|
||||
if ((getRegistry() == null)) {
|
||||
List<RegistryConfig> registryConfigs = new ArrayList<>();
|
||||
if (getApplication() == null || getApplication().getRegistries() == null || getApplication().getRegistries().isEmpty()) {
|
||||
if (getApplication() != null && getApplication().getRegistries() != null && !getApplication().getRegistries().isEmpty()) {
|
||||
registryConfigs = getApplication().getRegistries();
|
||||
} else {
|
||||
Map<String, RegistryConfig> registryConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class, false, false);
|
||||
|
|
@ -107,9 +107,9 @@ public class ConfigCenterBean extends ConfigCenterConfig implements Initializing
|
|||
if (auto) {
|
||||
Map<String, String> externalProperties = getConfigurations(getConfigfile(), environment);
|
||||
Map<String, String> appExternalProperties = getConfigurations("application." + getConfigfile(), environment);
|
||||
org.apache.dubbo.config.context.Environment.getInstance().setConfigCenter(this);
|
||||
org.apache.dubbo.config.context.Environment.getInstance().setExternalConfiguration(externalProperties);
|
||||
org.apache.dubbo.config.context.Environment.getInstance().setAppExternalConfiguration(appExternalProperties);
|
||||
org.apache.dubbo.common.config.Environment.getInstance().setExternalConfiguration(externalProperties);
|
||||
org.apache.dubbo.common.config.Environment.getInstance().setAppExternalConfiguration(appExternalProperties);
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* 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.configcenter;
|
||||
|
||||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.config.CompositeConfiguration;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ConfigurationUtils {
|
||||
private static final CompositeConfiguration compositeConfiguration;
|
||||
|
||||
static {
|
||||
compositeConfiguration = new CompositeConfiguration();
|
||||
compositeConfiguration.addConfiguration(getDynamicConfiguration());
|
||||
compositeConfiguration.addConfiguration(Environment.getInstance().getAppExternalConfiguration(null, null));
|
||||
compositeConfiguration.addConfiguration(Environment.getInstance().getExternalConfiguration(null, null));
|
||||
compositeConfiguration.addConfiguration(Environment.getInstance().getSystemConf(null, null));
|
||||
compositeConfiguration.addConfiguration(Environment.getInstance().getPropertiesConf(null, null));
|
||||
}
|
||||
|
||||
private volatile Map<String, CompositeConfiguration> runtimeCompositeConfsHolder = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* FIXME This method will recreate Configuration for each RPC, how much latency affect will this action has on performance?
|
||||
*
|
||||
* @param url, the url metadata.
|
||||
* @param method, the method name the RPC is trying to invoke.
|
||||
* @return
|
||||
*/
|
||||
public static CompositeConfiguration getRuntimeCompositeConf(URL url, String method) {
|
||||
CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
|
||||
|
||||
String app = url.getParameter(Constants.APPLICATION_KEY);
|
||||
String service = url.getServiceKey();
|
||||
compositeConfiguration.addConfiguration(new ConfigurationWrapper(app, service, method, getDynamicConfiguration()));
|
||||
|
||||
compositeConfiguration.addConfiguration(url.toConfiguration());
|
||||
|
||||
return compositeConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* If user opens DynamicConfig, the extension instance must has been created during the initialization of ConfigCenterConfig with the right extension type user specified.
|
||||
* If no DynamicConfig presents, NopDynamicConfiguration will be used.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static DynamicConfiguration getDynamicConfiguration() {
|
||||
Set<Object> configurations = ExtensionLoader.getExtensionLoader(DynamicConfiguration.class).getLoadedExtensionInstances();
|
||||
if (CollectionUtils.isEmpty(configurations)) {
|
||||
return ExtensionLoader.getExtensionLoader(DynamicConfiguration.class).getDefaultExtension();
|
||||
} else {
|
||||
return (DynamicConfiguration) configurations.iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static int getServerShutdownTimeout() {
|
||||
int timeout = Constants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT;
|
||||
String value = getProperty(Constants.SHUTDOWN_WAIT_KEY);
|
||||
if (value != null && value.length() > 0) {
|
||||
try {
|
||||
timeout = Integer.parseInt(value);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
value = getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
|
||||
if (value != null && value.length() > 0) {
|
||||
try {
|
||||
timeout = Integer.parseInt(value) * 1000;
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public static String getProperty(String key) {
|
||||
return compositeConfiguration.getString(key);
|
||||
}
|
||||
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
return compositeConfiguration.getString(key, defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.dubbo.config.context;
|
||||
package org.apache.dubbo.configcenter;
|
||||
|
||||
import org.apache.dubbo.common.config.AbstractConfiguration;
|
||||
import org.apache.dubbo.common.config.Configuration;
|
||||
|
|
@ -23,7 +23,7 @@ import org.apache.dubbo.common.extension.SPI;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
@SPI("zookeeper")
|
||||
@SPI("nop")
|
||||
public interface DynamicConfiguration extends Configuration {
|
||||
|
||||
void init();
|
||||
|
|
|
|||
|
|
@ -34,5 +34,10 @@
|
|||
<artifactId>dubbo-container-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
package org.apache.dubbo.container.log4j;
|
||||
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.container.Container;
|
||||
|
||||
import org.apache.log4j.Appender;
|
||||
import org.apache.log4j.FileAppender;
|
||||
import org.apache.log4j.LogManager;
|
||||
|
|
@ -43,9 +42,9 @@ public class Log4jContainer implements Container {
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void start() {
|
||||
String file = ConfigUtils.getProperty(LOG4J_FILE);
|
||||
String file = ConfigurationUtils.getProperty(LOG4J_FILE);
|
||||
if (file != null && file.length() > 0) {
|
||||
String level = ConfigUtils.getProperty(LOG4J_LEVEL);
|
||||
String level = ConfigurationUtils.getProperty(LOG4J_LEVEL);
|
||||
if (level == null || level.length() == 0) {
|
||||
level = DEFAULT_LOG4J_LEVEL;
|
||||
}
|
||||
|
|
@ -59,7 +58,7 @@ public class Log4jContainer implements Container {
|
|||
properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n");
|
||||
PropertyConfigurator.configure(properties);
|
||||
}
|
||||
String subdirectory = ConfigUtils.getProperty(LOG4J_SUBDIRECTORY);
|
||||
String subdirectory = ConfigurationUtils.getProperty(LOG4J_SUBDIRECTORY);
|
||||
if (subdirectory != null && subdirectory.length() > 0) {
|
||||
Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers();
|
||||
while (ls.hasMoreElements()) {
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@
|
|||
|
||||
<!-- use multicast registry center to discover service -->
|
||||
|
||||
<!--<dubbo:registry group="dubboregistrygroup1" address="zookeeper://127.0.0.1:2181"/>-->
|
||||
<dubbo:registry group="dubboregistrygroup1" address="zookeeper://127.0.0.1:2181"/>
|
||||
|
||||
<dubbo:configcenter address="zookeeper://127.0.0.1:2181" namespace="dubboregistrygroup1"
|
||||
configfile="dubbo.properties"/>
|
||||
<!--<dubbo:configcenter address="zookeeper://127.0.0.1:2181" namespace="dubboregistrygroup1"-->
|
||||
<!--configfile="dubbo.properties"/>-->
|
||||
|
||||
<!-- generate proxy for the remote service, then demoService can be used in the same way as the
|
||||
local regular interface -->
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@
|
|||
<dubbo:application name="demo-provider"/>
|
||||
<!--<dubbo:provider tag="tag3"/>-->
|
||||
|
||||
<dubbo:registry group="dubboregistrygroup1" address="zookeeper://127.0.0.1:2182">
|
||||
<dubbo:registry group="dubboregistrygroup1" address="zookeeper://127.0.0.1:2181">
|
||||
</dubbo:registry>
|
||||
|
||||
<dubbo:configcenter address="zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182" namespace="dubboregistrygroup1"
|
||||
configfile="dubbo.properties" appname="demo-provider"/>
|
||||
<!--<dubbo:configcenter address="zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182" namespace="dubboregistrygroup1"-->
|
||||
<!--configfile="dubbo.properties" appname="demo-provider"/>-->
|
||||
|
||||
<!-- use dubbo protocol to export service on port 20880 -->
|
||||
<dubbo:protocol name="dubbo" port="-1"/>
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public class RegistryDirectory<T> extends AbstractDirectory<T> implements Notify
|
|||
setConsumerUrl(url);
|
||||
String rawConfig = null;
|
||||
try {
|
||||
rawConfig = dynamicConfiguration.getConfig(url.getServiceKey() + Constants.CONFIGURATORS_SUFFIX, this);
|
||||
rawConfig = dynamicConfiguration.getConfig(url.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX, this);
|
||||
if (StringUtils.isNotEmpty(rawConfig)) {
|
||||
this.dynamicConfigurators = configToConfiguratiors(rawConfig);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ import org.apache.dubbo.common.extension.ExtensionLoader;
|
|||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.utils.CollectionUtils;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.common.utils.NamedThreadFactory;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.common.utils.UrlUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigChangeEvent;
|
||||
import org.apache.dubbo.configcenter.ConfigChangeType;
|
||||
import org.apache.dubbo.configcenter.ConfigurationListener;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.configcenter.DynamicConfiguration;
|
||||
import org.apache.dubbo.registry.NotifyListener;
|
||||
import org.apache.dubbo.registry.Registry;
|
||||
|
|
@ -190,7 +190,7 @@ public class RegistryProtocol implements Protocol {
|
|||
listener.setAppDynamicConfigurators(appDynamicConfigurators);
|
||||
configurators.addAll(appDynamicConfigurators);
|
||||
}
|
||||
String rawConfig = dynamicConfiguration.getConfig(providerUrl.getServiceKey() + Constants.CONFIGURATORS_SUFFIX, listener);
|
||||
String rawConfig = dynamicConfiguration.getConfig(providerUrl.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX, listener);
|
||||
if (!StringUtils.isEmpty(rawConfig)) {
|
||||
List<Configurator> dynamicConfigurators = RegistryDirectory.configToConfiguratiors(rawConfig);
|
||||
listener.setDynamicConfigurators(dynamicConfigurators);
|
||||
|
|
@ -637,7 +637,7 @@ public class RegistryProtocol implements Protocol {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int timeout = ConfigUtils.getServerShutdownTimeout();
|
||||
int timeout = ConfigurationUtils.getServerShutdownTimeout();
|
||||
if (timeout > 0) {
|
||||
logger.info("Waiting " + timeout + "ms for registry to notify all consumers before unexport. Usually, this is called when you use dubbo API");
|
||||
Thread.sleep(timeout);
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ public class ZKTools {
|
|||
new ExponentialBackoffRetry(1000, 3));
|
||||
client.start();
|
||||
|
||||
testStartupConfig();
|
||||
// testProviderConfig();
|
||||
// testStartupConfig();
|
||||
testProviderConfig();
|
||||
// testPathCache();
|
||||
// testTreeCache();
|
||||
// testCuratorListener();
|
||||
|
|
@ -72,20 +72,22 @@ public class ZKTools {
|
|||
}
|
||||
|
||||
public static void testProviderConfig() {
|
||||
String str = "{\n" +
|
||||
"\t\"service\": \"org.apache.dubbo.demo.DemoService\",\n" +
|
||||
"\t\"items\": [{\n" +
|
||||
"\t\t\"addresses\": [\"30.5.120.49\"],\n" +
|
||||
"\t\t\"rules\": [{\n" +
|
||||
"\t\t\t\"key\": \"weight\",\n" +
|
||||
"\t\t\t\"value\": 500\n" +
|
||||
"\t\t}],\n" +
|
||||
"\t\t\"app\": \"demo-provider\",\n" +
|
||||
"\t\t\"side\": \"provider\"\n" +
|
||||
"\t}]\n" +
|
||||
"}";
|
||||
String str = "---\n" +
|
||||
"apiVersion: v2.7\n" +
|
||||
"scope: service\n" +
|
||||
"key: dd-test/org.apache.dubbo.demo.DemoService:1.0.4\n" +
|
||||
"enabled: true\n" +
|
||||
"configs:\n" +
|
||||
"- addresses: ['0.0.0.0:20880']\n" +
|
||||
" side: provider\n" +
|
||||
" parameters:\n" +
|
||||
" timeout: 6000\n" +
|
||||
"...";
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
try {
|
||||
String path = "/dubbo/config/demo-provider/org.apache.dubbo.demo.DemoService.CONFIGURATORS";
|
||||
String path = "/dubbo/config/dd-test*org.apache.dubbo.demo.DemoService:1.0.4/configurators";
|
||||
if (client.checkExists().forPath(path) == null) {
|
||||
client.create().creatingParentsIfNeeded().forPath(path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-configcenter-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-remoting-netty4</artifactId>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package org.apache.dubbo.rpc.protocol.dubbo;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.utils.AtomicPositiveInteger;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.remoting.RemotingException;
|
||||
import org.apache.dubbo.remoting.TimeoutException;
|
||||
import org.apache.dubbo.remoting.exchange.ExchangeClient;
|
||||
|
|
@ -148,7 +148,7 @@ public class DubboInvoker<T> extends AbstractInvoker<T> {
|
|||
}
|
||||
for (ExchangeClient client : clients) {
|
||||
try {
|
||||
client.close(ConfigUtils.getServerShutdownTimeout());
|
||||
client.close(ConfigurationUtils.getServerShutdownTimeout());
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ import org.apache.dubbo.common.extension.ExtensionLoader;
|
|||
import org.apache.dubbo.common.serialize.support.SerializableClassRegistry;
|
||||
import org.apache.dubbo.common.serialize.support.SerializationOptimizer;
|
||||
import org.apache.dubbo.common.utils.ConcurrentHashSet;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.remoting.Channel;
|
||||
import org.apache.dubbo.remoting.RemotingException;
|
||||
import org.apache.dubbo.remoting.Transporter;
|
||||
|
|
@ -454,7 +454,7 @@ public class DubboProtocol extends AbstractProtocol {
|
|||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Close dubbo server: " + server.getLocalAddress());
|
||||
}
|
||||
server.close(ConfigUtils.getServerShutdownTimeout());
|
||||
server.close(ConfigurationUtils.getServerShutdownTimeout());
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
|
|
@ -468,7 +468,7 @@ public class DubboProtocol extends AbstractProtocol {
|
|||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Close dubbo connect: " + client.getLocalAddress() + "-->" + client.getRemoteAddress());
|
||||
}
|
||||
client.close(ConfigUtils.getServerShutdownTimeout());
|
||||
client.close(ConfigurationUtils.getServerShutdownTimeout());
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
|
|
@ -482,7 +482,7 @@ public class DubboProtocol extends AbstractProtocol {
|
|||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Close dubbo connect: " + client.getLocalAddress() + "-->" + client.getRemoteAddress());
|
||||
}
|
||||
client.close(ConfigUtils.getServerShutdownTimeout());
|
||||
client.close(ConfigurationUtils.getServerShutdownTimeout());
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package org.apache.dubbo.rpc.protocol.dubbo;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.common.utils.NetUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.remoting.exchange.ExchangeClient;
|
||||
import org.apache.dubbo.rpc.Exporter;
|
||||
import org.apache.dubbo.rpc.ProxyFactory;
|
||||
|
|
@ -91,7 +91,7 @@ public class DubboInvokerAvilableTest {
|
|||
|
||||
try{
|
||||
System.setProperty(Constants.SHUTDOWN_WAIT_KEY, "2000");
|
||||
System.out.println("------------ConfigUtils.getServerShutdownTimeout(): " + ConfigUtils.getServerShutdownTimeout());
|
||||
System.out.println("------------ConfigUtils.getServerShutdownTimeout(): " + ConfigurationUtils.getServerShutdownTimeout());
|
||||
protocol.destroy();
|
||||
}finally {
|
||||
System.getProperties().remove(Constants.SHUTDOWN_WAIT_KEY);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package org.apache.dubbo.rpc.protocol.thrift;
|
|||
import org.apache.dubbo.common.Constants;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.utils.ConfigUtils;
|
||||
import org.apache.dubbo.configcenter.ConfigurationUtils;
|
||||
import org.apache.dubbo.remoting.Channel;
|
||||
import org.apache.dubbo.remoting.RemotingException;
|
||||
import org.apache.dubbo.remoting.Transporter;
|
||||
|
|
@ -146,7 +146,7 @@ public class ThriftProtocol extends AbstractProtocol {
|
|||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Close dubbo server: " + server.getLocalAddress());
|
||||
}
|
||||
server.close(ConfigUtils.getServerShutdownTimeout());
|
||||
server.close(ConfigurationUtils.getServerShutdownTimeout());
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue