use of com.usthe.collector.dispatch.timer.Timeout in project hertzbeat by dromara.
the class CommonDispatcher method dispatchCollectData.
@Override
public void dispatchCollectData(Timeout timeout, Metrics metrics, CollectRep.MetricsData metricsData) {
WheelTimerTask timerJob = (WheelTimerTask) timeout.task();
Job job = timerJob.getJob();
metricsTimeoutMonitorMap.remove(job.getId() + "-" + metrics.getName());
Set<Metrics> metricsSet = job.getNextCollectMetrics(metrics, false);
if (job.isCyclic()) {
// If it is an asynchronous periodic cyclic task, directly send the collected data of the indicator group to the message middleware
// 若是异步的周期性循环任务,直接发送指标组的采集数据到消息中间件
kafkaDataExporter.send(metricsData);
// 或判断采集指标组是否优先级为0,即为可用性采集指标组 若可用性采集失败 则取消后面的指标组调度直接进入下一轮调度
if (metricsSet == null || (metrics.getPriority() == (byte) 0 && metricsData.getCode() != CollectRep.Code.SUCCESS)) {
// 先判断此次任务执行时间与任务采集间隔时间
if (timeout.isCancelled()) {
return;
}
long spendTime = System.currentTimeMillis() - job.getDispatchTime();
long interval = job.getInterval() - spendTime / 1000;
interval = interval <= 0 ? 0 : interval;
// Reset Construction Execution Metrics Group View 重置构造执行指标组视图
job.constructPriorMetrics();
timerDispatch.cyclicJob(timerJob, interval, TimeUnit.SECONDS);
} else if (!metricsSet.isEmpty()) {
// The execution of the current level indicator group is completed, and the execution of the next level indicator group starts
// 当前级别指标组执行完成,开始执行下一级别的指标组
metricsSet.forEach(metricItem -> {
MetricsCollect metricsCollect = new MetricsCollect(metricItem, timeout, this);
jobRequestQueue.addJob(metricsCollect);
metricsTimeoutMonitorMap.put(job.getId() + "-" + metricItem.getName(), new MetricsTime(System.currentTimeMillis(), metricItem, timeout));
});
} else {
// The list of indicator groups at the current execution level has not been fully executed.
// It needs to wait for the execution of other indicator groups of the same level to complete the execution and enter the next level for execution.
// 当前执行级别的指标组列表未全执行完成,
// 需等待其它同级别指标组执行完成后进入下一级别执行
}
} else {
// If it is a temporary one-time task, you need to wait for the collected data of all indicator groups to be packaged and returned.
// Insert the current indicator group data into the job for unified assembly
// 若是临时性一次任务,需等待所有指标组的采集数据统一包装返回
// 将当前指标组数据插入job里统一组装
job.addCollectMetricsData(metricsData);
if (metricsSet == null) {
// The collection and execution of all indicator groups of this job are completed
// and the result listener is notified of the combination of all indicator group data
// 此Job所有指标组采集执行完成
// 将所有指标组数据组合一起通知结果监听器
timerDispatch.responseSyncJobData(job.getId(), job.getResponseDataTemp());
} else if (!metricsSet.isEmpty()) {
// The execution of the current level indicator group is completed, and the execution of the next level indicator group starts
// 当前级别指标组执行完成,开始执行下一级别的指标组
metricsSet.forEach(metricItem -> {
MetricsCollect metricsCollect = new MetricsCollect(metricItem, timeout, this);
jobRequestQueue.addJob(metricsCollect);
metricsTimeoutMonitorMap.put(job.getId() + "-" + metricItem.getName(), new MetricsTime(System.currentTimeMillis(), metricItem, timeout));
});
} else {
// The list of indicator groups at the current execution level has not been fully executed.
// It needs to wait for the execution of other indicator groups of the same level to complete the execution and enter the next level for execution.
// 当前执行级别的指标组列表未全执行完成,
// 需等待其它同级别指标组执行完成后进入下一级别执行
}
}
}
Aggregations