format code

pull/326/head
weihu 2 years ago
parent 72fff2459f
commit 2f27841691

@ -89,7 +89,6 @@ public class PolarisPropertySourceAutoRefresher
this.placeholderHelper = SpringInjector.getInstance(PlaceholderHelper.class);
this.typeConverterHasConvertIfNecessaryWithFieldParameter = testTypeConverterHasConvertIfNecessaryWithFieldParameter();
}
@Override
@ -164,14 +163,15 @@ public class PolarisPropertySourceAutoRefresher
LOGGER.info("Auto update polaris changed value successfully, new value: {}, {}", value,
springValue);
} catch (Throwable ex) {
}
catch (Throwable ex) {
LOGGER.error("Auto update polaris changed value failed, {}", springValue.toString(), ex);
}
}
/**
* Logic transplanted from DefaultListableBeanFactory
* Logic transplanted from DefaultListableBeanFactory.
*
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#doResolveDependency(org.springframework.beans.factory.config.DependencyDescriptor,
* java.lang.String, java.util.Set, org.springframework.beans.TypeConverter)
@ -183,16 +183,19 @@ public class PolarisPropertySourceAutoRefresher
if (springValue.isJson()) {
value = parseJsonValue((String) value, springValue.getTargetType());
} else {
}
else {
if (springValue.isField()) {
// org.springframework.beans.TypeConverter#convertIfNecessary(java.lang.Object, java.lang.Class, java.lang.reflect.Field) is available from Spring 3.2.0+
if (typeConverterHasConvertIfNecessaryWithFieldParameter) {
value = this.typeConverter
.convertIfNecessary(value, springValue.getTargetType(), springValue.getField());
} else {
}
else {
value = this.typeConverter.convertIfNecessary(value, springValue.getTargetType());
}
} else {
}
else {
value = this.typeConverter.convertIfNecessary(value, springValue.getTargetType(),
springValue.getMethodParameter());
}
@ -204,7 +207,8 @@ public class PolarisPropertySourceAutoRefresher
private Object parseJsonValue(String json, Class<?> targetType) {
try {
return JacksonUtils.json2JavaBean(json, targetType);
} catch (Throwable ex) {
}
catch (Throwable ex) {
LOGGER.error("Parsing json '{}' to type {} failed!", json, targetType, ex);
throw ex;
}
@ -213,7 +217,8 @@ public class PolarisPropertySourceAutoRefresher
private boolean testTypeConverterHasConvertIfNecessaryWithFieldParameter() {
try {
TypeConverter.class.getMethod("convertIfNecessary", Object.class, Class.class, Field.class);
} catch (Throwable ex) {
}
catch (Throwable ex) {
return false;
}
return true;

@ -54,13 +54,20 @@ public abstract class AbstractPolarisProcessor implements BeanPostProcessor, Pri
return bean;
}
/**
* subclass should implement this method to process field
* subclass should implement this method to process field.
* @param bean bean
* @param beanName beanName
* @param field field
*/
protected abstract void processField(Object bean, String beanName, Field field);
/**
* subclass should implement this method to process method
* subclass should implement this method to process method.
* @param bean bean
* @param beanName beanName
* @param method method
*/
protected abstract void processMethod(Object bean, String beanName, Method method);

@ -111,10 +111,12 @@ public class SpringValueProcessor extends AbstractPolarisProcessor implements Be
if (member instanceof Field) {
Field field = (Field) member;
springValue = new SpringValue(key, value.value(), bean, beanName, field, false);
} else if (member instanceof Method) {
}
else if (member instanceof Method) {
Method method = (Method) member;
springValue = new SpringValue(key, value.value(), bean, beanName, method, false);
} else {
}
else {
logger.error("polaris @Value annotation currently only support to be used on methods and fields, "
+ "but is used on {}", member.getClass());
return;
@ -143,7 +145,8 @@ public class SpringValueProcessor extends AbstractPolarisProcessor implements Be
bean, beanName, method, false);
springValueRegistry.register(beanFactory, definition.getKey(), springValue);
logger.debug("Monitoring {}", springValue);
} catch (Throwable ex) {
}
catch (Throwable ex) {
logger.error("Failed to enable auto update feature for {}.{}", bean.getClass(),
definition.getPropertyName());
}

