Move the IExecutorProperties class to the common module.

pull/1133/head
yanrongzhen 2 years ago
parent c0b1bb6dce
commit 17b62f7853

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.config.springboot.starter.config;
package cn.hippo4j.common.api;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -27,7 +27,7 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DynamicThreadPoolNotifyProperties {
public class ExecutorNotifyProperties {
/**
* Thread pool run alarm interval. unit: s

@ -15,7 +15,7 @@
* limitations under the License.
*/
package cn.hippo4j.config.springboot.starter.config;
package cn.hippo4j.common.api;
/**
* Interface for thread pool configuration.
@ -45,5 +45,5 @@ public interface IExecutorProperties {
/**
* Notify configs
*/
DynamicThreadPoolNotifyProperties getNotify();
ExecutorNotifyProperties getNotify();
}

@ -17,6 +17,8 @@
package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.common.api.ExecutorNotifyProperties;
import cn.hippo4j.common.api.IExecutorProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -101,7 +103,7 @@ public class ExecutorProperties implements IExecutorProperties {
/**
* Notify
*/
private DynamicThreadPoolNotifyProperties notify;
private ExecutorNotifyProperties notify;
/**
* Nodes, application startup is not affect, change properties is effect

@ -17,6 +17,8 @@
package cn.hippo4j.config.springboot.starter.config;
import cn.hippo4j.common.api.ExecutorNotifyProperties;
import cn.hippo4j.common.api.IExecutorProperties;
import lombok.Data;
/**
@ -58,5 +60,5 @@ public class WebExecutorProperties implements IExecutorProperties {
/**
* Notify config
*/
private DynamicThreadPoolNotifyProperties notify;
private ExecutorNotifyProperties notify;
}

@ -18,6 +18,8 @@
package cn.hippo4j.config.springboot.starter.notify;
import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.api.ExecutorNotifyProperties;
import cn.hippo4j.common.api.IExecutorProperties;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.config.*;
@ -128,19 +130,19 @@ public class ConfigModeNotifyConfigBuilder implements NotifyConfigBuilder {
private int buildInterval(IExecutorProperties executorProperties) {
return Optional.ofNullable(executorProperties.getNotify())
.map(DynamicThreadPoolNotifyProperties::getInterval)
.map(ExecutorNotifyProperties::getInterval)
.orElse(Optional.ofNullable(configProperties.getDefaultExecutor())
.map(ExecutorProperties::getNotify)
.map(DynamicThreadPoolNotifyProperties::getInterval)
.map(ExecutorNotifyProperties::getInterval)
.orElse(5));
}
private String buildReceive(IExecutorProperties executorProperties) {
return Optional.ofNullable(executorProperties.getNotify())
.map(DynamicThreadPoolNotifyProperties::getReceives)
.map(ExecutorNotifyProperties::getReceives)
.orElse(Optional.ofNullable(configProperties.getDefaultExecutor())
.map(ExecutorProperties::getNotify)
.map(DynamicThreadPoolNotifyProperties::getReceives).orElse(""));
.map(ExecutorNotifyProperties::getReceives).orElse(""));
}
private String getToken(NotifyPlatformProperties platformProperties) {

@ -23,7 +23,7 @@ import cn.hippo4j.common.executor.support.RejectedPolicyTypeEnum;
import cn.hippo4j.common.toolkit.ReflectUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.springboot.starter.config.BootstrapConfigProperties;
import cn.hippo4j.config.springboot.starter.config.DynamicThreadPoolNotifyProperties;
import cn.hippo4j.common.api.ExecutorNotifyProperties;
import cn.hippo4j.config.springboot.starter.config.ExecutorProperties;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
@ -229,7 +229,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
* @return thread-pool notify alarm
*/
private ThreadPoolNotifyAlarm buildThreadPoolNotifyAlarm(ExecutorProperties executorProperties) {
DynamicThreadPoolNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
ExecutorNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null);
boolean isAlarm = Optional.ofNullable(executorProperties.getAlarm())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getAlarm).orElse(true));
int activeAlarm = Optional.ofNullable(executorProperties.getActiveAlarm())
@ -237,11 +237,11 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
int capacityAlarm = Optional.ofNullable(executorProperties.getCapacityAlarm())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getCapacityAlarm).orElse(80));
int interval = Optional.ofNullable(notify)
.map(DynamicThreadPoolNotifyProperties::getInterval)
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(DynamicThreadPoolNotifyProperties::getInterval).orElse(5));
.map(ExecutorNotifyProperties::getInterval)
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(ExecutorNotifyProperties::getInterval).orElse(5));
String receive = Optional.ofNullable(notify)
.map(DynamicThreadPoolNotifyProperties::getReceives)
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(DynamicThreadPoolNotifyProperties::getReceives).orElse(""));
.map(ExecutorNotifyProperties::getReceives)
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(ExecutorNotifyProperties::getReceives).orElse(""));
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(isAlarm, activeAlarm, capacityAlarm);
threadPoolNotifyAlarm.setInterval(interval);
threadPoolNotifyAlarm.setReceives(receive);

Loading…
Cancel
Save