Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.dubbo.common.utils.ClassLoaderResourceLoader;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.Holder;
Expand Down Expand Up @@ -141,7 +142,7 @@ public class ExtensionLoader<T> {

private static final Map<String, String> specialSPILoadingStrategyMap = getSpecialSPILoadingStrategyMap();

private static SoftReference<Map<java.net.URL, List<String>>> urlListMapCache =
private static SoftReference<ConcurrentHashMap<java.net.URL, List<String>>> urlListMapCache =
new SoftReference<>(new ConcurrentHashMap<>());

private static final List<String> ignoredInjectMethodsDesc = getIgnoredInjectMethodsDesc();
Expand Down Expand Up @@ -1189,7 +1190,7 @@ && isIncluded(clazz, includedPackages)
}

private List<String> getResourceContent(java.net.URL resourceURL) throws IOException {
Map<java.net.URL, List<String>> urlListMap = urlListMapCache.get();
ConcurrentHashMap<java.net.URL, List<String>> urlListMap = urlListMapCache.get();
if (urlListMap == null) {
synchronized (ExtensionLoader.class) {
if ((urlListMap = urlListMapCache.get()) == null) {
Expand All @@ -1199,7 +1200,7 @@ private List<String> getResourceContent(java.net.URL resourceURL) throws IOExcep
}
}

List<String> contentList = urlListMap.computeIfAbsent(resourceURL, key -> {
List<String> contentList = ConcurrentHashMapUtils.computeIfAbsent(urlListMap, resourceURL, key -> {
List<String> newContentList = new ArrayList<>();

try (BufferedReader reader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
*/
package org.apache.dubbo.common.serialization;

import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class ClassHolder {
private final Map<String, Set<Class<?>>> classCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Set<Class<?>>> classCache = new ConcurrentHashMap<>();

public void storeClass(Class<?> clazz) {
classCache
.computeIfAbsent(clazz.getName(), k -> new ConcurrentHashSet<>())
ConcurrentHashMapUtils.computeIfAbsent(classCache, clazz.getName(), k -> new ConcurrentHashSet<>())
.add(clazz);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ private static Field getAndCacheField(Class<?> cls, String fieldName) {

if (result != null) {
ConcurrentMap<String, Field> fields =
CLASS_FIELD_CACHE.computeIfAbsent(cls, k -> new ConcurrentHashMap<>());
ConcurrentHashMapUtils.computeIfAbsent(CLASS_FIELD_CACHE, cls, k -> new ConcurrentHashMap<>());
fields.putIfAbsent(fieldName, result);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ public static <T> T computeServiceAttribute(URL url, String key, Function<URL, T
return Optional.ofNullable(url.getServiceModel())
.map(ServiceModel::getServiceMetadata)
.map(ServiceMetadata::getAttributeMap)
.map(stringObjectMap -> (T) stringObjectMap.computeIfAbsent(key, k -> fn.apply(url)))
.map(stringObjectMap ->
(T) ConcurrentHashMapUtils.computeIfAbsent(stringObjectMap, key, k -> fn.apply(url)))
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
Expand Down Expand Up @@ -73,9 +74,9 @@ public abstract class AbstractConfigManager extends LifecycleAdapter {
LoggerFactory.getErrorTypeAwareLogger(AbstractConfigManager.class);
private static final Set<Class<? extends AbstractConfig>> uniqueConfigTypes = new ConcurrentHashSet<>();

final Map<String, Map<String, AbstractConfig>> configsCache = new ConcurrentHashMap<>();
final ConcurrentHashMap<String, Map<String, AbstractConfig>> configsCache = new ConcurrentHashMap<>();

private final Map<String, AtomicInteger> configIdIndexes = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, AtomicInteger> configIdIndexes = new ConcurrentHashMap<>();

protected Set<AbstractConfig> duplicatedConfigs = new ConcurrentHashSet<>();

Expand Down Expand Up @@ -163,8 +164,8 @@ public final <T extends AbstractConfig> T addConfig(AbstractConfig config) {

Class<? extends AbstractConfig> targetConfigType = getTargetConfigType(config.getClass());

Map<String, AbstractConfig> configsMap =
configsCache.computeIfAbsent(getTagName(targetConfigType), type -> new ConcurrentHashMap<>());
Map<String, AbstractConfig> configsMap = ConcurrentHashMapUtils.computeIfAbsent(
configsCache, getTagName(targetConfigType), type -> new ConcurrentHashMap<>());

// fast check duplicated equivalent config before write lock
if (!(config instanceof ReferenceConfigBase || config instanceof ServiceConfigBase)) {
Expand Down Expand Up @@ -408,8 +409,7 @@ protected boolean isEquals(AbstractConfig oldOne, AbstractConfig newOne) {

protected <C extends AbstractConfig> String generateConfigId(C config) {
String tagName = getTagName(config.getClass());
int idx = configIdIndexes
.computeIfAbsent(tagName, clazz -> new AtomicInteger(0))
int idx = ConcurrentHashMapUtils.computeIfAbsent(configIdIndexes, tagName, clazz -> new AtomicInteger(0))
.incrementAndGet();
return tagName + "#" + idx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ServiceMetadata extends BaseServiceMetadata {
/**
* used locally
*/
private final Map<String, Object> attributeMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Object> attributeMap = new ConcurrentHashMap<>();

public ServiceMetadata(String serviceInterfaceName, String group, String version, Class<?> serviceType) {
this.serviceInterfaceName = serviceInterfaceName;
Expand All @@ -63,7 +63,7 @@ public Map<String, Object> getAttachments() {
return attachments;
}

public Map<String, Object> getAttributeMap() {
public ConcurrentHashMap<String, Object> getAttributeMap() {
return attributeMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.ClassUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
Expand Down Expand Up @@ -158,7 +159,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
/**
* The exported services
*/
private final Map<RegisterTypeEnum, List<Exporter<?>>> exporters = new ConcurrentHashMap<>();
private final ConcurrentHashMap<RegisterTypeEnum, List<Exporter<?>>> exporters = new ConcurrentHashMap<>();

private final List<ServiceListener> serviceListeners = new ArrayList<>();

Expand Down Expand Up @@ -969,8 +970,7 @@ private void doExportUrl(URL url, boolean withMetaData, RegisterTypeEnum registe
invoker = new DelegateProviderMetaDataInvoker(invoker, this);
}
Exporter<?> exporter = protocolSPI.export(invoker);
exporters
.computeIfAbsent(registerType, k -> new CopyOnWriteArrayList<>())
ConcurrentHashMapUtils.computeIfAbsent(exporters, registerType, k -> new CopyOnWriteArrayList<>())
.add(exporter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.SystemPropertyConfigUtils;
import org.apache.dubbo.metrics.config.event.ConfigCenterEvent;
Expand Down Expand Up @@ -167,7 +168,8 @@ private String getAddressWithProtocolPrefix(URL url) {
*/
@Override
public void addListener(String key, String group, ConfigurationListener listener) {
ApolloListener apolloListener = listeners.computeIfAbsent(group + key, k -> createTargetListener(key, group));
ApolloListener apolloListener =
ConcurrentHashMapUtils.computeIfAbsent(listeners, group + key, k -> createTargetListener(key, group));
apolloListener.addListener(listener);
dubboConfig.addChangeListener(apolloListener, Collections.singleton(key));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
Expand All @@ -50,7 +50,7 @@ public abstract class AbstractServiceNameMapping implements ServiceNameMapping {
protected final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(getClass());
protected ApplicationModel applicationModel;
private final MappingCacheManager mappingCacheManager;
private final Map<String, Set<MappingListener>> mappingListeners = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Set<MappingListener>> mappingListeners = new ConcurrentHashMap<>();
// mapping lock is shared among registries of the same application.
private final ConcurrentMap<String, ReentrantLock> mappingLocks = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -198,7 +198,7 @@ public Set<String> removeCachedMapping(String serviceKey) {
}

public Lock getMappingLock(String key) {
return mappingLocks.computeIfAbsent(key, _k -> new ReentrantLock());
return ConcurrentHashMapUtils.computeIfAbsent(mappingLocks, key, _k -> new ReentrantLock());
}

protected void removeMappingLock(String key) {
Expand Down Expand Up @@ -239,8 +239,8 @@ public Set<String> call() throws Exception {
String mappingKey = ServiceNameMapping.buildMappingKey(subscribedURL);
if (listener != null) {
mappedServices = toTreeSet(getAndListen(subscribedURL, listener));
Set<MappingListener> listeners =
mappingListeners.computeIfAbsent(mappingKey, _k -> new HashSet<>());
Set<MappingListener> listeners = ConcurrentHashMapUtils.computeIfAbsent(
mappingListeners, mappingKey, _k -> new HashSet<>());
listeners.add(listener);
if (CollectionUtils.isNotEmpty(mappedServices)) {
if (notifyAtFirstTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.dubbo.common.config.configcenter.ConfigItem;
import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.MD5Utils;
import org.apache.dubbo.common.utils.StringUtils;
Expand Down Expand Up @@ -79,9 +80,9 @@ public class NacosMetadataReport extends AbstractMetadataReport {
*/
private String group;

private Map<String, NacosConfigListener> watchListenerMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, NacosConfigListener> watchListenerMap = new ConcurrentHashMap<>();

private Map<String, MappingDataListener> casListenerMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, MappingDataListener> casListenerMap = new ConcurrentHashMap<>();

private MD5Utils md5Utils = new MD5Utils();

Expand Down Expand Up @@ -336,8 +337,8 @@ private String getConfig(String dataId, String group) {
}

private void addCasServiceMappingListener(String serviceKey, String group, MappingListener listener) {
MappingDataListener mappingDataListener = casListenerMap.computeIfAbsent(
buildListenerKey(serviceKey, group), k -> new MappingDataListener(serviceKey, group));
MappingDataListener mappingDataListener = ConcurrentHashMapUtils.computeIfAbsent(
casListenerMap, buildListenerKey(serviceKey, group), k -> new MappingDataListener(serviceKey, group));
mappingDataListener.addListeners(listener);
addListener(serviceKey, DEFAULT_MAPPING_GROUP, mappingDataListener);
}
Expand All @@ -355,8 +356,8 @@ private void removeCasServiceMappingListener(String serviceKey, String group, Ma

public void addListener(String key, String group, ConfigurationListener listener) {
String listenerKey = buildListenerKey(key, group);
NacosConfigListener nacosConfigListener =
watchListenerMap.computeIfAbsent(listenerKey, k -> createTargetListener(key, group));
NacosConfigListener nacosConfigListener = ConcurrentHashMapUtils.computeIfAbsent(
watchListenerMap, listenerKey, k -> createTargetListener(key, group));
nacosConfigListener.addListener(listener);
try {
configService.addListener(key, group, nacosConfigListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.metrics.data;

import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.metrics.exception.MetricsNeverHappenException;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.metrics.model.MetricsCategory;
Expand Down Expand Up @@ -48,7 +49,8 @@ public MethodStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
}

private final Map<MetricsKeyWrapper, Map<MethodMetric, AtomicLong>> methodNumStats = new ConcurrentHashMap<>();
private final ConcurrentHashMap<MetricsKeyWrapper, ConcurrentHashMap<MethodMetric, AtomicLong>> methodNumStats =
new ConcurrentHashMap<>();

public void initWrapper(List<MetricsKeyWrapper> metricsKeyWrappers) {
if (CollectionUtils.isEmpty(metricsKeyWrappers)) {
Expand All @@ -65,11 +67,10 @@ public void initMethodKey(MetricsKeyWrapper wrapper, Invocation invocation) {
return;
}

methodNumStats
.get(wrapper)
.computeIfAbsent(
new MethodMetric(getApplicationModel(), invocation, getServiceLevel()),
k -> new AtomicLong(0L));
ConcurrentHashMapUtils.computeIfAbsent(
methodNumStats.get(wrapper),
new MethodMetric(getApplicationModel(), invocation, getServiceLevel()),
k -> new AtomicLong(0L));
samplesChanged.set(true);
}

Expand All @@ -79,7 +80,8 @@ public void incrementMethodKey(MetricsKeyWrapper wrapper, MethodMetric methodMet
}
AtomicLong stat = methodNumStats.get(wrapper).get(methodMetric);
if (stat == null) {
methodNumStats.get(wrapper).computeIfAbsent(methodMetric, (k) -> new AtomicLong(0L));
ConcurrentHashMapUtils.computeIfAbsent(
methodNumStats.get(wrapper), methodMetric, (k) -> new AtomicLong(0L));
samplesChanged.set(true);
stat = methodNumStats.get(wrapper).get(methodMetric);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metrics.data;

import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.metrics.model.Metric;
import org.apache.dubbo.metrics.model.MetricsCategory;
Expand Down Expand Up @@ -57,7 +58,7 @@ public RtStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
}

private final Map<String, List<LongContainer<? extends Number>>> rtStats = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, List<LongContainer<? extends Number>>> rtStats = new ConcurrentHashMap<>();

public void init(MetricsPlaceValue... placeValues) {
if (placeValues == null) {
Expand All @@ -66,7 +67,8 @@ public void init(MetricsPlaceValue... placeValues) {
for (MetricsPlaceValue placeValue : placeValues) {
List<LongContainer<? extends Number>> containers = initStats(placeValue);
for (LongContainer<? extends Number> container : containers) {
rtStats.computeIfAbsent(container.getMetricsKeyWrapper().getType(), k -> new ArrayList<>())
ConcurrentHashMapUtils.computeIfAbsent(
rtStats, container.getMetricsKeyWrapper().getType(), k -> new ArrayList<>())
.add(container);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.metrics.data;

import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.metrics.model.MetricsCategory;
import org.apache.dubbo.metrics.model.ServiceKeyMetric;
import org.apache.dubbo.metrics.model.key.MetricsKeyWrapper;
Expand Down Expand Up @@ -45,8 +46,8 @@ public ServiceStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
}

private final Map<MetricsKeyWrapper, Map<ServiceKeyMetric, AtomicLong>> serviceWrapperNumStats =
new ConcurrentHashMap<>();
private final ConcurrentHashMap<MetricsKeyWrapper, ConcurrentHashMap<ServiceKeyMetric, AtomicLong>>
serviceWrapperNumStats = new ConcurrentHashMap<>();

public void initWrapper(List<MetricsKeyWrapper> metricsKeyWrappers) {
if (CollectionUtils.isEmpty(metricsKeyWrappers)) {
Expand All @@ -71,10 +72,10 @@ public void incrementExtraServiceKey(
if (extra != null) {
serviceKeyMetric.setExtraInfo(extra);
}
Map<ServiceKeyMetric, AtomicLong> map = serviceWrapperNumStats.get(wrapper);
ConcurrentHashMap<ServiceKeyMetric, AtomicLong> map = serviceWrapperNumStats.get(wrapper);
AtomicLong metrics = map.get(serviceKeyMetric);
if (metrics == null) {
metrics = map.computeIfAbsent(serviceKeyMetric, k -> new AtomicLong(0L));
metrics = ConcurrentHashMapUtils.computeIfAbsent(map, serviceKeyMetric, k -> new AtomicLong(0L));
samplesChanged.set(true);
}
metrics.getAndAdd(size);
Expand All @@ -93,10 +94,10 @@ public void setExtraServiceKey(MetricsKeyWrapper wrapper, String serviceKey, int
if (extra != null) {
serviceKeyMetric.setExtraInfo(extra);
}
Map<ServiceKeyMetric, AtomicLong> stats = serviceWrapperNumStats.get(wrapper);
ConcurrentHashMap<ServiceKeyMetric, AtomicLong> stats = serviceWrapperNumStats.get(wrapper);
AtomicLong metrics = stats.get(serviceKeyMetric);
if (metrics == null) {
metrics = stats.computeIfAbsent(serviceKeyMetric, k -> new AtomicLong(0L));
metrics = ConcurrentHashMapUtils.computeIfAbsent(stats, serviceKeyMetric, k -> new AtomicLong(0L));
samplesChanged.set(true);
}
metrics.set(num);
Expand Down
Loading
Loading