Search in sources :

Example 6 with DtpProperties

use of com.dtp.common.config.DtpProperties 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 7 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class AbstractWebServerDtpHandler method onApplicationEvent.

@Override
public void onApplicationEvent(ServletWebServerInitializedEvent event) {
    try {
        DtpProperties dtpProperties = ApplicationContextHolder.getBean(DtpProperties.class);
        updateTp(dtpProperties);
    } catch (Exception e) {
        log.error("Init web server thread pool failed.", e);
    }
}
Also used : DtpProperties(com.dtp.common.config.DtpProperties)

Example 8 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class DtpBeanDefinitionRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    DtpProperties dtpProperties = new DtpProperties();
    PropertiesBinder.bindDtpProperties(environment, dtpProperties);
    val executors = dtpProperties.getExecutors();
    if (CollUtil.isEmpty(executors)) {
        log.warn("DynamicTp registrar, no executors are configured.");
        return;
    }
    executors.forEach(x -> {
        Class<?> executorTypeClass = ExecutorType.getClass(x.getExecutorType());
        String beanName = x.getThreadPoolName();
        Map<String, Object> properties = buildProperties(x);
        Object[] args = buildArgs(executorTypeClass, x);
        BeanUtil.registerIfAbsent(registry, beanName, executorTypeClass, properties, args);
    });
}
Also used : lombok.val(lombok.val) DtpProperties(com.dtp.common.config.DtpProperties)

Example 9 with DtpProperties

use of com.dtp.common.config.DtpProperties in project dynamic-tp by dromara.

the class CuratorUtil method getCuratorFramework.

public static CuratorFramework getCuratorFramework(DtpProperties dtpProperties) {
    if (curatorFramework == null) {
        DtpProperties.Zookeeper zookeeper = dtpProperties.getZookeeper();
        curatorFramework = CuratorFrameworkFactory.newClient(zookeeper.getZkConnectStr(), new ExponentialBackoffRetry(1000, 3));
        final ConnectionStateListener connectionStateListener = (client, newState) -> {
            if (newState == ConnectionState.CONNECTED) {
                COUNT_DOWN_LATCH.countDown();
            }
        };
        curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
        curatorFramework.start();
        try {
            COUNT_DOWN_LATCH.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
        }
    }
    return curatorFramework;
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) SneakyThrows(lombok.SneakyThrows) lombok.val(lombok.val) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener) ConfigHandler(com.dtp.core.handler.ConfigHandler) Maps(com.google.common.collect.Maps) StandardCharsets(java.nio.charset.StandardCharsets) ConnectionState(org.apache.curator.framework.state.ConnectionState) JSON(com.dtp.common.em.ConfigFileTypeEnum.JSON) CountDownLatch(java.util.concurrent.CountDownLatch) Slf4j(lombok.extern.slf4j.Slf4j) ZKPaths(org.apache.curator.utils.ZKPaths) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Map(java.util.Map) DtpProperties(com.dtp.common.config.DtpProperties) Collections(java.util.Collections) PROPERTIES(com.dtp.common.em.ConfigFileTypeEnum.PROPERTIES) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DtpProperties(com.dtp.common.config.DtpProperties) ConnectionStateListener(org.apache.curator.framework.state.ConnectionStateListener)

Example 10 with DtpProperties

use of com.dtp.common.config.DtpProperties 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);
}
Also used : NotifyItem(com.dtp.common.dto.NotifyItem) DtpContext(com.dtp.core.context.DtpContext) DtpProperties(com.dtp.common.config.DtpProperties)

Aggregations

DtpProperties (com.dtp.common.config.DtpProperties)11 NotifyItem (com.dtp.common.dto.NotifyItem)2 DtpContext (com.dtp.core.context.DtpContext)2 Slf4j (lombok.extern.slf4j.Slf4j)2 lombok.val (lombok.val)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ConnectionState (org.apache.curator.framework.state.ConnectionState)2 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)2 WebServerTpHandler (com.dtp.adapter.web.handler.WebServerTpHandler)1 AlarmInfo (com.dtp.common.dto.AlarmInfo)1 ThreadPoolStats (com.dtp.common.dto.ThreadPoolStats)1 JSON (com.dtp.common.em.ConfigFileTypeEnum.JSON)1 PROPERTIES (com.dtp.common.em.ConfigFileTypeEnum.PROPERTIES)1 ConfigHandler (com.dtp.core.handler.ConfigHandler)1 AbstractRefresher (com.dtp.core.refresh.AbstractRefresher)1 ZK_PROPERTY_SOURCE_NAME (com.dtp.starter.zookeeper.autoconfigure.ZkConfigEnvironmentProcessor.ZK_PROPERTY_SOURCE_NAME)1 CuratorUtil (com.dtp.starter.zookeeper.util.CuratorUtil)1 Maps (com.google.common.collect.Maps)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1