This is an automated email from the ASF dual-hosted git repository. wujimin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push: new 0754bf3 [SCB-2253] reduce invoke setter when configuration changed for @InjectProperties 0754bf3 is described below commit 0754bf339e6ffc9840ea7a18ff3ac1fd28fe31d8 Author: wujimin <wuji...@huawei.com> AuthorDate: Tue Apr 6 08:56:31 2021 +0800 [SCB-2253] reduce invoke setter when configuration changed for @InjectProperties --- .../core/exception/DefaultExceptionProcessor.java | 3 +++ .../servicecomb/config/priority/ConfigObjectProperty.java | 8 ++++++-- .../servicecomb/config/priority/PriorityProperty.java | 15 +++++++++++++++ .../config/priority/PriorityPropertyManager.java | 6 ++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java index 724e8b0..e18f5e8 100644 --- a/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java +++ b/core/src/main/java/org/apache/servicecomb/core/exception/DefaultExceptionProcessor.java @@ -48,6 +48,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.annotation.JsonIgnore; + @Component @InjectProperties(prefix = "servicecomb.invocation.exception") public class DefaultExceptionProcessor implements ExceptionProcessor { @@ -55,6 +57,7 @@ public class DefaultExceptionProcessor implements ExceptionProcessor { public static final int ORDER = Integer.MAX_VALUE; + @JsonIgnore @SuppressWarnings("unchecked") private final List<ExceptionConverter<Throwable>> converters = SPIServiceUtils .getOrLoadSortedService(ExceptionConverter.class).stream() diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java index 7231999..e81465b 100644 --- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java +++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectProperty.java @@ -17,6 +17,8 @@ package org.apache.servicecomb.config.priority; +import javax.annotation.Nullable; + import org.apache.servicecomb.foundation.common.utils.bean.Setter; /** @@ -32,7 +34,9 @@ public class ConfigObjectProperty { this.property = property; } - public void updateValue(Object instance) { - setter.set(instance, property.getValue()); + public void updateValueWhenChanged(Object instance, @Nullable String changedKey) { + if (property.isChangedKey(changedKey)) { + setter.set(instance, property.getValue()); + } } } diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java index faad071..3af93c8 100644 --- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java +++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityProperty.java @@ -180,4 +180,19 @@ public class PriorityProperty<T> { public T getValue() { return finalValue; } + + public boolean isChangedKey(String changedKey) { + if (changedKey == null) { + // property source changed or clear, and so on + return true; + } + + for (DynamicProperty property : properties) { + if (changedKey.equals(property.getName())) { + return true; + } + } + + return false; + } } diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java index 7cf6eaf..15a1b5b 100644 --- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java +++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java @@ -63,10 +63,12 @@ public class PriorityPropertyManager { return; } - // just update all properties, it's very fast, no need to do any optimize + // just loop all properties, it's very fast, no need to do any optimize for (Entry<Object, List<ConfigObjectProperty>> entry : configObjectMap.entrySet()) { Object instance = entry.getKey(); - entry.getValue().forEach(configObjectProperty -> configObjectProperty.updateValue(instance)); + entry.getValue() + .forEach( + configObjectProperty -> configObjectProperty.updateValueWhenChanged(instance, event.getPropertyName())); } }