抽象消息发送公共模块.

pull/110/head
chen.ma 3 years ago
parent 0f3287403d
commit 227f8893e0

@ -40,6 +40,19 @@
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<!-- 用户反馈其中 javax.jms 无法下载, 未发现 log4j 用处, 暂且排除 -->
<exclusions>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
</dependencies>
<build>

@ -68,7 +68,7 @@ public class PoolRunStateInfo extends PoolBaseInfo implements Serializable {
/**
* rejectCount
*/
private Integer rejectCount;
private Long rejectCount;
/**
* host

@ -1,4 +1,4 @@
package cn.hippo4j.starter.alarm;
package cn.hippo4j.common.notify;
import cn.hutool.core.util.StrUtil;
import lombok.Builder;
@ -27,7 +27,7 @@ public class AlarmControlDTO {
/**
*
*/
private MessageTypeEnum typeEnum;
private NotifyTypeEnum typeEnum;
/**
* 线

@ -1,4 +1,4 @@
package cn.hippo4j.starter.alarm;
package cn.hippo4j.common.notify;
import cn.hippo4j.common.constant.Constants;
import cn.hutool.core.util.IdUtil;
@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
/**
* .
* Alarm control assembly.
*
* @author chen.ma
* @date 2021/10/28 21:24
@ -24,7 +24,7 @@ public class AlarmControlHandler {
private final Map<String, Cache<String, String>> threadPoolAlarmCache = Maps.newConcurrentMap();
/**
* .
* Control message push alarm frequency.
*
* @param alarmControl
* @return
@ -43,7 +43,7 @@ public class AlarmControlHandler {
try {
pkId = cache.getIfPresent(alarmControl.getTypeEnum().name());
if (StrUtil.isBlank(pkId)) {
// val 无意义
// Val meaningless.
cache.put(alarmControl.getTypeEnum().name(), IdUtil.simpleUUID());
return true;
}

@ -0,0 +1,24 @@
package cn.hippo4j.common.notify;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
/**
* Base send message service impl.
*
* @author chen.ma
* @date 2022/2/22 21:32
*/
public class BaseSendMessageServiceImpl implements SendMessageService {
@Override
public void sendAlarmMessage(NotifyTypeEnum typeEnum, AlarmNotifyRequest alarmNotifyRequest) {
}
@Override
public void sendChangeMessage(ChangeParameterNotifyRequest changeParameterNotifyRequest) {
}
}

@ -1,4 +1,4 @@
package cn.hippo4j.starter.alarm;
package cn.hippo4j.common.notify;
/**
* Notify platform enum.
@ -9,17 +9,17 @@ package cn.hippo4j.starter.alarm;
public enum NotifyPlatformEnum {
/**
*
* DING
*/
DING,
/**
*
* LARK
*/
LARK,
/**
*
* WECHAT
*/
WECHAT

@ -0,0 +1,31 @@
package cn.hippo4j.common.notify;
/**
* Notify type enum.
*
* @author chen.ma
* @date 2022/2/22 19:44
*/
public enum NotifyTypeEnum {
/**
* CHANGE
*/
CHANGE,
/**
* CAPACITY
*/
CAPACITY,
/**
* ACTIVITY
*/
ACTIVITY,
/**
* REJECT
*/
REJECT
}

@ -0,0 +1,34 @@
package cn.hippo4j.common.notify;
import cn.hippo4j.common.notify.request.NotifyRequest;
/**
* Send message handler.
*
* @author chen.ma
* @date 2021/8/15 15:44
*/
public interface SendMessageHandler<T extends NotifyRequest, R extends NotifyRequest> {
/**
* Get type.
*
* @return
*/
String getType();
/**
* Send alarm message.
*
* @param alarmNotifyRequest
*/
void sendAlarmMessage(T alarmNotifyRequest);
/**
* Send change message.
*
* @param changeParameterNotifyRequest
*/
void sendChangeMessage(R changeParameterNotifyRequest);
}

@ -0,0 +1,29 @@
package cn.hippo4j.common.notify;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
/**
* Send message service.
*
* @author chen.ma
* @date 2022/2/22 19:56
*/
public interface SendMessageService {
/**
* Send alarm message.
*
* @param typeEnum
* @param alarmNotifyRequest
*/
void sendAlarmMessage(NotifyTypeEnum typeEnum, AlarmNotifyRequest alarmNotifyRequest);
/**
* Send change message.
*
* @param changeParameterNotifyRequest
*/
void sendChangeMessage(ChangeParameterNotifyRequest changeParameterNotifyRequest);
}

@ -0,0 +1,82 @@
package cn.hippo4j.common.notify.platform;
/**
* Ding alarm constants.
*
* @author chen.ma
* @date 2021/11/26 20:03
*/
public class DingAlarmConstants {
/**
* Url
*/
public static final String DING_ROBOT_SERVER_URL = "https://oapi.dingtalk.com/robot/send?access_token=";
/**
* 线
*/
public static final String DING_ALARM_TITLE = "动态线程池告警";
/**
* 线
*/
public static final String DING_NOTICE_TITLE = "动态线程池通知";
/**
* 线
*/
public static final String DING_ALARM_TXT =
"<font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " +
"<font color='#778899' size=2>报警类型:%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>核心线程数:%d</font> \n\n " +
"<font color='#708090' size=2>最大线程数:%d</font> \n\n " +
"<font color='#708090' size=2>当前线程数:%d</font> \n\n " +
"<font color='#708090' size=2>活跃线程数:%d</font> \n\n " +
"<font color='#708090' size=2>最大任务数:%d</font> \n\n " +
"<font color='#708090' size=2>线程池任务总量:%d</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>队列类型:%s</font> \n\n " +
"<font color='#708090' size=2>队列容量:%d</font> \n\n " +
"<font color='#708090' size=2>队列元素个数:%d</font> \n\n " +
"<font color='#708090' size=2>队列剩余个数:%d</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>拒绝策略:%s</font> \n\n" +
"<font color='#708090' size=2>拒绝策略执行次数:</font><font color='#FF0000' size=2>%d</font> \n\n " +
"<font color='#708090' size=2>OWNER@%s</font> \n\n" +
"<font color='#708090' size=2>提示:%d 分钟内此线程池不会重复告警(可配置)</font> \n\n" +
" --- \n\n " +
"**播报时间:%s**";
/**
* 线
*/
public static final String DING_NOTICE_TXT =
"<font color='#2a9d8f'>[通知] </font>%s - 动态线程池参数变更 \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>核心线程数:%s</font> \n\n " +
"<font color='#708090' size=2>最大线程数:%s</font> \n\n " +
"<font color='#708090' size=2>核心线程超时:%s</font> \n\n " +
"<font color='#708090' size=2>线程存活时间:%s / SECONDS</font> \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>队列类型:%s</font> \n\n " +
"<font color='#708090' size=2>队列容量:%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>AGO 拒绝策略:%s</font> \n\n" +
"<font color='#708090' size=2>NOW 拒绝策略:%s</font> \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>提示:动态线程池配置变更实时通知(无限制)</font> \n\n" +
"<font color='#708090' size=2>OWNER@%s</font> \n\n" +
" --- \n\n " +
"**播报时间:%s**";
}

@ -0,0 +1,154 @@
package cn.hippo4j.common.notify.platform;
import cn.hippo4j.common.notify.NotifyPlatformEnum;
import cn.hippo4j.common.notify.request.RobotAlarmNotifyRequest;
import cn.hippo4j.common.notify.request.RobotChangeParameterNotifyRequest;
import cn.hippo4j.common.notify.SendMessageHandler;
import cn.hutool.core.date.DateUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import static cn.hippo4j.common.notify.platform.DingAlarmConstants.DING_ALARM_TXT;
import static cn.hippo4j.common.notify.platform.DingAlarmConstants.DING_NOTICE_TXT;
/**
* Send ding notification message.
*
* @author chen.ma
* @date 2021/8/15 15:49
*/
@Slf4j
public class DingSendMessageHandler implements SendMessageHandler<RobotAlarmNotifyRequest, RobotChangeParameterNotifyRequest> {
@Override
public String getType() {
return NotifyPlatformEnum.DING.name();
}
@Override
public void sendAlarmMessage(RobotAlarmNotifyRequest alarmNotifyRequest) {
String[] receives = alarmNotifyRequest.getReceives().split(",");
String afterReceives = Joiner.on(", @").join(receives);
String text = String.format(
DING_ALARM_TXT,
// 环境
alarmNotifyRequest.getActive(),
// 线程池ID
alarmNotifyRequest.getThreadPoolId(),
// 应用名称
alarmNotifyRequest.getAppName(),
// 实例信息
alarmNotifyRequest.getIdentify(),
// 报警类型
alarmNotifyRequest.getNotifyTypeEnum(),
// 核心线程数
alarmNotifyRequest.getCorePoolSize(),
// 最大线程数
alarmNotifyRequest.getMaximumPoolSize(),
// 当前线程数
alarmNotifyRequest.getPoolSize(),
// 活跃线程数
alarmNotifyRequest.getActiveCount(),
// 最大任务数
alarmNotifyRequest.getLargestPoolSize(),
// 线程池任务总量
alarmNotifyRequest.getCompletedTaskCount(),
// 队列类型名称
alarmNotifyRequest.getClass().getSimpleName(),
// 队列容量
alarmNotifyRequest.getCapacity(),
// 队列元素个数
alarmNotifyRequest.getQueueSize(),
// 队列剩余个数
alarmNotifyRequest.getRemainingCapacity(),
// 拒绝策略名称
alarmNotifyRequest.getRejectedExecutionHandlerName(),
// 拒绝策略次数
alarmNotifyRequest.getRejectCountNum(),
// 告警手机号
afterReceives,
// 报警频率
alarmNotifyRequest.getInterval(),
// 当前时间
DateUtil.now()
);
execute(alarmNotifyRequest.getSecretKey(), DingAlarmConstants.DING_ALARM_TITLE, text, Lists.newArrayList(receives));
}
@Override
public void sendChangeMessage(RobotChangeParameterNotifyRequest changeParameterNotifyRequest) {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String[] receives = changeParameterNotifyRequest.getReceives().split(",");
String afterReceives = Joiner.on(", @").join(receives);
/**
* hesitant e.g.
*/
String text = String.format(
DING_NOTICE_TXT,
// 环境
changeParameterNotifyRequest.getActive(),
// 线程池名称
threadPoolId,
// 应用名称
changeParameterNotifyRequest.getAppName(),
// 实例信息
changeParameterNotifyRequest.getIdentify(),
// 核心线程数
changeParameterNotifyRequest.getBeforeCorePoolSize() + " ➲ " + changeParameterNotifyRequest.getNowCorePoolSize(),
// 最大线程数
changeParameterNotifyRequest.getBeforeMaximumPoolSize() + " ➲ " + changeParameterNotifyRequest.getNowMaximumPoolSize(),
// 核心线程超时
changeParameterNotifyRequest.getBeforeAllowsCoreThreadTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 线程存活时间
changeParameterNotifyRequest.getBeforeKeepAliveTime() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 阻塞队列
changeParameterNotifyRequest.getBlockingQueueName(),
// 阻塞队列容量
changeParameterNotifyRequest.getBeforeQueueCapacity() + " ➲ " + changeParameterNotifyRequest.getNowQueueCapacity(),
// 拒绝策略
changeParameterNotifyRequest.getBeforeRejectedName(),
changeParameterNotifyRequest.getNowRejectedName(),
// 告警手机号
afterReceives,
// 当前时间
DateUtil.now()
);
execute(changeParameterNotifyRequest.getSecretKey(), DingAlarmConstants.DING_NOTICE_TITLE, text, Lists.newArrayList(receives));
}
private void execute(String secretKey, String title, String text, List<String> mobiles) {
String serverUrl = DingAlarmConstants.DING_ROBOT_SERVER_URL + secretKey;
DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(title);
markdown.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(mobiles);
request.setAt(at);
request.setMarkdown(markdown);
try {
dingTalkClient.execute(request);
} catch (ApiException ex) {
log.error("Ding failed to send message", ex);
}
}
}

@ -0,0 +1,42 @@
package cn.hippo4j.common.notify.platform;
/**
* lark alarm constants.
*
* @author imyzt
* @date 2021-11-23 19:29
*/
public class LarkAlarmConstants {
/**
* lark bot url
*/
public static final String LARK_BOT_URL = "https://open.feishu.cn/open-apis/bot/v2/hook/";
/**
* lark json
*/
public static final String ALARM_JSON_PATH = "classpath:properties/lark/alarm.json";
/**
* lark json
*/
public static final String NOTICE_JSON_PATH = "classpath:properties/lark/notice.json";
/**
* lark at format. openid
* openid,@
*/
public static final String LARK_AT_FORMAT_OPENID = "<at id='%s'></at>";
/**
* lark at format. username
* username,@username,@@
*/
public static final String LARK_AT_FORMAT_USERNAME = "<at id=''>%s</at>";
/**
* lark openid prefix
*/
public static final String LARK_OPENID_PREFIX = "ou_";
}

@ -0,0 +1,61 @@
package cn.hippo4j.common.notify.platform;
/**
* Ding alarm constants.
*
* @author chen.ma
* @date 2021/11/26 20:03
*/
public class WeChatAlarmConstants {
/**
* Url
*/
public static final String WE_CHAT_SERVER_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";
/**
* 线
*/
public static final String WE_CHAT_ALARM_TXT =
"### <font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n" +
"> 线程池ID<font color=\"warning\">%s</font> \n" +
"> 应用名称:<font color=\"warning\">%s</font> \n" +
"> 应用实例:%s \n" +
"> 报警类型:%s \n" +
"> 核心线程数:%s \n" +
"> 最大线程数:%s \n" +
"> 当前线程数:%s \n" +
"> 活跃线程数:%s \n" +
"> 最大任务数:%s \n" +
"> 线程池任务总量:%s \n" +
"> 队列类型:%s \n" +
"> 队列容量:%s \n" +
"> 队列元素个数:%s \n" +
"> 队列剩余个数:%s \n" +
"> 拒绝策略:%s \n" +
"> 拒绝策略执行次数:%s \n" +
"> OWNER@%s \n" +
"> 提示:%d 分钟内此线程池不会重复告警(可配置) \n\n" +
"**播报时间:%s**";
/**
* 线
*/
public static final String WE_CHAT_NOTICE_TXT =
"### <font color=\"info\">[通知] </font>%s - 动态线程池参数变更 \n" +
"> 线程池ID<font color=\"warning\">%s</font> \n" +
"> 应用名称:<font color=\"warning\">%s</font> \n" +
"> 应用实例:%s \n" +
"> 核心线程数:%s \n" +
"> 最大线程数:%s \n" +
"> 核心线程超时:%s \n" +
"> 线程存活时间:%s / SECONDS \n" +
"> 队列类型:%s \n" +
"> 队列容量:%s \n" +
"> AGO 拒绝策略:%s \n" +
"> NOW 拒绝策略:%s \n" +
"> OWNER<@%s> \n" +
"> 提示:动态线程池配置变更实时通知(无限制) \n\n" +
"**播报时间:%s**";
}

@ -0,0 +1,172 @@
package cn.hippo4j.common.notify.platform;
import cn.hippo4j.common.notify.NotifyPlatformEnum;
import cn.hippo4j.common.notify.SendMessageHandler;
import cn.hippo4j.common.notify.request.RobotAlarmNotifyRequest;
import cn.hippo4j.common.notify.request.RobotChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import com.google.common.base.Joiner;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import static cn.hippo4j.common.notify.platform.WeChatAlarmConstants.*;
/**
* WeChat send message handler.
*
* @author chen.ma
* @date 2021/11/26 20:06
*/
@Slf4j
public class WeChatSendMessageHandler implements SendMessageHandler<RobotAlarmNotifyRequest, RobotChangeParameterNotifyRequest> {
@Override
public String getType() {
return NotifyPlatformEnum.WECHAT.name();
}
@Override
public void sendAlarmMessage(RobotAlarmNotifyRequest alarmNotifyRequest) {
String[] receives = alarmNotifyRequest.getReceives().split(",");
String afterReceives = Joiner.on(", @").join(receives);
String text = String.format(
WE_CHAT_ALARM_TXT,
// 环境
alarmNotifyRequest.getActive(),
// 线程池ID
alarmNotifyRequest.getThreadPoolId(),
// 应用名称
alarmNotifyRequest.getAppName(),
// 实例信息
alarmNotifyRequest.getIdentify(),
// 报警类型
alarmNotifyRequest.getNotifyTypeEnum(),
// 核心线程数
alarmNotifyRequest.getCorePoolSize(),
// 最大线程数
alarmNotifyRequest.getMaximumPoolSize(),
// 当前线程数
alarmNotifyRequest.getPoolSize(),
// 活跃线程数
alarmNotifyRequest.getActiveCount(),
// 最大任务数
alarmNotifyRequest.getLargestPoolSize(),
// 线程池任务总量
alarmNotifyRequest.getCompletedTaskCount(),
// 队列类型名称
alarmNotifyRequest.getClass().getSimpleName(),
// 队列容量
alarmNotifyRequest.getCapacity(),
// 队列元素个数
alarmNotifyRequest.getQueueSize(),
// 队列剩余个数
alarmNotifyRequest.getRemainingCapacity(),
// 拒绝策略名称
alarmNotifyRequest.getRejectedExecutionHandlerName(),
// 拒绝策略次数
alarmNotifyRequest.getRejectCountNum(),
// 告警手机号
afterReceives,
// 报警频率
alarmNotifyRequest.getInterval(),
// 当前时间
DateUtil.now()
);
execute(alarmNotifyRequest.getSecretKey(), text);
}
@Override
public void sendChangeMessage(RobotChangeParameterNotifyRequest changeParameterNotifyRequest) {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String[] receives = changeParameterNotifyRequest.getReceives().split(",");
String afterReceives = Joiner.on("><@").join(receives);
String text = String.format(
WE_CHAT_NOTICE_TXT,
// 环境
changeParameterNotifyRequest.getActive(),
// 线程池名称
threadPoolId,
// 应用名称
changeParameterNotifyRequest.getAppName(),
// 实例信息
changeParameterNotifyRequest.getIdentify(),
// 核心线程数
changeParameterNotifyRequest.getBeforeCorePoolSize() + " ➲ " + changeParameterNotifyRequest.getNowCorePoolSize(),
// 最大线程数
changeParameterNotifyRequest.getBeforeMaximumPoolSize() + " ➲ " + changeParameterNotifyRequest.getNowMaximumPoolSize(),
// 核心线程超时
changeParameterNotifyRequest.getBeforeAllowsCoreThreadTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 线程存活时间
changeParameterNotifyRequest.getBeforeKeepAliveTime() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 阻塞队列
changeParameterNotifyRequest.getBlockingQueueName(),
// 阻塞队列容量
changeParameterNotifyRequest.getBeforeQueueCapacity() + " ➲ " + changeParameterNotifyRequest.getNowQueueCapacity(),
// 拒绝策略
changeParameterNotifyRequest.getBeforeRejectedName(),
changeParameterNotifyRequest.getNowRejectedName(),
// 告警手机号
afterReceives,
// 当前时间
DateUtil.now()
);
execute(changeParameterNotifyRequest.getSecretKey(), text);
}
/**
* Execute.
*
* @param secretKey
* @param text
*/
private void execute(String secretKey, String text) {
String serverUrl = WE_CHAT_SERVER_URL + secretKey;
try {
WeChatReqDTO weChatReq = new WeChatReqDTO();
weChatReq.setMsgtype("markdown");
Markdown markdown = new Markdown();
markdown.setContent(text);
weChatReq.setMarkdown(markdown);
HttpRequest.post(serverUrl).body(JSONUtil.toJSONString(weChatReq)).execute();
} catch (Exception ex) {
log.error("WeChat failed to send message", ex);
}
}
@Data
@Accessors(chain = true)
public static class WeChatReqDTO {
/**
* msgType
*/
private String msgtype;
/**
* markdown
*/
private Markdown markdown;
}
@Data
public static class Markdown {
/**
* content
*/
private String content;
}
}

@ -0,0 +1,55 @@
package cn.hippo4j.common.notify.request;
import cn.hippo4j.common.notify.NotifyTypeEnum;
import lombok.Data;
/**
* Alarm notify request.
*
* @author chen.ma
* @date 2022/2/22 19:41
*/
@Data
public class AlarmNotifyRequest extends BaseNotifyRequest {
/**
* interval
*/
private Integer interval;
/**
* notifyTypeEnum
*/
private NotifyTypeEnum notifyTypeEnum;
private String active;
private String appName;
private String identify;
private Integer corePoolSize;
private Integer maximumPoolSize;
private Integer poolSize;
private Integer activeCount;
private Integer largestPoolSize;
private Long completedTaskCount;
private String queueName;
private Integer capacity;
private Integer queueSize;
private Integer remainingCapacity;
private String rejectedExecutionHandlerName;
private Long rejectCountNum;
}

@ -0,0 +1,44 @@
package cn.hippo4j.common.notify.request;
import lombok.Data;
/**
* Base notify request.
*
* @author chen.ma
* @date 2022/2/22 19:35
*/
@Data
public class BaseNotifyRequest implements NotifyRequest {
/**
* tenantId
*/
private String tenantId;
/**
* itemId
*/
private String itemId;
/**
* threadPoolId
*/
private String threadPoolId;
/**
* platform
*/
private String platform;
/**
* type
*/
private String type;
/**
* receives
*/
private String receives;
}

@ -0,0 +1,46 @@
package cn.hippo4j.common.notify.request;
import lombok.Data;
/**
* Change parameter notify request.
*
* @author chen.ma
* @date 2022/2/22 20:22
*/
@Data
public class ChangeParameterNotifyRequest extends BaseNotifyRequest {
private String active;
private String appName;
private String identify;
private Integer beforeCorePoolSize;
private Integer nowCorePoolSize;
private Integer beforeMaximumPoolSize;
private Integer nowMaximumPoolSize;
private Boolean beforeAllowsCoreThreadTimeOut;
private Boolean nowAllowsCoreThreadTimeOut;
private Long beforeKeepAliveTime;
private Long nowKeepAliveTime;
private String blockingQueueName;
private Integer beforeQueueCapacity;
private Integer nowQueueCapacity;
private String beforeRejectedName;
private String nowRejectedName;
}

@ -0,0 +1,10 @@
package cn.hippo4j.common.notify.request;
/**
* Notify request.
*
* @author chen.ma
* @date 2022/2/22 19:38
*/
public interface NotifyRequest {
}

@ -0,0 +1,19 @@
package cn.hippo4j.common.notify.request;
import lombok.Data;
/**
* Robot alarm notify request.
*
* @author chen.ma
* @date 2022/2/22 21:50
*/
@Data
public class RobotAlarmNotifyRequest extends AlarmNotifyRequest {
/**
* secretKey
*/
private String secretKey;
}

@ -0,0 +1,19 @@
package cn.hippo4j.common.notify.request;
import lombok.Data;
/**
* Robot change parameter notify request.
*
* @author chen.ma
* @date 2022/2/22 21:03
*/
@Data
public class RobotChangeParameterNotifyRequest extends ChangeParameterNotifyRequest {
/**
* secretKey
*/
private String secretKey;
}

@ -2,6 +2,8 @@ package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.function.Matcher;
import java.lang.reflect.Array;
/**
* Array util.
*
@ -53,4 +55,48 @@ public class ArrayUtil {
return null;
}
/**
* Add all.
*
* @param array1
* @param array2
* @param <T>
* @return
*/
public static <T> T[] addAll(final T[] array1, @SuppressWarnings("unchecked") final T... array2) {
if (array1 == null) {
return clone(array2);
} else if (array2 == null) {
return clone(array1);
}
final Class<?> type1 = array1.getClass().getComponentType();
@SuppressWarnings("unchecked") final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
try {
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
} catch (final ArrayStoreException ase) {
final Class<?> type2 = array2.getClass().getComponentType();
if (!type1.isAssignableFrom(type2)) {
throw new IllegalArgumentException("Cannot store " + type2.getName() + " in an array of "
+ type1.getName(), ase);
}
throw ase;
}
return joinedArray;
}
/**
* Clone.
*
* @param array
* @param <T>
* @return
*/
public static <T> T[] clone(final T[] array) {
if (array == null) {
return null;
}
return array.clone();
}
}

@ -0,0 +1,43 @@
package cn.hippo4j.common.toolkit;
/**
* Thread util.
*
* @author chen.ma
* @date 2021/12/6 23:34
*/
public class ThreadUtil {
/**
* 线.
*
* @param runnable {@link Runnable}
* @param name 线
* @param isDaemon 线
* @return {@link Thread}
*/
public static Thread newThread(Runnable runnable, String name, boolean isDaemon) {
Thread t = new Thread(null, runnable, name);
t.setDaemon(isDaemon);
return t;
}
/**
* 线.
*
* @param millis
* @return
*/
public static boolean sleep(long millis) {
if (millis > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
return false;
}
}
return true;
}
}
Loading…
Cancel
Save