Skip to content

Commit

Permalink
Support concurrent loading of Config for different namespaces (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zth9 committed Aug 11, 2023
1 parent 265fe49 commit f351a6a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class DefaultConfigManager implements ConfigManager {
private ConfigFactoryManager m_factoryManager;

private Map<String, Config> m_configs = Maps.newConcurrentMap();
private Map<String, Object> m_configLocks = Maps.newConcurrentMap();
private Map<String, ConfigFile> m_configFiles = Maps.newConcurrentMap();
private Map<String, Object> m_configFileLocks = Maps.newConcurrentMap();

public DefaultConfigManager() {
m_factoryManager = ApolloInjector.getInstance(ConfigFactoryManager.class);
Expand All @@ -44,7 +46,8 @@ public Config getConfig(String namespace) {
Config config = m_configs.get(namespace);

if (config == null) {
synchronized (this) {
Object lock = m_configLocks.computeIfAbsent(namespace, key -> new Object());
synchronized (lock) {
config = m_configs.get(namespace);

if (config == null) {
Expand All @@ -65,7 +68,8 @@ public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFor
ConfigFile configFile = m_configFiles.get(namespaceFileName);

if (configFile == null) {
synchronized (this) {
Object lock = m_configFileLocks.computeIfAbsent(namespaceFileName, key -> new Object());
synchronized (lock) {
configFile = m_configFiles.get(namespaceFileName);

if (configFile == null) {
Expand Down

0 comments on commit f351a6a

Please sign in to comment.