datax(12):调度源码解读AbstractScheduler「建议收藏」

datax(12):调度源码解读AbstractScheduler「建议收藏」datax的jobContainer最终会通过调度周期性的执行,今天把它看完;一、基类AbstractScheduler概述类继承关系全部方法二、AbstractScheduler的主要属性和方法1、主要属性/***脏数据行数检查器,用于运行中随时检查脏数据是否超过限制(脏数据行数,或脏数据百分比)*/privateErrorRecordCheckererrorLimit;/***积累容器通讯器,来处理JobContainer、Tas.

大家好,又见面了,我是你们的朋友全栈君。

datax的jobContainer最终会通过调度周期性的执行,今天把它看完;


一、基类AbstractScheduler概述

类继承关系
在这里插入图片描述

全部方法
在这里插入图片描述


二、AbstractScheduler的主要属性和方法

1、主要属性

  /** * 脏数据行数检查器,用于运行中随时检查脏数据是否超过限制(脏数据行数,或脏数据百分比) */
  private ErrorRecordChecker errorLimit;

  /** * 积累容器通讯器,来处理JobContainer、TaskGroupContainer和Task的通讯 */
  private AbstractContainerCommunicator containerCommunicator;

2、主要方法

  /** * 默认调度执行方法 <br> * 1 传入多个调度配置,获取报告时间+休息时间+jobId(赋值给全局jobId),生成错误记录检查类 * 2 给全局jobId赋值,生成错误记录检查类,生成容器通讯类(反馈任务信息) * 3 根据入参计算task的数量,开始所有taskGroup * * @param cfg List<Configuration> */
  public void schedule(List<Configuration> cfg) { 
   
    xxx
}
  /** * 开始所有的taskGroup,只允许本包的类访问 * * @param configurations List<Configuration> */
  protected abstract void startAllTaskGroup(List<Configuration> configurations);
 

三、谁调用AbstractScheduler的schedule

从JobContainer.schedule调用AbstractScheduler.schedule


四、schedule和startAllTaskGroup方法解析

schedule方法主要在AbstractScheduler实现
运行时序图

在这里插入图片描述

  /** * 默认调度执行方法 <br> * 1 传入多个调度配置,获取报告时间+休息时间+jobId(赋值给全局jobId),生成错误记录检查类 * 2 给全局jobId赋值,生成错误记录检查类,生成容器通讯类(反馈任务信息) * 3 根据入参计算task的数量,开始所有taskGroup * * @param cfg List<Configuration> */
  public void schedule(List<Configuration> cfg) { 
   
    Validate.notNull(cfg, "scheduler配置不能为空");
    int reportMillSec = cfg.get(0).getInt(DATAX_CORE_CONTAINER_JOB_REPORTINTERVAL, 30000);
    int sleepMillSec = cfg.get(0).getInt(DATAX_CORE_CONTAINER_JOB_SLEEPINTERVAL, 10000);

    this.jobId = cfg.get(0).getLong(CoreConstant.DATAX_CORE_CONTAINER_JOB_ID);
    errorLimit = new ErrorRecordChecker(cfg.get(0));
    //给 taskGroupContainer 的 Communication 注册
    this.containerCommunicator.registerCommunication(cfg);
    int taskCnt = calculateTaskCount(cfg);
    startAllTaskGroup(cfg);
    Communication lastComm = new Communication();
    long lastReportTimeStamp = System.currentTimeMillis();
    try { 
   
      while (true) { 
   
        /** * step 1: collect job stat * step 2: getReport info, then report it * step 3: errorLimit do check * step 4: dealSucceedStat(); * step 5: dealKillingStat(); * step 6: dealFailedStat(); * step 7: refresh last job stat, and then sleep for next while * * above steps, some ones should report info to DS * */
        Communication nowComm = this.containerCommunicator.collect();
        nowComm.setTimestamp(System.currentTimeMillis());
        LOG.debug(nowComm.toString());

        //汇报周期
        long now = System.currentTimeMillis();
        if (now - lastReportTimeStamp > reportMillSec) { 
   
          Communication comm = CommunicationTool.getReportCommunication(nowComm, lastComm, taskCnt);

          this.containerCommunicator.report(comm);
          lastReportTimeStamp = now;
          lastComm = nowComm;
        }

        errorLimit.checkRecordLimit(nowComm);
        if (nowComm.getState() == State.SUCCEEDED) { 
   
          LOG.info("Scheduler accomplished all tasks.");
          break;
        }

        if (isJobKilling(this.getJobId())) { 
   
          dealKillingStat(this.containerCommunicator, taskCnt);
        } else if (nowComm.getState() == State.FAILED) { 
   
          dealFailedStat(this.containerCommunicator, nowComm.getThrowable());
        }
        Thread.sleep(sleepMillSec);
      }
    } catch (InterruptedException e) { 
   
      // 以 failed 状态退出
      LOG.error("捕获到InterruptedException异常!", e);
      throw DataXException.asDataXException(FrameworkErrorCode.RUNTIME_ERROR, e);
    }
  }

