Skip to content

Commit

Permalink
fix #1380
Browse files Browse the repository at this point in the history
  • Loading branch information
呈铭 committed Mar 4, 2024
1 parent 2d3120e commit df66482
Showing 1 changed file with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import static com.alipay.sofa.rpc.common.utils.StringUtils.CONTEXT_SEP;

Expand Down Expand Up @@ -103,8 +101,6 @@ public class NacosRegistry extends Registry {

private Properties nacosConfig = new Properties();

private static final Lock lock = new ReentrantLock();

/**
* Instantiates a new Nacos registry.
*
Expand Down Expand Up @@ -149,7 +145,6 @@ public synchronized void init() {
nacosConfig.putAll(parameters);
}

lock.lock();
try {
if (providerObserver == null) {
providerObserver = new NacosRegistryProviderObserver();
Expand All @@ -158,8 +153,6 @@ public synchronized void init() {
namingService = NamingFactory.createNamingService(nacosConfig);
} catch (NacosException e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_INIT_NACOS_NAMING_SERVICE, address), e);
} finally {
lock.unlock();
}
}

Expand Down Expand Up @@ -283,12 +276,7 @@ public List<ProviderGroup> subscribe(final ConsumerConfig config) {

try {
ProviderInfoListener providerInfoListener = config.getProviderInfoListener();
try {
lock.lock();
providerObserver.addProviderListener(config, providerInfoListener);
} finally {
lock.unlock();
}
providerObserver.addProviderListener(config, providerInfoListener);

EventListener eventListener = event -> {
if (event instanceof NamingEvent) {
Expand All @@ -299,12 +287,7 @@ public List<ProviderGroup> subscribe(final ConsumerConfig config) {
instances = new ArrayList<>();
}
instances.removeIf(i -> !i.isEnabled());
try {
lock.lock();
providerObserver.updateProviders(config, instances);
} finally {
lock.unlock();
}
providerObserver.updateProviders(config, instances);
}
};
namingService.subscribe(serviceName, defaultCluster, eventListener);
Expand Down Expand Up @@ -345,12 +328,7 @@ public void unSubscribe(ConsumerConfig config) {
}
}
}
try {
lock.lock();
providerObserver.removeProviderListener(config);
} finally {
lock.unlock();
}
providerObserver.removeProviderListener(config);
}
}

Expand Down

0 comments on commit df66482

Please sign in to comment.