@ -44,11 +44,13 @@ public class PlaceholderHelper {
private static final String EXPRESSION_PREFIX = "#{";
private static final String EXPRESSION_SUFFIX = "}";
/**
* Resolve placeholder property values, e.g.
* <br />
* <br />
* "${somePropertyValue}" -> "the actual property value"
* @param beanFactory beanFactory
* @param beanName beanName
* @param placeholder placeholder
* @return "${somePropertyValue}" -> "the actual property value"
*/
public Object resolvePropertyValue(ConfigurableBeanFactory beanFactory, String beanName, String placeholder) {
// resolve string value
@ -74,6 +76,8 @@ public class PlaceholderHelper {
/**
* Extract keys from placeholder, e.g.
* @param propertyString propertyString
* @return
* <ul>
* <li>${some.key} => "some.key"</li>
* <li>${some.key:${some.other.key:100}} => "some.key", "some.other.key"</li>
@ -111,13 +115,15 @@ public class PlaceholderHelper {
// ${some.key:other.key}
if (placeholderCandidate.startsWith(PLACEHOLDER_PREFIX)) {
stack.push(placeholderCandidate);
} else {
}
else {
// some.key:${some.other.key:100}
int separatorIndex = placeholderCandidate.indexOf(VALUE_SEPARATOR);
if (separatorIndex == -1) {
stack.push(placeholderCandidate);
} else {
}
else {
stack.push(placeholderCandidate.substring(0, separatorIndex));
String defaultValuePart =
normalizeToPlaceholder(placeholderCandidate.substring(separatorIndex + VALUE_SEPARATOR.length()));
@ -169,13 +175,16 @@ public class PlaceholderHelper {
if (withinNestedPlaceholder > 0) {
withinNestedPlaceholder--;
index = index + PLACEHOLDER_SUFFIX.length();
} else {
}
else {
return index;
}
} else if (StringUtils.substringMatch(buf, index, SIMPLE_PLACEHOLDER_PREFIX)) {
}
else if (StringUtils.substringMatch(buf, index, SIMPLE_PLACEHOLDER_PREFIX)) {
withinNestedPlaceholder++;
index = index + SIMPLE_PLACEHOLDER_PREFIX.length();
} else {
}
else {
index++;
}
}

@ -73,7 +73,8 @@ public class SpringValue {
public void update(Object newVal) throws IllegalAccessException, InvocationTargetException {
if (isField()) {
injectField(newVal);
} else {
}
else {
injectMethod(newVal);
}
}
@ -142,7 +143,8 @@ public class SpringValue {
}
if (isField()) {
return String
.format("key: %s, beanName: %s, field: %s.%s", key, beanName, bean.getClass().getName(), field.getName());
.format("key: %s, beanName: %s, field: %s.%s", key, beanName, bean.getClass()
.getName(), field.getName());
}
return String.format("key: %s, beanName: %s, method: %s.%s", key, beanName, bean.getClass().getName(),
methodParameter.getMethod().getName());

@ -74,13 +74,15 @@ public class SpringValueRegistry {
}
private void initialize() {
Executors.newSingleThreadScheduledExecutor(PolarisThreadFactory.create("SpringValueRegistry", true)).scheduleAtFixedRate(
Executors.newSingleThreadScheduledExecutor(PolarisThreadFactory.create("SpringValueRegistry", true))
.scheduleAtFixedRate(
new Runnable() {
@Override
public void run() {
try {
scanAndClean();
} catch (Throwable ex) {
}
catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
}
}

@ -41,7 +41,8 @@ public class SpringInjector {
if (s_injector == null) {
try {
s_injector = Guice.createInjector(new SpringModule());
} catch (Throwable ex) {
}
catch (Throwable ex) {
PolarisConfigException exception = new PolarisConfigException("Unable to initialize Apollo Spring Injector!", ex);
throw exception;
}
@ -55,7 +56,8 @@ public class SpringInjector {
public static <T> T getInstance(Class<T> clazz) {
try {
return getInjector().getInstance(clazz);
} catch (Throwable ex) {
}
catch (Throwable ex) {
throw new PolarisConfigException(
String.format("Unable to load instance for %s!", clazz.getName()), ex);
}

@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
*@date : 2022/6/28 09:26
*@description:
*/
public class PolarisThreadFactory implements ThreadFactory {
public final class PolarisThreadFactory implements ThreadFactory {
private static Logger log = LoggerFactory.getLogger(PolarisThreadFactory.class);
private final AtomicLong threadNumber = new AtomicLong(1);
@ -53,10 +53,12 @@ public class PolarisThreadFactory implements ThreadFactory {
log.info("Alive polaris threads: {}", alives);
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException ex) {
}
catch (InterruptedException ex) {
// ignore
}
} else {
}
else {
log.info("All polaris threads are shutdown.");
return true;
}
@ -66,9 +68,6 @@ public class PolarisThreadFactory implements ThreadFactory {
return false;
}
private interface ClassifyStandard<T> {
boolean satisfy(T thread);
}
private static <T> void classify(Set<T> src, Set<T> des, ClassifyStandard<T> standard) {
Set<T> set = new HashSet<>();
@ -87,7 +86,7 @@ public class PolarisThreadFactory implements ThreadFactory {
}
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(threadGroup, runnable,//
Thread thread = new Thread(threadGroup, runnable,
threadGroup.getName() + "-" + namePrefix + "-" + threadNumber.getAndIncrement());
thread.setDaemon(daemon);
if (thread.getPriority() != Thread.NORM_PRIORITY) {
@ -95,4 +94,9 @@ public class PolarisThreadFactory implements ThreadFactory {
}
return thread;
}
private interface ClassifyStandard<T> {
boolean satisfy(T thread);
}
}

@ -2,11 +2,11 @@ server:
port: 48084
spring:
application:
name: polaris-config-example
name: xiaozou
cloud:
polaris:
address: grpc://183.47.111.80:8091
namespace: default
namespace: xiaozou
config:
auto-refresh: true # auto refresh when config file changed
groups:

Loading…
Cancel
Save