use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
the class DtpLarkNotifier method sendChangeMsg.
@Override
public void sendChangeMsg(DtpMainProp oldProp, List<String> diffs) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.LARK.name());
String content = buildNoticeContent(platform, LARK_CHANGE_NOTICE_JSON_STR, oldProp, diffs);
if (StringUtils.isBlank(content)) {
return;
}
doSend(platform, content);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by dromara.
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 dromara.
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 refresh, main properties of [{}] have not changed.", executor.getThreadPoolName());
return;
}
List<FieldInfo> diffFields = EQUATOR.getDiffFields(oldProp, newProp);
List<String> diffKeys = diffFields.stream().map(FieldInfo::getFieldName).collect(toList());
log.info("DynamicTp refresh, name: [{}], 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 lyh200.
the class AlarmManager method doAlarm.
public static void doAlarm(DtpExecutor executor, NotifyTypeEnum typeEnum) {
boolean triggerCondition = false;
if (typeEnum == NotifyTypeEnum.REJECT) {
triggerCondition = checkReject(executor);
} else if (typeEnum == NotifyTypeEnum.CAPACITY) {
triggerCondition = checkCapacity(executor);
} else if (typeEnum == NotifyTypeEnum.LIVENESS) {
triggerCondition = checkLiveness(executor);
}
if (!triggerCondition) {
return;
}
boolean ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
if (!ifAlarm) {
log.warn("DynamicTp notify, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
return;
}
DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, typeEnum);
DtpContext dtpContext = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).build();
DtpContextHolder.set(dtpContext);
AlarmLimiter.putVal(executor, typeEnum.getValue());
NotifierHandler.getInstance().sendAlarm(typeEnum);
}
use of com.dtp.core.context.DtpContext in project dynamic-tp by lyh200.
the class DtpDingNotifier method sendChangeMsg.
@Override
public void sendChangeMsg(DtpMainProp oldProp, List<String> diffs) {
DtpContext contextWrapper = DtpContextHolder.get();
NotifyPlatform platform = contextWrapper.getPlatform(NotifyPlatformEnum.DING.name());
String content = buildNoticeContent(platform, DING_CHANGE_NOTICE_TEMPLATE, oldProp, diffs);
if (StringUtils.isBlank(content)) {
return;
}
List<String> receivesList = StrUtil.split(platform.getReceivers(), ',');
doSend(platform, DING_NOTICE_TITLE, content, receivesList);
}
Aggregations