diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/config/ServerBootstrapProperties.java b/hippo4j-config/src/main/java/cn/hippo4j/config/config/ServerBootstrapProperties.java new file mode 100644 index 00000000..3e6db115 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/config/ServerBootstrapProperties.java @@ -0,0 +1,34 @@ +package cn.hippo4j.config.config; + +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * Server bootstrap properties. + * + * @author chen.ma + * @date 2021/12/22 08:01 + */ +@Slf4j +@Getter +@Setter +@Configuration +@ConfigurationProperties(prefix = ServerBootstrapProperties.PREFIX) +public class ServerBootstrapProperties { + + public final static String PREFIX = "hippo4j.core"; + + /** + * Whether to start the background task of cleaning up thread pool history data. + */ + private Boolean cleanHistoryDataEnable = Boolean.TRUE; + + /** + * Regularly clean up the historical running data of thread pool. unit: minute. + */ + private Integer cleanHistoryDataPeriod = 30; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/monitor/TimeCleanHistoryDataTask.java b/hippo4j-config/src/main/java/cn/hippo4j/config/monitor/TimeCleanHistoryDataTask.java index 988c0b5c..94816ef9 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/monitor/TimeCleanHistoryDataTask.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/monitor/TimeCleanHistoryDataTask.java @@ -1,6 +1,7 @@ package cn.hippo4j.config.monitor; import cn.hippo4j.common.executor.ExecutorFactory; +import cn.hippo4j.config.config.ServerBootstrapProperties; import cn.hippo4j.config.model.HisRunDataInfo; import cn.hippo4j.config.service.biz.HisRunDataService; import cn.hutool.core.date.DateTime; @@ -10,7 +11,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Date; @@ -29,11 +29,8 @@ import static cn.hippo4j.common.constant.Constants.DEFAULT_GROUP; @RequiredArgsConstructor public class TimeCleanHistoryDataTask implements Runnable, InitializingBean { - @Value("${clean.history.data.period:30}") - private Long cleanHistoryDataPeriod; - - @Value("${clean.history.data.period.enable:true}") - private Boolean cleanHistoryDataPeriodEnable; + @NonNull + private final ServerBootstrapProperties properties; @NonNull private final HisRunDataService hisRunDataService; @@ -43,7 +40,7 @@ public class TimeCleanHistoryDataTask implements Runnable, InitializingBean { @Override public void run() { Date currentDate = new Date(); - DateTime offsetMinuteDateTime = DateUtil.offsetMinute(currentDate, (int) -cleanHistoryDataPeriod); + DateTime offsetMinuteDateTime = DateUtil.offsetMinute(currentDate, -properties.getCleanHistoryDataPeriod()); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(HisRunDataInfo.class) .le(HisRunDataInfo::getTimestamp, offsetMinuteDateTime.getTime()); @@ -53,7 +50,7 @@ public class TimeCleanHistoryDataTask implements Runnable, InitializingBean { @Override public void afterPropertiesSet() throws Exception { - if (cleanHistoryDataPeriodEnable) { + if (properties.getCleanHistoryDataEnable()) { cleanHistoryDataExecutor = ExecutorFactory.Managed .newSingleScheduledExecutorService(DEFAULT_GROUP, r -> new Thread(r, "clean-history-data")); cleanHistoryDataExecutor.scheduleWithFixedDelay(this, 0, 1, TimeUnit.MINUTES); diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java index e19b1bbf..c84713ed 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java @@ -3,6 +3,7 @@ package cn.hippo4j.config.service.biz.impl; import cn.hippo4j.common.monitor.Message; import cn.hippo4j.common.monitor.RuntimeMessage; import cn.hippo4j.common.toolkit.GroupKey; +import cn.hippo4j.config.config.ServerBootstrapProperties; import cn.hippo4j.config.mapper.HisRunDataMapper; import cn.hippo4j.config.model.HisRunDataInfo; import cn.hippo4j.config.model.biz.monitor.MonitorActiveRespDTO; @@ -14,7 +15,7 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; -import org.springframework.beans.factory.annotation.Value; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import java.util.Date; @@ -29,15 +30,15 @@ import static cn.hutool.core.date.DatePattern.NORM_TIME_PATTERN; * @date 2021/12/10 21:28 */ @Service +@AllArgsConstructor public class HisRunDataServiceImpl extends ServiceImpl implements HisRunDataService { - @Value("${clean.history.data.period:30}") - private Long cleanHistoryDataPeriod; + private final ServerBootstrapProperties properties; @Override public List query(MonitorQueryReqDTO reqDTO) { Date currentDate = new Date(); - DateTime dateTime = DateUtil.offsetMinute(currentDate, (int) -cleanHistoryDataPeriod); + DateTime dateTime = DateUtil.offsetMinute(currentDate, -properties.getCleanHistoryDataPeriod()); long startTime = dateTime.getTime(); List hisRunDataInfos = this.lambdaQuery() @@ -55,7 +56,7 @@ public class HisRunDataServiceImpl extends ServiceImpl hisRunDataInfos = this.lambdaQuery() diff --git a/hippo4j-server/conf/application.properties b/hippo4j-server/conf/application.properties index 6f5c9ccf..2a0e1b43 100644 --- a/hippo4j-server/conf/application.properties +++ b/hippo4j-server/conf/application.properties @@ -17,8 +17,8 @@ server.tomcat.basedir= tenant=hippo4j ### Regularly clean up the historical running data of thread pool. unit: minute. -clean.history.data.period=30 -clean.history.data.period.enable=true +hippo4j.core.clean-history-data-period=30 +hippo4j.core.clean-history-data-enable=true #*************** Config Module Related Configurations ***************# diff --git a/hippo4j-server/src/main/resources/application.properties b/hippo4j-server/src/main/resources/application.properties index 6f5c9ccf..2a0e1b43 100644 --- a/hippo4j-server/src/main/resources/application.properties +++ b/hippo4j-server/src/main/resources/application.properties @@ -17,8 +17,8 @@ server.tomcat.basedir= tenant=hippo4j ### Regularly clean up the historical running data of thread pool. unit: minute. -clean.history.data.period=30 -clean.history.data.period.enable=true +hippo4j.core.clean-history-data-period=30 +hippo4j.core.clean-history-data-enable=true #*************** Config Module Related Configurations ***************#