Adding error code to multiple classes in multiple modules. (#10373)

* Add @Override in DubboConfigDefaultPropertyValueBeanPostProcessor

* Add error code 5-1 in config center module.

* Code optimization.
This commit is contained in:
Andy Cheung 2022-07-27 17:21:39 +08:00 committed by GitHub
parent 88f17daf06
commit f9eb28cf7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 12 deletions

View File

@ -17,7 +17,7 @@
package org.apache.dubbo.common.config.configcenter;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
@ -75,7 +75,7 @@ public abstract class AbstractDynamicConfiguration implements DynamicConfigurati
/**
* Logger
*/
protected final Logger logger = LoggerFactory.getLogger(getClass());
protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
/**
* The thread pool for workers who executes the tasks

View File

@ -52,6 +52,7 @@ public class DubboConfigDefaultPropertyValueBeanPostProcessor extends GenericBea
*/
public static final String BEAN_NAME = "dubboConfigDefaultPropertyValueBeanPostProcessor";
@Override
protected void processBeforeInitialization(AbstractConfig dubboConfigBean, String beanName) throws BeansException {
// ignore auto generate bean name
if (!beanName.contains("#")) {

View File

@ -21,7 +21,7 @@ import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
@ -61,7 +61,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE
* Please see http://dubbo.apache.org/zh-cn/docs/user/configuration/config-center.html for details.
*/
public class ApolloDynamicConfiguration implements DynamicConfiguration {
private static final Logger logger = LoggerFactory.getLogger(ApolloDynamicConfiguration.class);
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(ApolloDynamicConfiguration.class);
private static final String APOLLO_ENV_KEY = "env";
private static final String APOLLO_ADDR_KEY = "apollo.meta";
private static final String APOLLO_CLUSTER_KEY = "apollo.cluster";
@ -106,7 +106,10 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
throw new IllegalStateException("Failed to connect to config center, the config center is Apollo, " +
"the address is: " + (StringUtils.isNotEmpty(configAddr) ? configAddr : configEnv));
} else {
logger.warn("Failed to connect to config center, the config center is Apollo, " +
// 5-1 Failed to connect to configuration center.
logger.warn("5-1", "configuration server offline", "",
"Failed to connect to config center, the config center is Apollo, " +
"the address is: " + (StringUtils.isNotEmpty(configAddr) ? configAddr : configEnv) +
", will use the local cache value instead before eventually the connection is established.");
}

View File

@ -63,7 +63,16 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration
zkClient = zookeeperTransporter.connect(url);
boolean isConnected = zkClient.isConnected();
if (!isConnected) {
throw new IllegalStateException("Failed to connect with zookeeper, pls check if url " + url + " is correct.");
IllegalStateException illegalStateException =
new IllegalStateException("Failed to connect with zookeeper, pls check if url " + url + " is correct.");
if (logger != null) {
logger.error("5-1", "configuration server offline", "",
"Failed to connect with zookeeper", illegalStateException);
}
throw illegalStateException;
}
}

View File

@ -52,8 +52,8 @@ import static org.apache.dubbo.metadata.MetadataConstants.META_DATA_STORE_TAG;
*/
public class RedisMetadataReport extends AbstractMetadataReport {
private final static String REDIS_DATABASE_KEY = "database";
private final static Logger logger = LoggerFactory.getLogger(RedisMetadataReport.class);
private static final String REDIS_DATABASE_KEY = "database";
private static final Logger logger = LoggerFactory.getLogger(RedisMetadataReport.class);
// protected , for test
protected JedisPool pool;
@ -66,7 +66,7 @@ public class RedisMetadataReport extends AbstractMetadataReport {
super(url);
timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
if (url.getParameter(CLUSTER_KEY, false)) {
jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes = new HashSet<>();
List<URL> urls = url.getBackupUrls();
for (URL tmpUrl : urls) {
jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
@ -103,7 +103,7 @@ public class RedisMetadataReport extends AbstractMetadataReport {
if (StringUtils.isEmpty(content)) {
return Collections.emptyList();
}
return new ArrayList<String>(Arrays.asList(URL.decode(content)));
return new ArrayList<>(Arrays.asList(URL.decode(content)));
}
@Override

View File

@ -19,7 +19,7 @@ package org.apache.dubbo.rpc.proxy.javassist;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.bytecode.Proxy;
import org.apache.dubbo.common.bytecode.Wrapper;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.proxy.AbstractProxyFactory;
@ -33,7 +33,7 @@ import java.util.Arrays;
* JavassistRpcProxyFactory
*/
public class JavassistProxyFactory extends AbstractProxyFactory {
private final static Logger logger = LoggerFactory.getLogger(JavassistProxyFactory.class);
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(JavassistProxyFactory.class);
private final JdkProxyFactory jdkProxyFactory = new JdkProxyFactory();
@Override