Search in sources :

Example 1 with AlarmInfo

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

the class AlarmManager method doAlarm.

public static void doAlarm(DtpExecutor executor, NotifyTypeEnum typeEnum) {
    if (!preCheck(executor, typeEnum)) {
        return;
    }
    boolean ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
    if (!ifAlarm) {
        log.debug("DynamicTp notify, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
        return;
    }
    DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
    NotifyItem notifyItem = NotifyHelper.getNotifyItem(executor, typeEnum);
    if (Objects.isNull(notifyItem)) {
        return;
    }
    synchronized (SEND_LOCK) {
        // recheck alarm limit.
        ifAlarm = AlarmLimiter.ifAlarm(executor, typeEnum.getValue());
        if (!ifAlarm) {
            log.warn("DynamicTp notify, concurrent send, alarm limit, dtpName: {}, type: {}", executor.getThreadPoolName(), typeEnum.getValue());
            return;
        }
        AlarmLimiter.putVal(executor, typeEnum.getValue());
    }
    AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executor.getThreadPoolName(), notifyItem.getType());
    DtpContext dtpContext = DtpContext.builder().dtpExecutor(executor).platforms(dtpProperties.getPlatforms()).notifyItem(notifyItem).alarmInfo(alarmInfo).build();
    DtpContextHolder.set(dtpContext);
    NotifierHandler.getInstance().sendAlarm(typeEnum);
    AlarmCounter.reset(executor.getThreadPoolName(), notifyItem.getType());
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) DtpContext(com.dtp.core.context.DtpContext) DtpProperties(com.dtp.common.config.DtpProperties) AlarmInfo(com.dtp.common.dto.AlarmInfo)

Example 2 with AlarmInfo

use of com.dtp.common.dto.AlarmInfo 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 3 with AlarmInfo

use of com.dtp.common.dto.AlarmInfo 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 4 with AlarmInfo

use of com.dtp.common.dto.AlarmInfo 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)

Aggregations

AlarmInfo (com.dtp.common.dto.AlarmInfo)4 NotifyItem (com.dtp.common.dto.NotifyItem)4 DtpProperties (com.dtp.common.config.DtpProperties)1 DtpContext (com.dtp.core.context.DtpContext)1