Search in sources :

Example 1 with WheelTimerTask

use of com.usthe.collector.dispatch.timer.WheelTimerTask 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.
        // 当前执行级别的指标组列表未全执行完成,
        // 需等待其它同级别指标组执行完成后进入下一级别执行
        }
    }
}
Also used : Timeout(com.usthe.collector.dispatch.timer.Timeout) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) MetricsDataExporter(com.usthe.collector.dispatch.export.MetricsDataExporter) TimeUnit(java.util.concurrent.TimeUnit) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) WheelTimerTask(com.usthe.collector.dispatch.timer.WheelTimerTask) Job(com.usthe.common.entity.job.Job) Map(java.util.Map) Data(lombok.Data) TimerDispatch(com.usthe.collector.dispatch.timer.TimerDispatch) AllArgsConstructor(lombok.AllArgsConstructor) CollectRep(com.usthe.common.entity.message.CollectRep) Metrics(com.usthe.common.entity.job.Metrics) Metrics(com.usthe.common.entity.job.Metrics) WheelTimerTask(com.usthe.collector.dispatch.timer.WheelTimerTask) Job(com.usthe.common.entity.job.Job)

Example 2 with WheelTimerTask

use of com.usthe.collector.dispatch.timer.WheelTimerTask in project hertzbeat by dromara.

the class CommonDispatcher method dispatchMetricsTask.

@Override
public void dispatchMetricsTask(Timeout timeout) {
    // Divide the collection task of a single application into corresponding collection tasks of the indicator group according to the indicator group under it. AbstractCollect
    // Put each indicator group into the thread pool for scheduling
    // 将单个应用的采集任务根据其下的指标组拆分为对应的指标组采集任务 AbstractCollect
    // 将每个指标组放入线程池进行调度
    WheelTimerTask timerTask = (WheelTimerTask) timeout.task();
    Job job = timerTask.getJob();
    job.constructPriorMetrics();
    Set<Metrics> metricsSet = job.getNextCollectMetrics(null, true);
    metricsSet.forEach(metrics -> {
        MetricsCollect metricsCollect = new MetricsCollect(metrics, timeout, this);
        jobRequestQueue.addJob(metricsCollect);
        metricsTimeoutMonitorMap.put(job.getId() + "-" + metrics.getName(), new MetricsTime(System.currentTimeMillis(), metrics, timeout));
    });
}
Also used : Metrics(com.usthe.common.entity.job.Metrics) WheelTimerTask(com.usthe.collector.dispatch.timer.WheelTimerTask) Job(com.usthe.common.entity.job.Job)

Aggregations

WheelTimerTask (com.usthe.collector.dispatch.timer.WheelTimerTask)2 Job (com.usthe.common.entity.job.Job)2 Metrics (com.usthe.common.entity.job.Metrics)2 MetricsDataExporter (com.usthe.collector.dispatch.export.MetricsDataExporter)1 Timeout (com.usthe.collector.dispatch.timer.Timeout)1 TimerDispatch (com.usthe.collector.dispatch.timer.TimerDispatch)1 CollectRep (com.usthe.common.entity.message.CollectRep)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Component (org.springframework.stereotype.Component)1