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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 在阿里云申请商标注册步骤详细教程视频_阿里云商标注册不予处理

    在阿里云申请商标注册步骤详细教程视频_阿里云商标注册不予处理近年来国内商标注册申请量的迅猛增长,然而,并不是你申请商标就能下来,很多情况下,你申请的商标,很有可能会失败,而且申请的费用就打水漂了。说白了就是,你申请商标的钱,不会因为你申请商标的失败,还会再退给

    2022年8月6日
    7
  • idea 2022 Mac 激活码【中文破解版】

    (idea 2022 Mac 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html4KDDGND3CI-eyJsaWN…

    2022年4月1日
    465
  • java建立http_java-创建一个HttpEntity

    java建立http_java-创建一个HttpEntity我正在尝试更新到 com loopj android android async http 的最新版本 1 4 9 其中 org apache http 被 cz msebera android httpclient 取代了 目前 我使用 StringEntity newStringEnt somedata client post static context getAb

    2025年6月13日
    4
  • 2015智能家居市场十大收购案

    2015智能家居市场十大收购案一方面,由于智能家居行业发展前景的无可**,大企业纷纷拓展智能家居业务;另一方面,资本寒冬来袭,小型智能家居企业纷纷求抱大腿。一时间,智能家居行业收购案频频发生。此等收购案背后真正企图是什么?又会给智能家居行业的发展带来哪些影响?  高通24亿美元收购英国CSR进军智能家居2015年8月13日,全球最大智能手机芯片供应商高通正式宣布以24亿美元完成对…

    2022年6月22日
    26
  • mac 安装jboss[通俗易懂]

    mac 安装jboss[通俗易懂]mac安装jboss

    2022年10月3日
    2
  • phpproxy建立代理服务器_proxy设计模式

    phpproxy建立代理服务器_proxy设计模式代理,指的就是一个角色代表另一个角色采取行动,就象生活中,一个红酒厂商,是不会直接把红酒零售客户的,都是通过代理来完成他的销售业务。而客户,也不用为了喝红酒而到处找工厂,他只要找到厂商在当地的代理就行了,具体红酒工厂在那里,客户不用关心,代理会帮他处理。代理模式,就是给某一对象提供代理对象,并由代理对象控制具体对象的引用。代理模式涉及的角色:抽象主题角色,声明了代理主题和真实主题的公共…

    2025年6月26日
    4

发表回复

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

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