use of com.dtp.core.context.DtpContext in project dynamic-tp by lyh200.
the class DtpWechatNotifier method sendChangeMsg.
@Override
public void sendChangeMsg(DtpMainProp oldProp, List<String> diffs) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.WECHAT.name());
String content = buildNoticeContent(platform, WECHAT_CHANGE_NOTICE_TEMPLATE, oldProp, diffs);
if (StringUtils.isBlank(content)) {
return;
}
doSend(platform, content);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by lyh200.
the class AbstractNotifier method buildAlarmContent.
public String buildAlarmContent(NotifyPlatform platform, NotifyTypeEnum typeEnum, String template) {
DtpContext contextWrapper = DtpContextHolder.get();
String dtpName = contextWrapper.getDtpExecutor().getThreadPoolName();
DtpExecutor executor = DtpRegistry.getExecutor(dtpName);
List<String> receivers = StrUtil.split(platform.getReceivers(), ',');
String receivesStr = Joiner.on(", @").join(receivers);
NotifyItem notifyItem = contextWrapper.getNotifyItem();
String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), executor.getThreadPoolName(), typeEnum.getValue(), notifyItem.getThreshold(), executor.getCorePoolSize(), executor.getMaximumPoolSize(), executor.getPoolSize(), executor.getActiveCount(), executor.getLargestPoolSize(), executor.getTaskCount(), executor.getCompletedTaskCount(), executor.getQueue().size(), executor.getQueueName(), executor.getQueueCapacity(), executor.getQueue().size(), executor.getQueue().remainingCapacity(), executor.getRejectHandlerName(), executor.getRejectCount(), receivesStr, DateUtil.now(), notifyItem.getInterval());
return highlightAlarmContent(content, typeEnum);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by lyh200.
the class DtpDingNotifier method sendAlarmMsg.
@Override
public void sendAlarmMsg(NotifyTypeEnum typeEnum) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.DING.name());
String content = buildAlarmContent(platform, typeEnum, DING_ALARM_TEMPLATE);
if (StringUtils.isBlank(content)) {
return;
}
List<String> receivesList = StrUtil.split(platform.getReceivers(), ',');
doSend(platform, DingNotifyConst.DING_ALARM_TITLE, content, receivesList);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by lyh200.
the class DtpRegistry method refresh.
private static void refresh(DtpExecutor executor, ThreadPoolProperties properties) {
if (properties.getCorePoolSize() < 0 || properties.getMaximumPoolSize() <= 0 || properties.getMaximumPoolSize() < properties.getCorePoolSize() || properties.getKeepAliveTime() < 0) {
log.error("DynamicTp refresh, invalid parameters exist, properties: {}", properties);
return;
}
DtpMainProp oldProp = ExecutorConverter.convert(executor);
doRefresh(executor, properties);
DtpMainProp newProp = ExecutorConverter.convert(executor);
if (oldProp.equals(newProp)) {
log.warn("DynamicTp [{}] has no properties changed.", executor.getThreadPoolName());
return;
}
List<FieldInfo> diffFields = EQUATOR.getDiffFields(oldProp, newProp);
List<String> diffKeys = diffFields.stream().map(FieldInfo::getFieldName).collect(Collectors.toList());
log.info("DynamicTp [{}] refreshed end, changed keys: {}, corePoolSize: [{}], maxPoolSize: [{}], " + "queueType: [{}], queueCapacity: [{}], keepAliveTime: [{}], rejectedType: [{}], " + "allowsCoreThreadTimeOut: [{}]", executor.getThreadPoolName(), diffKeys, String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getCorePoolSize(), newProp.getCorePoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getMaxPoolSize(), newProp.getMaxPoolSize()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueType(), newProp.getQueueType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getQueueCapacity(), newProp.getQueueCapacity()), String.format("%ss => %ss", oldProp.getKeepAliveTime(), newProp.getKeepAliveTime()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.getRejectType(), newProp.getRejectType()), String.format(DynamicTpConst.PROPERTIES_CHANGE_SHOW_STYLE, oldProp.isAllowCoreThreadTimeOut(), newProp.isAllowCoreThreadTimeOut()));
val notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.CHANGE);
boolean ifNotice = CollUtil.isNotEmpty(dtpProperties.getPlatforms()) && Objects.nonNull(notifyItem) && notifyItem.isEnabled();
if (!ifNotice) {
return;
}
DtpContext context = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).build();
DtpContextHolder.set(context);
NOTIFY_EXECUTOR.execute(() -> NotifierHandler.getInstance().sendNotice(oldProp, diffKeys));
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class DtpDingNotifier method sendAlarmMsg.
@Override
public void sendAlarmMsg(NotifyTypeEnum typeEnum) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.DING.name());
String content = buildAlarmContent(platform, typeEnum, DING_ALARM_TEMPLATE);
if (StringUtils.isBlank(content)) {
return;
}
List<String> receivesList = StrUtil.split(platform.getReceivers(), ',');
doSend(platform, DingNotifyConst.DING_ALARM_TITLE, content, receivesList);
}
Aggregations