Skip to content

Commit

Permalink
Merge branch 'master' into springboot3
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Jan 24, 2024
2 parents 57da4ed + 7ac3a74 commit 2c763c3
Show file tree
Hide file tree
Showing 44 changed files with 440 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ public enum CollectorTypeEnum {
*/
LOGGING,

/**
* Micrometer collect type.
*/
MICROMETER,

INTERNAL_LOGGING
/**
* Logging collect type.
*/
INTERNAL_LOGGING,

/**
* JMX collect type.
*/
JMX

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.em;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
Expand All @@ -26,6 +27,7 @@
* @since 1.0.0
**/
@Getter
@AllArgsConstructor
public enum ConfigFileTypeEnum {

/**
Expand All @@ -40,10 +42,6 @@ public enum ConfigFileTypeEnum {

private final String value;

ConfigFileTypeEnum(String value) {
this.value = value;
}

public static ConfigFileTypeEnum of(String value) {
for (ConfigFileTypeEnum typeEnum : ConfigFileTypeEnum.values()) {
if (typeEnum.value.equals(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.em;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
Expand All @@ -26,6 +27,7 @@
* @since 1.0.0
**/
@Getter
@AllArgsConstructor
public enum NotifyItemEnum {

/**
Expand Down Expand Up @@ -63,11 +65,6 @@ public enum NotifyItemEnum {

private final String unit;

NotifyItemEnum(String value, String unit) {
this.value = value;
this.unit = unit;
}

public static NotifyItemEnum of(String value) {
for (NotifyItemEnum notifyItem : NotifyItemEnum.values()) {
if (notifyItem.value.equals(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.em;

import lombok.AllArgsConstructor;
import org.dromara.dynamictp.common.ex.DtpException;
import org.dromara.dynamictp.common.queue.MemorySafeLinkedBlockingQueue;
import org.dromara.dynamictp.common.queue.VariableLinkedBlockingQueue;
Expand All @@ -43,6 +44,7 @@
**/
@Slf4j
@Getter
@AllArgsConstructor
public enum QueueTypeEnum {

/**
Expand All @@ -66,13 +68,9 @@ public enum QueueTypeEnum {

MEMORY_SAFE_LINKED_BLOCKING_QUEUE(9, "MemorySafeLinkedBlockingQueue");

private final Integer code;
private final String name;
private final int code;

QueueTypeEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
private final String name;

public static BlockingQueue<Runnable> buildLbq(String name, int capacity) {
return buildLbq(name, capacity, false, 256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.em;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -28,6 +29,7 @@
**/
@Slf4j
@Getter
@AllArgsConstructor
public enum RejectedTypeEnum {

/**
Expand All @@ -43,7 +45,4 @@ public enum RejectedTypeEnum {

private final String name;

RejectedTypeEnum(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package org.dromara.dynamictp.common.entity;

import lombok.Data;
import lombok.experimental.Accessors;
import org.dromara.dynamictp.common.em.NotifyItemEnum;
import org.dromara.dynamictp.common.util.DateUtil;
import lombok.Builder;
import lombok.Data;

import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -31,7 +31,7 @@
* @since 1.0.4
**/
@Data
@Builder
@Accessors(chain = true)
public class AlarmInfo {

private NotifyItemEnum notifyItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class NotifyPlatform {
*/
private String secret;

/**
* webHook, may be null.
*/
private String webHook;

/**
* Receivers, split by ,
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@

package org.dromara.dynamictp.common.entity;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;


/**
* ThreadPoolStats related
*
* @author yanhom
* @since 1.0.0
**/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@EqualsAndHashCode(callSuper = true)
public class ThreadPoolStats extends Metrics {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.dromara.dynamictp.common.util.JsonUtil;

import java.util.List;
import java.util.Optional;

import static org.dromara.dynamictp.common.constant.DingNotifyConst.DING_NOTICE_TITLE;

Expand Down Expand Up @@ -72,22 +73,24 @@ protected String buildMsgBody(NotifyPlatform platform, String content) {

@Override
protected String buildUrl(NotifyPlatform platform) {
return getTargetUrl(platform.getSecret(), platform.getUrlKey());
String webHook = Optional.ofNullable(platform.getWebHook()).orElse(DingNotifyConst.DING_WEBHOOK);
return getTargetUrl(platform.getSecret(), platform.getUrlKey(), webHook);
}

/**
* Build target url.
*
* @param secret secret
* @param accessToken accessToken
* @param webHook webHook
* @return url
*/
private String getTargetUrl(String secret, String accessToken) {
private String getTargetUrl(String secret, String accessToken, String webHook) {
if (StringUtils.isBlank(secret)) {
return DingNotifyConst.DING_WEBHOOK + accessToken;
return webHook + accessToken;
}
long timestamp = System.currentTimeMillis();
String sign = DingSignUtil.dingSign(secret, timestamp);
return DingNotifyConst.DING_WEBHOOK + accessToken + "&timestamp=" + timestamp + "&sign=" + sign;
return webHook + accessToken + "&timestamp=" + timestamp + "&sign=" + sign;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;

import static org.dromara.dynamictp.common.constant.LarkNotifyConst.SIGN_PARAM;
import static org.dromara.dynamictp.common.constant.LarkNotifyConst.SIGN_REPLACE;
Expand Down Expand Up @@ -93,6 +94,7 @@ protected String buildMsgBody(NotifyPlatform platform, String content) {

@Override
protected String buildUrl(NotifyPlatform platform) {
return LarkNotifyConst.LARK_WEBHOOK + platform.getUrlKey();
String webHook = Optional.ofNullable(platform.getWebHook()).orElse(LarkNotifyConst.LARK_WEBHOOK);
return webHook + platform.getUrlKey();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.dromara.dynamictp.common.entity.NotifyPlatform;
import org.dromara.dynamictp.common.util.JsonUtil;

import java.util.Optional;

/**
* WechatNotifier related
*
Expand All @@ -50,6 +52,7 @@ protected String buildMsgBody(NotifyPlatform platform, String content) {

@Override
protected String buildUrl(NotifyPlatform platform) {
return WechatNotifyConst.WECHAT_WEB_HOOK + platform.getUrlKey();
String webHook = Optional.ofNullable(platform.getWebHook()).orElse(WechatNotifyConst.WECHAT_WEB_HOOK);
return webHook + platform.getUrlKey();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ private DtpProperties() { }
*/
private boolean enabled = true;

/**
* Environment, if not set, will use "spring.profiles.active".
*/
private String env;

/**
* If print banner.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.dromara.dynamictp.common.util;

import org.dromara.dynamictp.common.properties.DtpProperties;
import org.dromara.dynamictp.common.spring.ApplicationContextHolder;
import org.dromara.dynamictp.common.entity.ServiceInstance;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -37,7 +38,8 @@
@Slf4j
public final class CommonUtil {

private CommonUtil() { }
private CommonUtil() {
}

private static final ServiceInstance SERVICE_INSTANCE;

Expand All @@ -57,8 +59,11 @@ private CommonUtil() { }
log.error("get localhost address error.", e);
}

// fix #I8SSGQ
String env = environment.getProperty("spring.profiles.active");
String env = DtpProperties.getInstance().getEnv();
if (StringUtils.isBlank(env)) {
// fix #I8SSGQ
env = environment.getProperty("spring.profiles.active");
}
if (StringUtils.isBlank(env)) {
String[] profiles = environment.getActiveProfiles();
if (profiles.length < 1) {
Expand All @@ -68,6 +73,7 @@ private CommonUtil() { }
env = profiles[0];
}
}

SERVICE_INSTANCE = new ServiceInstance(address, port, appName, env);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

package org.dromara.dynamictp.core.aware;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* AwareType Enum
*
* @author kyao
* @since 1.1.4
*/
@Getter
@AllArgsConstructor
public enum AwareTypeEnum {

/**
Expand All @@ -44,16 +49,4 @@ public enum AwareTypeEnum {

private final String name;

AwareTypeEnum(int order, String name) {
this.order = order;
this.name = name;
}

public int getOrder() {
return order;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
**/
public class ExecutorConverter {

private ExecutorConverter() { }
private ExecutorConverter() {
}

public static TpMainFields toMainFields(ExecutorWrapper executorWrapper) {
TpMainFields mainFields = new TpMainFields();
Expand Down Expand Up @@ -82,20 +83,20 @@ public static ThreadPoolStats toMetrics(ExecutorWrapper wrapper) {
}

private static ThreadPoolStats convertCommon(ExecutorAdapter<?> executor) {
return ThreadPoolStats.builder()
.corePoolSize(executor.getCorePoolSize())
.maximumPoolSize(executor.getMaximumPoolSize())
.poolSize(executor.getPoolSize())
.activeCount(executor.getActiveCount())
.largestPoolSize(executor.getLargestPoolSize())
.queueType(executor.getQueueType())
.queueCapacity(executor.getQueueCapacity())
.queueSize(executor.getQueueSize())
.queueRemainingCapacity(executor.getQueueRemainingCapacity())
.taskCount(executor.getTaskCount())
.completedTaskCount(executor.getCompletedTaskCount())
.waitTaskCount(executor.getQueueSize())
.rejectHandlerName(executor.getRejectHandlerType())
.build();
ThreadPoolStats poolStats = new ThreadPoolStats();
poolStats.setCorePoolSize(executor.getCorePoolSize());
poolStats.setMaximumPoolSize(executor.getMaximumPoolSize());
poolStats.setPoolSize(executor.getPoolSize());
poolStats.setActiveCount(executor.getActiveCount());
poolStats.setLargestPoolSize(executor.getLargestPoolSize());
poolStats.setQueueType(executor.getQueueType());
poolStats.setQueueCapacity(executor.getQueueCapacity());
poolStats.setQueueSize(executor.getQueueSize());
poolStats.setQueueRemainingCapacity(executor.getQueueRemainingCapacity());
poolStats.setTaskCount(executor.getTaskCount());
poolStats.setCompletedTaskCount(executor.getCompletedTaskCount());
poolStats.setWaitTaskCount(executor.getQueueSize());
poolStats.setRejectHandlerName(executor.getRejectHandlerType());
return poolStats;
}
}
Loading

0 comments on commit 2c763c3

Please sign in to comment.