Skip to content

Commit

Permalink
1. skip low cost spring.context.config-classes.enhance and bean-factory
Browse files Browse the repository at this point in the history
sofastack#1270

2. Support ExcludeBeanNameAutoProxyCreator sofastack#1277
3. avoid ReadinessCheckListener cuncrrency
  • Loading branch information
HzjNeverStop authored and 致节 committed Jan 23, 2024
1 parent 0d8f249 commit 0319b6d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<description>SOFABoot Build</description>

<properties>
<revision>3.21.0</revision>
<revision>3.22.0-SNAPSHOT</revision>
<sofa.boot.version>${revision}</sofa.boot.version>
<!--maven plugin-->
<maven.staging.plugin>1.6.7</maven.staging.plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -71,11 +72,11 @@ public class ReadinessCheckListener implements ApplicationContextAware, Ordered,

private boolean healthCheckerStatus = true;

private Map<String, Health> healthCheckerDetails = new HashMap<>();
private Map<String, Health> healthCheckerDetails = new ConcurrentHashMap<>();

private boolean healthIndicatorStatus = true;

private Map<String, Health> healthIndicatorDetails = new HashMap<>();
private Map<String, Health> healthIndicatorDetails = new ConcurrentHashMap<>();

private boolean healthCallbackStatus = true;
private boolean readinessCheckFinish = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,23 @@ public class StartupReporter {

public static final String SPRING_CONTEXT_BEAN_FACTORY_POST_PROCESSOR = "spring.context.bean-factory.post-process";

public static final String SPRING_BEAN_POST_PROCESSOR = "spring.context.beans.post-process";

public static final String SPRING_CONFIG_CLASSES_ENHANCE = "spring.context.config-classes.enhance";

public static final Collection<String> SPRING_BEAN_INSTANTIATE_TYPES = new HashSet<>();

public static final Collection<String> SPRING_CONTEXT_POST_PROCESSOR_TYPES = new HashSet<>();

public static final Collection<String> SPRING_CONFIG_CLASSES_ENHANCE_TYPES = new HashSet<>();

static {
SPRING_BEAN_INSTANTIATE_TYPES.add(SPRING_BEANS_INSTANTIATE);
SPRING_BEAN_INSTANTIATE_TYPES.add(SPRING_BEANS_SMART_INSTANTIATE);
SPRING_CONTEXT_POST_PROCESSOR_TYPES.add(SPRING_CONTEXT_BEANDEF_REGISTRY_POST_PROCESSOR);
SPRING_CONTEXT_POST_PROCESSOR_TYPES.add(SPRING_CONTEXT_BEAN_FACTORY_POST_PROCESSOR);
SPRING_CONFIG_CLASSES_ENHANCE_TYPES.add(SPRING_CONFIG_CLASSES_ENHANCE);
SPRING_CONFIG_CLASSES_ENHANCE_TYPES.add(SPRING_BEAN_POST_PROCESSOR);
}

private final StartupStaticsModel startupStaticsModel = new StartupStaticsModel();
Expand Down Expand Up @@ -175,7 +183,9 @@ public List<BeanStat> generateBeanStats(ConfigurableApplicationContext context)

private boolean filterBeanInitializeByCost(BeanStat beanStat) {
String name = beanStat.getBeanType();
if (SPRING_BEAN_INSTANTIATE_TYPES.contains(name)) {
if (SPRING_BEAN_INSTANTIATE_TYPES.contains(name)
|| SPRING_CONTEXT_POST_PROCESSOR_TYPES.contains(name)
|| SPRING_CONFIG_CLASSES_ENHANCE_TYPES.contains(name)) {
return beanStat.getCost() >= beanInitCostThreshold;
} else {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.PatternMatchUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void setExcludeBeanNames(String... beanNames) {
Assert.notEmpty(beanNames, "'excludeBeanNames' must not be empty");
this.excludeBeanNames = new ArrayList<>(beanNames.length);
for (String mappedName : beanNames) {
this.excludeBeanNames.add(mappedName.strip());
this.excludeBeanNames.add(StringUtils.trimWhitespace(mappedName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -34,7 +34,7 @@
* @author huzijie
* @version ExcludeBeanNameAutoProxyCreatorTests.java, v 0.1 2024年01月04日 4:36 PM huzijie Exp $
*/
public class ExcludeBeanNameAutoProxyCreatorTests {
public class ExcludeBeanNameAutoProxyCreatorTest {

@Test
public void excludeBeanNames() {
Expand Down

0 comments on commit 0319b6d

Please sign in to comment.