use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by dromara.
the class AbstractNotifier method buildAlarmContent.
public String buildAlarmContent(NotifyPlatform platform, NotifyTypeEnum typeEnum, String template) {
DtpContext contextWrapper = DtpContextHolder.get();
String dtpName = contextWrapper.getDtpExecutor().getThreadPoolName();
DtpExecutor executor = DtpRegistry.getDtpExecutor(dtpName);
String receivesStr = getReceives(platform.getPlatform(), platform.getReceivers());
NotifyItem notifyItem = contextWrapper.getNotifyItem();
AlarmInfo alarmInfo = contextWrapper.getAlarmInfo();
val triple = AlarmCounter.countNotifyItems(dtpName);
String content = String.format(template, getInstance().getServiceName(), getInstance().getIp() + ":" + getInstance().getPort(), getInstance().getEnv(), populatePoolName(executor), typeEnum.getValue(), notifyItem.getThreshold(), executor.getCorePoolSize(), executor.getMaximumPoolSize(), executor.getPoolSize(), executor.getActiveCount(), executor.getLargestPoolSize(), executor.getTaskCount(), executor.getCompletedTaskCount(), executor.getQueue().size(), executor.getQueueName(), executor.getQueueCapacity(), executor.getQueue().size(), executor.getQueue().remainingCapacity(), executor.getRejectHandlerName(), triple.getLeft() + "/" + executor.getRejectCount(), triple.getMiddle() + "/" + executor.getRunTimeoutCount(), triple.getRight() + "/" + executor.getQueueTimeoutCount(), alarmInfo.getLastAlarmTime() == null ? UNKNOWN : alarmInfo.getLastAlarmTime(), DateUtil.now(), receivesStr, notifyItem.getInterval());
return highlightAlarmContent(content, typeEnum);
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by lyh200.
the class RejectedAware method beforeReject.
/**
* Do sth before reject.
* @param executor ThreadPoolExecutor instance
*/
default void beforeReject(ThreadPoolExecutor executor) {
if (executor instanceof DtpExecutor) {
DtpExecutor dtpExecutor = (DtpExecutor) executor;
dtpExecutor.incRejectCount(1);
AlarmManager.triggerAlarm(() -> AlarmManager.doAlarm(dtpExecutor, NotifyTypeEnum.REJECT));
}
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by lyh200.
the class DtpEndpoint method invoke.
@ReadOperation
public List<Metrics> invoke() {
List<String> dtpNames = DtpRegistry.listAllDtpNames();
List<Metrics> metricsList = Lists.newArrayList();
dtpNames.forEach(x -> {
DtpExecutor executor = DtpRegistry.getExecutor(x);
metricsList.add(MetricsConverter.convert(executor));
});
JvmStats jvmStats = new JvmStats();
RuntimeInfo runtimeInfo = new RuntimeInfo();
jvmStats.setMaxMemory(FileUtil.readableFileSize(runtimeInfo.getMaxMemory()));
jvmStats.setTotalMemory(FileUtil.readableFileSize(runtimeInfo.getTotalMemory()));
jvmStats.setFreeMemory(FileUtil.readableFileSize(runtimeInfo.getFreeMemory()));
jvmStats.setUsableMemory(FileUtil.readableFileSize(runtimeInfo.getUsableMemory()));
metricsList.add(jvmStats);
return metricsList;
}
use of com.dtp.core.thread.DtpExecutor in project dynamic-tp by lyh200.
the class TestController method task.
public void task() throws InterruptedException {
DtpExecutor dtpExecutor1 = DtpRegistry.getExecutor("dynamic-tp-test-1");
DtpExecutor dtpExecutor2 = DtpRegistry.getExecutor("dynamic-tp-test-2");
for (int i = 0; i < 100; i++) {
Thread.sleep(100);
dtpExecutor1.execute(() -> {
log.info("i am dynamic-tp-test-1 task");
});
dtpExecutor2.execute(() -> {
log.info("i am dynamic-tp-test-2 task");
});
}
}
Aggregations