源碼分析ElasticJob 啓動流程
本篇文章重點講解 ElasticJob 啓動加載過程
ElasticJob 加載方法如下
CoordinatorRegistryCenter regCenter = setUpRegistryCenter();
//創建JobEvent配置對象
JobEventConfiguration jobConfig = new JobEventRdbConfiguration(null);
//設置simpleJob拼裝
simpleJob(regCenter, jobConfig );
//設置setUpDataflowJob拼裝
setUpDataflowJob(regCenter, jobConfig );
JobCoreConfiguration coreConfig =JobCoreConfiguration.newBuilder(“simpleJob”, “時間”,
shardingItemParameters(“分片規則”).build();
SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig,
JavaSimpleJob.class.getCanonicalName());
new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(simpleJobConfig).build(),
jobEventConfig).init();
作業註冊到Zookeeper之前,會將job任務統一存儲到註冊器JobRegistry,即託管所有
job的註冊信息,而jobScheduler用於作業控制器,通過setUpSimpleJob、setUpDataflowJob不同類型的作業執行拼裝後,將相關參數、服務配置拼裝到jobScheduler對象中。init()方法執行如下
LiteJobConfiguration liteJobConfigFromRegCenter =
schedulerFacade.updateJobConfiguration(liteJobConfig);
JobRegistry.getInstance().setCurrentShardingTotalCount(liteJobConfigFromRegCenter.getJobName(),
liteJobConfigFromRegCenter.getTypeConfig().getCoreConfig().getShardingTotalCount());
JobScheduleController jobScheduleController = new JobScheduleController( createScheduler(),
createJobDetail(liteJobConfigFromRegCenter.getTypeConfig().getJobClass()),
liteJobConfigFromRegCenter.getJobName());
JobRegistry.getInstance().registerJob(liteJobConfigFromRegCenter.getJobName(),
jobScheduleController, regCenter);
schedulerFacade.registerStartUpInfo(!liteJobConfigFromRegCenter.isDisabled());
jobScheduleController.scheduleJob(liteJobConfigFromRegCenter.getTypeConfig().getCoreConfig().getCron());
啓動 主要處理流程如下
- job的配置信息通過scheduler傳遞給configService服務,並通過zookeeper保存或更新最新的配置信息
- 所有分片參數、配置規則由 JobRegistry管理提供
- 根據配置中心去check是否正常加載選主節點、服務監控
- JobScheduleController ElasticJob自身接口
- scheduleJob主要啓動quartz的schedule
到此啓動完成
作者簡介:張程 技術研究
更多文章請關注微信公衆號:zachary分解獅 (frankly0423)