Search in sources :

Example 6 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class AlarmManager method checkReject.

private static boolean checkReject(DtpExecutor executor) {
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.REJECT);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executor.getThreadPoolName(), notifyItem.getType());
    int rejectCount = alarmInfo.getCount();
    return satisfyBaseCondition(notifyItem) && rejectCount >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) AlarmInfo(com.dtp.common.dto.AlarmInfo)

Example 7 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class AlarmManager method checkQueueTimeout.

private static boolean checkQueueTimeout(DtpExecutor executor) {
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.QUEUE_TIMEOUT);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executor.getThreadPoolName(), notifyItem.getType());
    int queueTimeoutTaskCount = alarmInfo.getCount();
    return satisfyBaseCondition(notifyItem) && queueTimeoutTaskCount >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) AlarmInfo(com.dtp.common.dto.AlarmInfo)

Example 8 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class AlarmManager method checkLiveness.

private static boolean checkLiveness(DtpExecutor executor) {
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.LIVENESS);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    int maximumPoolSize = executor.getMaximumPoolSize();
    double div = NumberUtil.div(executor.getActiveCount(), maximumPoolSize, 2) * 100;
    return satisfyBaseCondition(notifyItem) && div >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Example 9 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class AlarmManager method checkRunTimeout.

private static boolean checkRunTimeout(DtpExecutor executor) {
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, NotifyTypeEnum.RUN_TIMEOUT);
    if (Objects.isNull(notifyItem)) {
        return false;
    }
    AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executor.getThreadPoolName(), notifyItem.getType());
    int runTimeoutTaskCount = alarmInfo.getCount();
    return satisfyBaseCondition(notifyItem) && runTimeoutTaskCount >= notifyItem.getThreshold();
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) AlarmInfo(com.dtp.common.dto.AlarmInfo)

Example 10 with NotifyItem

use of com.dtp.common.dto.NotifyItem in project dynamic-tp by dromara.

the class NotifyHelper method updateNotifyItems.

public static void updateNotifyItems(DtpExecutor executor, DtpProperties dtpProperties, ThreadPoolProperties tpp) {
    if (CollUtil.isEmpty(dtpProperties.getPlatforms())) {
        executor.setNotifyItems(Collections.emptyList());
        return;
    }
    fillPlatforms(dtpProperties.getPlatforms(), tpp.getNotifyItems());
    List<NotifyItem> oldNotifyItems = executor.getNotifyItems();
    Map<String, NotifyItem> oldNotifyItemMap = StreamUtil.toMap(oldNotifyItems, NotifyItem::getType);
    tpp.getNotifyItems().forEach(x -> {
        NotifyItem oldNotifyItem = oldNotifyItemMap.get(x.getType());
        if (Objects.nonNull(oldNotifyItem) && oldNotifyItem.getInterval() == x.getInterval()) {
            return;
        }
        AlarmLimiter.initAlarmLimiter(executor.getThreadPoolName(), x);
        AlarmCounter.init(executor.getThreadPoolName(), x.getType());
    });
    executor.setNotifyItems(tpp.getNotifyItems());
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem)

Aggregations

NotifyItem (com.dtp.common.dto.NotifyItem)15 AlarmInfo (com.dtp.common.dto.AlarmInfo)4 DtpProperties (com.dtp.common.config.DtpProperties)3 DtpContext (com.dtp.core.context.DtpContext)3 DtpExecutor (com.dtp.core.thread.DtpExecutor)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ThreadPoolProperties (com.dtp.common.config.ThreadPoolProperties)1 NotifyPlatform (com.dtp.common.dto.NotifyPlatform)1 NotifyTypeEnum (com.dtp.common.em.NotifyTypeEnum)1 StreamUtil (com.dtp.common.util.StreamUtil)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1