代码优化.

pull/142/head
chen.ma 4 years ago
parent 8ede173bbb
commit cb842fa083

@ -1,12 +0,0 @@
package cn.hippo4j.core.config;
/**
* Thread pool notify alarm config.
*
* @author chen.ma
* @date 2022/3/3 20:45
*/
public class ThreadPoolNotifyAlarmConfig {
}

@ -17,12 +17,12 @@ import java.util.concurrent.ConcurrentHashMap;
public class GlobalThreadPoolManage { public class GlobalThreadPoolManage {
/** /**
* 线 * 线.
*/ */
private static final Map<String, PoolParameter> POOL_PARAMETER = new ConcurrentHashMap(); private static final Map<String, PoolParameter> POOL_PARAMETER = new ConcurrentHashMap();
/** /**
* 线 * 线.
*/ */
private static final Map<String, DynamicThreadPoolWrapper> EXECUTOR_MAP = new ConcurrentHashMap(); private static final Map<String, DynamicThreadPoolWrapper> EXECUTOR_MAP = new ConcurrentHashMap();

@ -5,7 +5,7 @@ package cn.hippo4j.core.starter.parser;
* @date : 2022/3/1 07:50 * @date : 2022/3/1 07:50
* @description: * @description:
*/ */
public abstract class AbstractConfigParser implements ConfigParser{ public abstract class AbstractConfigParser implements ConfigParser {
@Override @Override
public boolean supports(ConfigFileTypeEnum type) { public boolean supports(ConfigFileTypeEnum type) {

@ -11,10 +11,28 @@ import java.util.Map;
*/ */
public interface ConfigParser { public interface ConfigParser {
/**
* Supports.
*
* @param type
* @return
*/
boolean supports(ConfigFileTypeEnum type); boolean supports(ConfigFileTypeEnum type);
/**
* Do parse.
*
* @param content
* @return
* @throws IOException
*/
Map<Object, Object> doParse(String content) throws IOException; Map<Object, Object> doParse(String content) throws IOException;
/**
* Get config file types.
*
* @return
*/
List<ConfigFileTypeEnum> getConfigFileTypes(); List<ConfigFileTypeEnum> getConfigFileTypes();
} }

@ -33,6 +33,7 @@ public class ConfigParserHandler {
return parser.doParse(content); return parser.doParse(content);
} }
} }
return Collections.emptyMap(); return Collections.emptyMap();
} }

@ -13,8 +13,7 @@ import java.util.Properties;
* @date : 2022/3/1 07:49 * @date : 2022/3/1 07:49
* @description: * @description:
*/ */
public class PropertiesConfigParser extends AbstractConfigParser{ public class PropertiesConfigParser extends AbstractConfigParser {
@Override @Override
public Map<Object, Object> doParse(String content) throws IOException { public Map<Object, Object> doParse(String content) throws IOException {
@ -27,4 +26,5 @@ public class PropertiesConfigParser extends AbstractConfigParser{
public List<ConfigFileTypeEnum> getConfigFileTypes() { public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.PROPERTIES); return Lists.newArrayList(ConfigFileTypeEnum.PROPERTIES);
} }
} }

@ -21,8 +21,10 @@ public class YamlConfigParser extends AbstractConfigParser {
if (StringUtils.isEmpty(content)) { if (StringUtils.isEmpty(content)) {
return Maps.newHashMapWithExpectedSize(0); return Maps.newHashMapWithExpectedSize(0);
} }
YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean(); YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean();
bean.setResources(new ByteArrayResource(content.getBytes())); bean.setResources(new ByteArrayResource(content.getBytes()));
return bean.getObject(); return bean.getObject();
} }
@ -30,4 +32,5 @@ public class YamlConfigParser extends AbstractConfigParser {
public List<ConfigFileTypeEnum> getConfigFileTypes() { public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.YML, ConfigFileTypeEnum.YAML); return Lists.newArrayList(ConfigFileTypeEnum.YML, ConfigFileTypeEnum.YAML);
} }
} }

@ -59,6 +59,7 @@ public class BootstrapCorePropertiesBinderAdapt {
* @param configInfo * @param configInfo
* @return * @return
*/ */
@Deprecated
private static BootstrapCoreProperties adapt(Map<Object, Object> configInfo) { private static BootstrapCoreProperties adapt(Map<Object, Object> configInfo) {
BootstrapCoreProperties bindableCoreProperties; BootstrapCoreProperties bindableCoreProperties;
try { try {

@ -2,6 +2,7 @@ package cn.hippo4j.core.starter.support;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.notify.ThreadPoolNotifyAlarm; import cn.hippo4j.common.notify.ThreadPoolNotifyAlarm;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.executor.DynamicThreadPool; import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
@ -99,10 +100,11 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
try { try {
// 使用相关参数创建线程池 // 使用相关参数创建线程池
BlockingQueue workQueue = QueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), executorProperties.getQueueCapacity()); BlockingQueue workQueue = QueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), executorProperties.getQueueCapacity());
String threadNamePrefix = executorProperties.getThreadNamePrefix();
newDynamicPoolExecutor = ThreadPoolBuilder.builder() newDynamicPoolExecutor = ThreadPoolBuilder.builder()
.dynamicPool() .dynamicPool()
.workQueue(workQueue) .workQueue(workQueue)
.threadFactory(threadPoolId) .threadFactory(StringUtil.isNotBlank(threadNamePrefix) ? threadNamePrefix : threadPoolId)
.executeTimeOut(Optional.ofNullable(executorProperties.getExecuteTimeOut()).orElse(0L)) .executeTimeOut(Optional.ofNullable(executorProperties.getExecuteTimeOut()).orElse(0L))
.poolThreadSize(executorProperties.getCorePoolSize(), executorProperties.getMaximumPoolSize()) .poolThreadSize(executorProperties.getCorePoolSize(), executorProperties.getMaximumPoolSize())
.keepAliveTime(executorProperties.getKeepAliveTime(), TimeUnit.SECONDS) .keepAliveTime(executorProperties.getKeepAliveTime(), TimeUnit.SECONDS)

Loading…
Cancel
Save