修正checkstyle格式

pull/1095/head
yangjuanying 2 years ago
parent 668fc24fdd
commit f807ce1053

@ -18,16 +18,6 @@
package com.tencent.cloud.polaris.config;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans;
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigPropertyRefresher;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector;
@ -44,6 +34,16 @@ import com.tencent.cloud.polaris.config.spring.annotation.SpringValueProcessor;
import com.tencent.cloud.polaris.config.spring.property.PlaceholderHelper;
import com.tencent.cloud.polaris.config.spring.property.SpringValueRegistry;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans;
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* polaris config module auto configuration at init application context phase.
*

@ -22,17 +22,19 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.logger.PolarisConfigLoggerContext;
import com.tencent.polaris.configuration.api.core.ConfigKVFileChangeListener;
import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
import org.springframework.util.CollectionUtils;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.logger.PolarisConfigLoggerContext;
import com.tencent.polaris.configuration.api.core.ConfigKVFileChangeListener;
import com.tencent.polaris.configuration.api.core.ConfigPropertyChangeInfo;
/**
* 1. Listen to the Polaris server configuration publishing event 2. Write the changed
@ -99,16 +101,16 @@ public abstract class PolarisConfigPropertyAutoRefresher
// 新增动态改变日志级别的能力
try {
if(changedKey.startsWith("logging.level") && changedKey.length() >= 14) {
if (changedKey.startsWith("logging.level") && changedKey.length() >= 14) {
String loggerName = changedKey.substring(14);
String newValue = configPropertyChangeInfo.getNewValue();
LOGGER.info("[SCT Config] set logging.level loggerName:{}, newValue:{}", loggerName, newValue);
PolarisConfigLoggerContext.setLevel(loggerName, newValue);
}
} catch(Exception e) {
}
catch (Exception e) {
LOGGER.error("[SCT Config] set logging.level exception,", e);
}
switch (configPropertyChangeInfo.getChangeType()) {
case MODIFIED:
case ADDED:

@ -15,15 +15,15 @@
* specific language governing permissions and limitations under the License.
*
*/
package com.tencent.cloud.polaris.config.config;
import java.util.List;
import com.tencent.cloud.polaris.config.enums.RefreshType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import com.tencent.cloud.polaris.config.enums.RefreshType;
/**
* polaris config module bootstrap configs.
@ -32,7 +32,6 @@ import com.tencent.cloud.polaris.config.enums.RefreshType;
*/
@ConfigurationProperties("spring.cloud.polaris.config")
public class PolarisConfigProperties {
/**
* Whether to open the configuration center.
*/

@ -18,12 +18,16 @@
package com.tencent.cloud.polaris.config.listener;
import static com.tencent.cloud.polaris.config.condition.ReflectRefreshTypeCondition.POLARIS_CONFIG_REFRESH_TYPE;
import java.util.Collections;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.enums.RefreshType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@ -36,11 +40,7 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.lang.NonNull;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.enums.RefreshType;
import static com.tencent.cloud.polaris.config.condition.ReflectRefreshTypeCondition.POLARIS_CONFIG_REFRESH_TYPE;
/**
* When {@link com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector} detects that
@ -72,19 +72,16 @@ public class PolarisConfigRefreshOptimizationListener implements ApplicationList
.getBean(PolarisConfigRefreshScopeAnnotationDetector.class);
boolean isRefreshScopeAnnotationUsed = detector.isRefreshScopeAnnotationUsed();
String annotatedRefreshScopeBeanName = detector.getAnnotatedRefreshScopeBeanName();
// using System.setProperty to set spring.cloud.polaris.config.refresh-type
String value = System.getProperty("spring.cloud.polaris.config.refresh-type");
boolean isSystemSetRefreshType = RefreshType.REFRESH_CONTEXT.toString().equalsIgnoreCase(value);
// a bean is using @RefreshScope, but the config refresh type is still [reflect], switch automatically
if (isRefreshScopeAnnotationUsed || isSystemSetRefreshType) {
if(isRefreshScopeAnnotationUsed) {
if (isRefreshScopeAnnotationUsed) {
LOGGER.warn("Detected that the bean [{}] is using @RefreshScope annotation, but the config refresh type is still [reflect]. "
+ "[SCT] will automatically switch to [refresh_context].", annotatedRefreshScopeBeanName);
}
if(isSystemSetRefreshType) {
if (isSystemSetRefreshType) {
LOGGER.warn("Detected that using System.setProperty to set spring.cloud.polaris.config.refresh-type = refresh_context, but the config refresh type is still [reflect]. "
+ "[SCT] will automatically switch to [refresh_context].");
}

@ -5,19 +5,18 @@ package com.tencent.cloud.polaris.config.logger;
*/
public enum Level {
TRACE("TRACE"), DEBUG("DEBUG"), INFO("INFO"), WARN("WARN"), ERROR("ERROR"),FATAL("FATAL"),OFF("OFF");
/** 日志级别. */
TRACE("TRACE"), DEBUG("DEBUG"), INFO("INFO"), WARN("WARN"), ERROR("ERROR"), FATAL("FATAL"), OFF("OFF");
private String level;
Level(String level) {
this.level = level;
}
public String getLevel() {
return level;
}
public static Level levelOf(String level) {
for (Level l : Level.values()) {
if (l.level.equalsIgnoreCase(level)) {

@ -2,6 +2,7 @@ package com.tencent.cloud.polaris.config.logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.ApplicationEvent;
@ -11,9 +12,7 @@ import org.springframework.context.ApplicationListener;
* @author juanyinyang
*/
public class PolarisConfigLoggerApplicationListener implements ApplicationListener<ApplicationEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigLoggerApplicationListener.class);
/**
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
*/
@ -28,7 +27,8 @@ public class PolarisConfigLoggerApplicationListener implements ApplicationListen
LOGGER.info("PolarisConfigLoggerApplicationListener onApplicationEvent init loggingSystem:{}", loggingSystem);
PolarisConfigLoggerContext.setLogSystem(loggingSystem);
}
} catch (Exception e) {
}
catch (Exception e) {
LOGGER.error("PolarisConfigLoggerApplicationListener onApplicationEvent exception:", e);
}
}

@ -9,14 +9,14 @@
package com.tencent.cloud.polaris.config.logger;
import static org.springframework.boot.logging.LoggingSystem.ROOT_LOGGER_NAME;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.util.Assert;
import static org.springframework.boot.logging.LoggingSystem.ROOT_LOGGER_NAME;
/**
* @author juanyinyang
@ -28,20 +28,19 @@ public final class PolarisConfigLoggerContext {
private PolarisConfigLoggerContext() {
}
protected static void setLogSystem(LoggingSystem logSystem) {
Assert.notNull(logSystem,"Logging System should not be null");
Assert.notNull(logSystem, "Logging System should not be null");
PolarisConfigLoggerContext.loggingSystem = logSystem;
}
public static void setLevel(String loggerName, String level) {
if (loggingSystem == null) {
printLog("[SCT Config] PolarisConfigLoggerContext logger: ["+loggerName+"] change to target level fail. caused by internal exception:" + level,Level.WARN);
printLog("[SCT Config] PolarisConfigLoggerContext logger: [" + loggerName + "] change to target level fail. caused by internal exception:" + level, Level.WARN);
return;
}
Level loggerLevel = Level.levelOf(level);
if (loggerLevel == null) {
printLog("[SCT Config] PolarisConfigLoggerContext logger: ["+loggerName+"] change to target level fail. caused by level is not support, level:" + level,Level.WARN);
printLog("[SCT Config] PolarisConfigLoggerContext logger: [" + loggerName + "] change to target level fail. caused by level is not support, level:" + level, Level.WARN);
return;
}
LogLevel logLevel = null;
@ -68,29 +67,29 @@ public final class PolarisConfigLoggerContext {
logLevel = LogLevel.FATAL;
break;
default:
printLog("[SCT Config] PolarisConfigLoggerContext logger: ["+loggerName+"] setLevel fail. caused by level is not support, level: " + level,Level.WARN);
printLog("[SCT Config] PolarisConfigLoggerContext logger: [" + loggerName + "] setLevel fail. caused by level is not support, level: " + level, Level.WARN);
}
loggingSystem.setLogLevel(loggerName,logLevel);
printLog("[SCT Config] PolarisConfigLoggerContext logger: ["+loggerName+"] changed to level:" + level,Level.INFO);
loggingSystem.setLogLevel(loggerName, logLevel);
printLog("[SCT Config] PolarisConfigLoggerContext logger: [" + loggerName + "] changed to level:" + level, Level.INFO);
}
/**
*
* @param message
* @param level
* .
*/
private static void printLog(String message, Level level){
private static void printLog(String message, Level level) {
Logger logger = LoggerFactory.getLogger(ROOT_LOGGER_NAME);
if (level.ordinal() <= Level.INFO.ordinal() ) {
if (level.ordinal() <= Level.INFO.ordinal()) {
if (logger != null) {
logger.info(message);
} else {
}
else {
StdLog.info(message);
}
} else {
}
else {
if (logger != null) {
logger.warn(message);
} else {
}
else {
StdLog.warn(message);
}
}

@ -4,10 +4,10 @@ import java.io.PrintStream;
import java.util.Calendar;
/**
* internal output logger
* internal output logger.
* @author juanyinyang
*/
public class StdLog {
public final class StdLog {
private static final String CLASS_INFO = StdLog.class.getName();
@ -15,27 +15,29 @@ public class StdLog {
protected static boolean debugEnabled = false;
/**
* enable info level log
* *enable info level log.
*/
protected static boolean infoEnabled = true;
/**
* quite mode will out put nothing
* quite mode will out put nothing.
*/
protected static boolean quietMode = false;
private static final String DEBUG_FIX = "StdLog:DEBUG: ";
private static final String INFO_FIX = "StdLog:INFO: ";
private static final String WARN_FIX = "StdLog:WARN: ";
private StdLog() {
}
public static void setQuietMode(boolean quietMode) {
StdLog.quietMode = quietMode;
}
public static void setInfoEnabled(boolean infoEnabled ){
public static void setInfoEnabled(boolean infoEnabled) {
StdLog.infoEnabled = infoEnabled;
}
@ -44,21 +46,20 @@ public class StdLog {
}
public static void debug(String msg) {
if (debugEnabled && !quietMode) {
println(System.out,DEBUG_FIX + msg);
println(System.out, DEBUG_FIX + msg);
}
}
public static void info(String msg) {
if (infoEnabled && !quietMode) {
println(System.out,INFO_FIX + msg);
println(System.out, INFO_FIX + msg);
}
}
public static void warn(String msg) {
if (infoEnabled && !quietMode) {
println(System.err,WARN_FIX + msg);
println(System.err, WARN_FIX + msg);
}
}
@ -66,7 +67,7 @@ public class StdLog {
if (quietMode) {
return;
}
println(System.err,WARN_FIX + msg);
println(System.err, WARN_FIX + msg);
if (t != null) {
t.printStackTrace();
}
@ -75,5 +76,4 @@ public class StdLog {
private static void println(PrintStream out, String msg) {
out.println(Calendar.getInstance().getTime().toString() + " " + CLASS_INFO + " " + msg);
}
}

@ -24,16 +24,16 @@ import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.CollectionUtils;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.polaris.api.config.ConfigProvider;
import com.tencent.polaris.api.config.Configuration;
import com.tencent.polaris.factory.ConfigAPIFactory;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.CollectionUtils;
/**
* Properties for Polaris {@link com.tencent.polaris.client.api.SDKContext}.

Loading…
Cancel
Save