Browse Source

REPORT-114391 【微服务适配】远程&本地设计器能够正常启动 移动memconfig

mss/2.0
Destiny.Lin 6 months ago
parent
commit
c713d09675
  1. 90
      designer-realize/src/main/java/com/fanruan/boot/mem/MemConfigRepository.java
  2. 20
      designer-realize/src/main/java/com/fanruan/boot/mem/MemConfigRepositoryBuilder.java
  3. 4
      designer-realize/src/main/java/com/fanruan/boot/pre/DesignConfigComponent.java

90
designer-realize/src/main/java/com/fanruan/boot/mem/MemConfigRepository.java

@ -0,0 +1,90 @@
package com.fanruan.boot.mem;
import com.fanruan.config.event.ConfigListener;
import com.fanruan.config.realm.ConfigRepositoryProvider;
import com.fr.log.FineLoggerFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* MemConfigRealm
*
* @author rinoux
* created on 2023-06-08
*/
public class MemConfigRepository implements ConfigRepositoryProvider {
private final String namespace;
private final Map<String, Map<String, String>> configValueMap = new ConcurrentHashMap<>();
private final Map<String, Set<ConfigListener>> configListenerMap = new ConcurrentHashMap<>();
public MemConfigRepository(String namespace) {
this.namespace = namespace;
}
@Override
public String namespace() {
return namespace;
}
@Override
public String get(String configID, String configItem, String group, boolean cache) throws Exception {
return configValueMap.computeIfAbsent(configID, k -> new ConcurrentHashMap<>()).get(configItem);
}
@Override
public void set(String configID, String configItem, String value, String group) throws Exception {
configValueMap.computeIfAbsent(configID, k -> new ConcurrentHashMap<>()).put(configItem, value);
triggerConfigChange(configID);
}
@Override
public void remove(String configID, String group) {
configValueMap.remove(configID);
triggerConfigChange(configID);
}
@Override
public void removeKey(String configID, String key, String group) {
Map<String, String> configItemMap = configValueMap.get(configID);
if (configItemMap!= null) {
configItemMap.remove(key);
}
triggerConfigChange(configID);
}
@Override
public void watch(String configID, String item, String group, ConfigListener configListener) {
Set<ConfigListener> configListeners = configListenerMap.computeIfAbsent(configID, k -> Collections.synchronizedSet(new HashSet<>()));
configListeners.add(configListener);
}
@Override
public void unWatch(String configID, String item, String group, ConfigListener configListener) {
Set<ConfigListener> configListeners = configListenerMap.get(configID);
if (configListeners != null) {
configListeners.remove(configListener);
}
}
private void triggerConfigChange(String configID) {
Set<ConfigListener> configListeners = configListenerMap.get(configID);
if (configListeners != null) {
List<ConfigListener> configListenerList = new ArrayList<>(configListeners);
for (ConfigListener configListener : configListenerList) {
try {
configListener.onConfigChange();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}
}
}

20
designer-realize/src/main/java/com/fanruan/boot/mem/MemConfigRepositoryBuilder.java

@ -0,0 +1,20 @@
package com.fanruan.boot.mem;
import com.fanruan.config.realm.ConfigRepositoryBuilder;
import com.fanruan.config.realm.ConfigRepositoryProvider;
/**
* 设计器MemConfigRepositoryBuilder
*
* @author Destiny.Lin
* @since 11.0
* Created on 2024/5/29
*/
public class MemConfigRepositoryBuilder implements ConfigRepositoryBuilder {
@Override
public ConfigRepositoryProvider build(String namespace) throws Exception {
return new MemConfigRepository(namespace);
}
}

4
designer-realize/src/main/java/com/fanruan/boot/pre/DesignConfigComponent.java

@ -7,10 +7,10 @@ import com.fanruan.config.impl.PublicConfigProviderImpl;
import com.fanruan.config.impl.ShareConfigProviderImpl;
import com.fanruan.config.realm.ConfigRealm;
import com.fanruan.config.realm.ConfigRepositoryFactory;
import com.fanruan.config.realm.mem.MemConfigRepositoryBuilder;
import com.fanruan.boot.mem.MemConfigRepositoryBuilder;
/**
* 类解释注释
* 设计器configprovider注册
*
* @author Destiny.Lin
* @since 11.0

Loading…
Cancel
Save