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());
}
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);
}
}
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);
});
}
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;
}
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);
}
Aggregations