Skip to content

Commit

Permalink
fix: spring xml配置文件可配置 async-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mySingleLive committed Nov 21, 2022
1 parent 954be44 commit cdc1033
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,26 +716,6 @@ public ForestConfiguration setAsyncMode(ForestAsyncMode asyncMode) {
return this;
}

/**
* 设置异步模式
*
* @param asyncMode 异步模式 - 字符串
* @return 当前ForestConfiguration实例
* @since 1.5.27
*/
public ForestConfiguration setAsyncMode(String asyncMode) {
if (StringUtils.isEmpty(asyncMode)) {
throw new ForestRuntimeException("Can not resolve async mode '" + asyncMode + "'");
}
final String enumName = asyncMode.trim().toUpperCase();
ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName);
if (mode == null) {
throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'");
}
this.asyncMode = mode;
return this;
}

/**
* 获取最大异步线程池队列大小
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dtflys.forest.schema;

import com.dtflys.forest.http.ForestAsyncMode;
import com.dtflys.forest.interceptor.SpringInterceptorFactory;
import com.dtflys.forest.logging.ForestLogHandler;
import com.dtflys.forest.reflection.SpringForestObjectFactory;
Expand Down Expand Up @@ -83,8 +84,17 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
if (StringUtils.isNotEmpty(attributeValue)) {
if ("backend".equals(attributeName)) {
beanDefinition.getPropertyValues().addPropertyValue("backendName", attributeValue);
}
else if ("logHandler".equals(attributeName)) {
} else if ("asyncMode".equals(attributeName)) {
if (StringUtils.isEmpty(attributeValue)) {
throw new ForestRuntimeException("Can not resolve async mode '" + attributeValue + "'");
}
final String enumName = attributeValue.trim().toUpperCase();
ForestAsyncMode mode = ForestAsyncMode.valueOf(enumName);
if (mode == null) {
throw new ForestRuntimeException("Can not resolve async mode '" + enumName + "'");
}
beanDefinition.getPropertyValues().addPropertyValue("asyncMode", mode);
} else if ("logHandler".equals(attributeName)) {
try {
Class clazz = Class.forName(attributeValue);
if (!ForestLogHandler.class.isAssignableFrom(clazz)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dtflys.forest.Forest;
import com.dtflys.forest.config.ForestConfiguration;
import com.dtflys.forest.http.ForestAsyncMode;
import com.dtflys.spring.test.client2.GithubClient;
import junit.framework.TestCase;
import com.dtflys.spring.test.client0.BeastshopClient;
Expand Down Expand Up @@ -35,6 +36,7 @@ public void testScan() {
assertThat(configuration.getMaxRequestQueueSize()).isEqualTo(300);
assertThat(configuration.getMaxAsyncThreadSize()).isEqualTo(256);
assertThat(configuration.getMaxAsyncQueueSize()).isEqualTo(128);
assertThat(configuration.getAsyncMode()).isEqualTo(ForestAsyncMode.KOTLIN_COROUTINE);
Object baseUrl = configuration.getVariableValue("baseUrl");
assertThat(baseUrl).isNotNull().isEqualTo("http://www.thebeastshop.com");
}
Expand Down

0 comments on commit cdc1033

Please sign in to comment.