startAllTaskGroup方法在ProcessInnerScheduler实现
运行时序图

在这里插入图片描述


  /** * 1、创建线程池 <br/> * 2、变量传入的cfgs,生成tgRunner,然后线程池执行 <br/> * 3、线程池关闭 <br/> * * @param cfgs List<Configuration> */
  @Override
  public void startAllTaskGroup(List<Configuration> cfgs) { 
   
    this.taskGroupContainerExecutorService = new ThreadPoolExecutor(cfgs.size(), cfgs.size(),
        0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
    for (Configuration taskGroupCfg : cfgs) { 
   
      TaskGroupContainerRunner taskGroupContainerRunner = newTaskGroupContainerRunner(taskGroupCfg);
      this.taskGroupContainerExecutorService.execute(taskGroupContainerRunner);
    }
    this.taskGroupContainerExecutorService.shutdown();
  }

注:

  1. 对源码进行略微改动,主要修改为 1 阿里代码规约扫描出来的,2 clean code;

  2. 所有代码都已经上传到github(master分支和dev),可以免费白嫖

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/145542.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • countdown timer plus_android studio计时器

    countdown timer plus_android studio计时器Inthisandroidcountdowntimerexample,we’llimplementatimerobjecttodisplaytheprogressinaProgressBar.Theapplicationwe’llbuildinthistutorialisausefulcomponentinQuizappswhere…

    2025年11月25日
    2
  • eclipse方法自动注释_eclipse快速补全

    eclipse方法自动注释_eclipse快速补全1、Eclipse自动补全功能设置,默认是键入“.”才会有代码提示,否则就只有按“Alt+/”组合键。通过下面的设置可以按照你自己的需求显示代码提示。1)、直接设置打开Eclipse->Window->Perferences->Java->Editor->ContentAssist,右边出现的选项中,有一个AutoactivationtriggersorforJava

    2022年10月9日
    2
  • BootStrap Validator入门

    BootStrap Validator入门目录官网使用效果认识 bootstrapval 初级用法简单使用官网官网 http bootstrapval com 源码下载地址 https github com nghuuphuoc bootstrapval 使用效果认识 bootstrapval 来看 bootstrapval 的描述 T

    2025年10月27日
    3
  • vue中watch的用法

    vue中watch的用法当 vue 项目中需要对某个值进行监听做一些操作的时候我们会用到 watch 进行监听 1 监听普通属性 单一字符串 布尔值 等等 data return dvid goodsInfo userInfo closeTime 0 关仓倒计时 watch closeTime newVal oldVal console log newVal oldVal

    2025年6月21日
    5
  • WEB/HTTP服务器搭建[通俗易懂]

    WEB/HTTP服务器搭建[通俗易懂]HTTP对于软件都有服务和客户,有服务端和客户端服务就是在操作系统运行一个或者多个程序,并为客户端提供相应所需的服务协议就是计算机网络中进行数据交换而建立的规则、标准或约定的集合。只有遵守这个约定,计算机之间才能相互通信交流。它的三要素是:语法、语义、时序。1.WEB服务器web服务器一般指网站服务器,他是一个驻留于Internet的一个计算机程序,用于向浏览器提供文档…

    2022年5月28日
    184
  • Matlab画图线型、符号及颜色汇总[通俗易懂]

    Matlab画图线型、符号及颜色汇总[通俗易懂]【1】线型、标记符、颜色的说明【2】对于坐标轴的注释内容xlabel,ylabel的属性说明figure,plot(Seg1,SS1_QJ1,’k’);holdonplot(Seg1,SS1_QJ1,’ks’)plot(Seg1,Q1*ones(length(Seg1)),’r’)xlabel(‘\bf{安装角}(°)’,’FontS…

    2022年5月31日
    70

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号