|
48 | 48 | import java.util.List; |
49 | 49 | import java.util.Map; |
50 | 50 | import java.util.concurrent.ConcurrentHashMap; |
| 51 | +import java.util.concurrent.ConcurrentMap; |
51 | 52 | import java.util.concurrent.ExecutorService; |
52 | 53 |
|
53 | 54 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
@@ -99,7 +100,7 @@ public class RegistryProtocol implements Protocol { |
99 | 100 | private final ProviderConfigurationListener providerConfigurationListener = new ProviderConfigurationListener(); |
100 | 101 | //To solve the problem of RMI repeated exposure port conflicts, the services that have been exposed are no longer exposed. |
101 | 102 | //providerurl <--> exporter |
102 | | - private final Map<String, ExporterChangeableWrapper<?>> bounds = new ConcurrentHashMap<>(); |
| 103 | + private final ConcurrentMap<String, ExporterChangeableWrapper<?>> bounds = new ConcurrentHashMap<>(); |
103 | 104 | private Cluster cluster; |
104 | 105 | private Protocol protocol; |
105 | 106 | private RegistryFactory registryFactory; |
@@ -212,19 +213,11 @@ private URL overrideUrlWithConfig(URL providerUrl, OverrideListener listener) { |
212 | 213 | @SuppressWarnings("unchecked") |
213 | 214 | private <T> ExporterChangeableWrapper<T> doLocalExport(final Invoker<T> originInvoker, URL providerUrl) { |
214 | 215 | String key = getCacheKey(originInvoker); |
215 | | - ExporterChangeableWrapper<T> exporter = (ExporterChangeableWrapper<T>) bounds.get(key); |
216 | | - if (exporter == null) { |
217 | | - synchronized (bounds) { |
218 | | - exporter = (ExporterChangeableWrapper<T>) bounds.get(key); |
219 | | - if (exporter == null) { |
220 | 216 |
|
221 | | - final Invoker<?> invokerDelegete = new InvokerDelegate<T>(originInvoker, providerUrl); |
222 | | - exporter = new ExporterChangeableWrapper<T>((Exporter<T>) protocol.export(invokerDelegete), originInvoker); |
223 | | - bounds.put(key, exporter); |
224 | | - } |
225 | | - } |
226 | | - } |
227 | | - return exporter; |
| 217 | + return (ExporterChangeableWrapper<T>) bounds.computeIfAbsent(key, s -> { |
| 218 | + Invoker<?> invokerDelegete = new InvokerDelegate<>(originInvoker, providerUrl); |
| 219 | + return new ExporterChangeableWrapper<>((Exporter<T>) protocol.export(invokerDelegete), originInvoker); |
| 220 | + }); |
228 | 221 | } |
229 | 222 |
|
230 | 223 | public <T> void reExport(final Invoker<T> originInvoker, URL newInvokerUrl) { |
|
0 commit comments