funky-eyes commented on code in PR #6420:
URL: https://github.com/apache/incubator-seata/pull/6420#discussion_r1527183731
##########
config/seata-config-core/src/test/java/org/apache/seata/config/FileConfigurationTest.java:
##########
@@ -41,13 +41,17 @@ void addConfigListener() throws InterruptedException {
Configuration fileConfig = ConfigurationFactory.getInstance();
CountDownLatch countDownLatch = new CountDownLatch(1);
boolean value =
fileConfig.getBoolean("service.disableGlobalTransaction");
-
ConfigurationCache.addConfigListener("service.disableGlobalTransaction",
(event) -> {
- Assertions.assertEquals(Boolean.parseBoolean(event.getNewValue()),
!Boolean.parseBoolean(event.getOldValue()));
- countDownLatch.countDown();
+ fileConfig.addConfigListener("service.disableGlobalTransaction", new
CachedConfigurationChangeListener() {
+ @Override
+ public void onChangeEvent(ConfigurationChangeEvent event) {
+
Assertions.assertEquals(Boolean.parseBoolean(event.getNewValue()),
!Boolean.parseBoolean(event.getOldValue()));
+ countDownLatch.countDown();
+ }
});
System.setProperty("service.disableGlobalTransaction",
String.valueOf(!value));
countDownLatch.await(5, TimeUnit.SECONDS);
System.setProperty("file.listener.enabled", "false");
+ Thread.sleep(1000);
Review Comment:
Why sleep for 1 second?
##########
config/seata-config-etcd3/src/main/java/org/apache/seata/config/etcd3/EtcdConfiguration.java:
##########
@@ -394,7 +394,7 @@ public void onNext(WatchResponse watchResponse) {
List<KeyValue> keyValues = getResponse.getKvs();
if (CollectionUtils.isNotEmpty(keyValues)) {
event.setDataId(dataId).setNewValue(keyValues.get(0).getValue().toString(UTF_8));
- listener.onChangeEvent(event);
+ listener.onProcessEvent(event);
Review Comment:
I'm worried that the user's extended implementation doesn't call
onProcessEvent this way.
我担心用户的扩展实现里并不会这样去调用onProcessEvent
##########
config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java:
##########
@@ -90,12 +53,10 @@ public void onChangeEvent(ConfigurationChangeEvent event) {
CONFIG_CACHE.put(event.getDataId(), new
ObjectWrapper(event.getNewValue(), null));
} else {
Object newValue = new ObjectWrapper(event.getNewValue(),
null).convertData(oldWrapper.getType());
- if (!Objects.equals(oldWrapper.getData(), newValue)) {
- CONFIG_CACHE.put(event.getDataId(), new
ObjectWrapper(newValue, oldWrapper.getType(),oldWrapper.getLastDefaultValue()));
- }
+ CONFIG_CACHE.replace(event.getDataId(), oldWrapper, new
ObjectWrapper(newValue, oldWrapper.getType(),
oldWrapper.getLastDefaultValue()));
Review Comment:
If the value remains unchanged, it will result in a meaningless replace.
##########
config/seata-config-core/src/main/java/org/apache/seata/config/CachedConfigurationChangeListener.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * 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.seata.config;
+
+public interface CachedConfigurationChangeListener extends
ConfigurationChangeListener {
+
+ ConfigurationCache CONFIGURATION_CACHE = ConfigurationCache.getInstance();
+
+ @Override
+ default void afterEvent(ConfigurationChangeEvent event) {
+ ConfigurationChangeListener listener =
(ConfigurationChangeListener)CONFIGURATION_CACHE;
+ listener.onProcessEvent(event);
Review Comment:
```suggestion
ConfigurationChangeListener afterListener =
ConfigurationCache.getInstance();
@Override
default void afterEvent(ConfigurationChangeEvent event) {
afterListener.onProcessEvent(event);
```
这样写是不是更加合适?
Is it more appropriate to write this way?
##########
config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java:
##########
@@ -115,6 +76,9 @@ public Configuration proxy(Configuration
originalConfiguration) throws Exception
}
if (null == wrapper
|| (null != defaultValue &&
!Objects.equals(defaultValue, wrapper.lastDefaultValue))) {
+ if (DATA_ID_CACHED.add(rawDataId)) {
+ originalConfiguration.addConfigListener(rawDataId,
this);
Review Comment:
Why do need to listen on every key?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]