Skip to content

Commit

Permalink
add cache for scan result. (#8049)
Browse files Browse the repository at this point in the history
* add cache for scan result. (#7477)

* remove unused method and delete Unused import. (#8049)

* delete checkCandidate method.

* Please remove redundant comments.

Co-authored-by: zhang.jie <zhangjie@rivamed.cn>
  • Loading branch information
zhangjiezhang and zhang.jie committed Jun 21, 2021
1 parent f004643 commit 96680dd
Showing 1 changed file with 16 additions and 9 deletions.
Expand Up @@ -17,13 +17,15 @@
package org.apache.dubbo.config.spring.context.annotation;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;

import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors;

Expand All @@ -36,6 +38,11 @@
*/
public class DubboClassPathBeanDefinitionScanner extends ClassPathBeanDefinitionScanner {

/**
* key is package to scan, value is BeanDefinition
*/
private final ConcurrentMap<String, Set<BeanDefinition>> beanDefinitionMap = new ConcurrentHashMap<>();


public DubboClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment,
ResourceLoader resourceLoader) {
Expand All @@ -58,13 +65,13 @@ public DubboClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, Envi
}

@Override
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
return super.doScan(basePackages);
public Set<BeanDefinition> findCandidateComponents(String basePackage) {
Set<BeanDefinition> beanDefinitions = beanDefinitionMap.get(basePackage);
// if beanDefinitions size is null => scan
if (Objects.isNull(beanDefinitions)) {
beanDefinitions = super.findCandidateComponents(basePackage);
beanDefinitionMap.put(basePackage, beanDefinitions);
}
return beanDefinitions;
}

@Override
public boolean checkCandidate(String beanName, BeanDefinition beanDefinition) throws IllegalStateException {
return super.checkCandidate(beanName, beanDefinition);
}

}

0 comments on commit 96680dd

Please sign in to comment.