TBSchedule源码阅读1-TBScheduleManagerFactory
TBSchedule
1 TBScheduleManagerFactory 初始化
成员变量
ZKManager;
IScheduleDataManager;
ScheduleStrategyDataManager4ZK;
ManagerFactoryTimerTask; TimerTask
InitialThread 内部类
1.1 init 方法初始化
1.1.1读取schedule.xml 配置的 zookeeper
1.1.2 ConsoleManager.setScheduleManagerFactory(this);
1.1.3 this.zkManager = new ZKManager(p);
private void connect() throws Exception {
CountDownLatch connectionLatch = new CountDownLatch(1);
createZookeeper(connectionLatch);
connectionLatch.await(10,TimeUnit.SECONDS);
}
1.1.4 初始化相关信息
initialThread = new initialThread(this); 检测zookeeper状态,在Zk状态正常后回调数据初始化,初始化数据 initialData
initialThread.setName("TBScheduleManagerFactory-initialThread");
initialThread.start();
1.1.4.1 initialThread run方法:initialData
public void initialData() throws Exception{
this.zkManager.initial(); //创建根路径,设置版本信息
this.scheduleDataManager = new ScheduleDataManager4ZK(this.zkManager);//调度配置中心客户端接口,可以有基于数据库的实现,可以有基于ConfigServer的实现
this.scheduleStrategyManager = new ScheduleStrategyDataManager4ZK(this.zkManager);//调度策略
if (this.start == true) {
// 注册调度管理器
this.scheduleStrategyManager.registerManagerFactory(this);
if(timer == null){
timer = new Timer("TBScheduleManagerFactory-Timer");
}
if(timerTask == null){
timerTask = new ManagerFactoryTimerTask(this);//Zookeeper连接失败,关闭所有的任务后,重新连接Zookeeper服务器
timer.schedule(timerTask, 2000,this.timerInterval);
}
}
}
ScheduleDataManager4ZK :构造方法 zkManager
建立 根路径+/baseTaskType
获取 zookeeper 时间,同本地时间比较
ScheduleStrategyDataManager4ZK : 构造方法 zkManager
建立 根路径+/strategy
建立 根路径+/factory
注册调度管理器
根路径+/factory 写入TBScheduleManagerFactory 的id: ip+"$"+hostname+"$"+随机数
遍历根路径+/strategy,
如果//暂停或者不在IP范围 //添加可管理TaskType CreateMode.EPHEMERAL(断开连接节点就删除)
否则//清除原来注册的Factory
ManagerFactoryTimerTask : Zookeeper连接失败,关闭所有的任务后,重新连接Zookeeper服务器
1.2 zookeeper 路径
/tbSchedule/zmlTbScheduleTest[v.1][taobao-pamirs-schedule-3.0.0]
/tbSchedule/zmlTbScheduleTest/baseTaskType
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task[v.3][{"baseTaskType":"DBDemoSingle_task","heartBeatRate":5000,"judgeDeadInterval":60000,"sleepTimeNoData":500,"sleepTimeInterval":0,"fetchDataNumber":500,"executeNumber":1,"threadNumber":5,"processorType":"SLEEP","permitRunStartTime":"0 * * * * ?","expireOwnSignInterval":1.0,"dealBeanName":"demoTaskBean","taskParameter":"","taskKind":"static","taskItems":["1","2","3","4","5","6"],"maxTaskItemsOfOneThreadGroup":0,"version":0,"sts":"resume"}]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/server[v.4][reload=true]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/server/DBDemoSingle_task$192.168.255.1$29C5AFD33E254391B2D7FA01E8D88A57$0000000013[v.21][{"uuid":"DBDemoSingle_task$192.168.255.1$29C5AFD33E254391B2D7FA01E8D88A57$0000000013","id":16103079872455,"taskType":"DBDemoSingle_task","baseTaskType":"DBDemoSingle_task","ownSign":"BASE","ip":"192.168.255.1","hostName":"zhuml","threadNum":5,"registerTime":"2016-10-30 13:59:19","heartBeatTime":"2016-10-30 14:00:10","lastFetchDataTime":"2016-10-30 14:00:10","dealInfoDesc":"到达开始时间,resume调度:FetchDataCount\u003d3,FetchDataNum\u003d1500,DealDataSucess\u003d1005,DealDataFail\u003d0,DealSpendTime\u003d50501,otherCompareCount\u003d0","nextRunStartTime":"2016-10-30 14:01:00","nextRunEndTime":"当不能获取到数据的时候pause","version":20,"isRegister":true,"managerFactoryUUID":"192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004"}]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/server/DBDemoSingle_task$192.168.255.1$42BE86701CF14F5487EDC966DD484262$0000000014[v.21][{"uuid":"DBDemoSingle_task$192.168.255.1$42BE86701CF14F5487EDC966DD484262$0000000014","id":16103064628283,"taskType":"DBDemoSingle_task","baseTaskType":"DBDemoSingle_task","ownSign":"BASE","ip":"192.168.255.1","hostName":"zhuml","threadNum":5,"registerTime":"2016-10-30 13:59:20","heartBeatTime":"2016-10-30 14:00:10","lastFetchDataTime":"2016-10-30 14:00:10","dealInfoDesc":"到达开始时间,resume调度:FetchDataCount\u003d3,FetchDataNum\u003d1500,DealDataSucess\u003d1010,DealDataFail\u003d0,DealSpendTime\u003d50768,otherCompareCount\u003d0","nextRunStartTime":"2016-10-30 14:01:00","nextRunEndTime":"当不能获取到数据的时候pause","version":20,"isRegister":true,"managerFactoryUUID":"192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004"}]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/server/DBDemoSingle_task$192.168.255.1$B4B0C906A87A4944BD19CFBB68FBEDF7$0000000012[v.21][{"uuid":"DBDemoSingle_task$192.168.255.1$B4B0C906A87A4944BD19CFBB68FBEDF7$0000000012","id":16103045591231,"taskType":"DBDemoSingle_task","baseTaskType":"DBDemoSingle_task","ownSign":"BASE","ip":"192.168.255.1","hostName":"zhuml","threadNum":5,"registerTime":"2016-10-30 13:59:19","heartBeatTime":"2016-10-30 14:00:10","lastFetchDataTime":"2016-10-30 14:00:10","dealInfoDesc":"到达开始时间,resume调度:FetchDataCount\u003d3,FetchDataNum\u003d1500,DealDataSucess\u003d1000,DealDataFail\u003d0,DealSpendTime\u003d50233,otherCompareCount\u003d0","nextRunStartTime":"2016-10-30 14:01:00","nextRunEndTime":"当不能获取到数据的时候pause","version":20,"isRegister":true,"managerFactoryUUID":"192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004"}]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/server/DBDemoSingle_task$192.168.255.1$F67CFFE9F5DA4E008AF7BB694C1197E1$0000000011[v.21][{"uuid":"DBDemoSingle_task$192.168.255.1$F67CFFE9F5DA4E008AF7BB694C1197E1$0000000011","id":16103071968380,"taskType":"DBDemoSingle_task","baseTaskType":"DBDemoSingle_task","ownSign":"BASE","ip":"192.168.255.1","hostName":"zhuml","threadNum":5,"registerTime":"2016-10-30 13:59:19","heartBeatTime":"2016-10-30 14:00:10","lastFetchDataTime":"2016-10-30 14:00:10","dealInfoDesc":"到达开始时间,resume调度:FetchDataCount\u003d2,FetchDataNum\u003d1000,DealDataSucess\u003d1000,DealDataFail\u003d0,DealSpendTime\u003d50277,otherCompareCount\u003d0","nextRunStartTime":"2016-10-30 14:01:00","nextRunEndTime":"当不能获取到数据的时候pause","version":20,"isRegister":true,"managerFactoryUUID":"192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004"}]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem[v.12][DBDemoSingle_task$192.168.255.1$F67CFFE9F5DA4E008AF7BB694C1197E1$0000000011]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1/cur_server[v.1][DBDemoSingle_task$192.168.255.1$F67CFFE9F5DA4E008AF7BB694C1197E1$0000000011]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/1/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2/cur_server[v.1][DBDemoSingle_task$192.168.255.1$F67CFFE9F5DA4E008AF7BB694C1197E1$0000000011]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/2/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3/cur_server[v.1][DBDemoSingle_task$192.168.255.1$B4B0C906A87A4944BD19CFBB68FBEDF7$0000000012]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/3/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4/cur_server[v.1][DBDemoSingle_task$192.168.255.1$B4B0C906A87A4944BD19CFBB68FBEDF7$0000000012]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/4/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5/cur_server[v.1][DBDemoSingle_task$192.168.255.1$29C5AFD33E254391B2D7FA01E8D88A57$0000000013]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/5/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6/cur_server[v.1][DBDemoSingle_task$192.168.255.1$42BE86701CF14F5487EDC966DD484262$0000000014]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6/deal_desc[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6/parameter[v.0][]
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6/req_server
/tbSchedule/zmlTbScheduleTest/baseTaskType/DBDemoSingle_task/DBDemoSingle_task/taskItem/6/sts[v.0][ACTIVTE]
/tbSchedule/zmlTbScheduleTest/factory
/tbSchedule/zmlTbScheduleTest/factory/192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004
/tbSchedule/zmlTbScheduleTest/strategy
/tbSchedule/zmlTbScheduleTest/strategy/DBDemoSingle-stratrery[v.0][{"strategyName":"DBDemoSingle-stratrery","IPList":["127.0.0.1"],"numOfSingleServer":0,"assignNum":4,"kind":"Schedule","taskName":"DBDemoSingle_task","taskParameter":"","sts":"resume"}]
/tbSchedule/zmlTbScheduleTest/strategy/DBDemoSingle-stratrery/192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004[v.28][{"strategyName":"DBDemoSingle-stratrery","uuid":"192.168.255.1$zhuml$0BDBD014D78042A88F8DF06CF781C452$0000000004","requestNum":4,"currentNum":0,"message":""}] 1.3 ManagerFactoryTimerTask 定时任务 :this.factory.refresh();
this.factory.refresh(); 判断任务状态 详细说明见 TBSchedule源码阅读2-TBScheduleManagerFactory 定时任务ManagerFactoryTimerTask
TBSchedule源码阅读1-TBScheduleManagerFactory的更多相关文章
- TBSchedule源码阅读2-TBScheduleManagerFactory 定时任务ManagerFactoryTimerTask
定时任务 : 主要功能:监听zookeeper状态,正常则this.factory.refresh(),异常则this.factory.reStart(); 1 正常情况this.factory.re ...
- 【原】FMDB源码阅读(三)
[原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...
- 【原】FMDB源码阅读(二)
[原]FMDB源码阅读(二) 本文转载请注明出处 -- polobymulberry-博客园 1. 前言 上一篇只是简单地过了一下FMDB一个简单例子的基本流程,并没有涉及到FMDB的所有方方面面,比 ...
- 【原】FMDB源码阅读(一)
[原]FMDB源码阅读(一) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 说实话,之前的SDWebImage和AFNetworking这两个组件我还是使用过的,但是对于 ...
- 【原】AFNetworking源码阅读(六)
[原]AFNetworking源码阅读(六) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这一篇的想讲的,一个就是分析一下AFSecurityPolicy文件,看看AF ...
- 【原】AFNetworking源码阅读(五)
[原]AFNetworking源码阅读(五) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇中提及到了Multipart Request的构建方法- [AFHTTP ...
- 【原】AFNetworking源码阅读(四)
[原]AFNetworking源码阅读(四) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇还遗留了很多问题,包括AFURLSessionManagerTaskDe ...
- 【原】AFNetworking源码阅读(三)
[原]AFNetworking源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇的话,主要是讲了如何通过构建一个request来生成一个data tas ...
- 【原】AFNetworking源码阅读(二)
[原]AFNetworking源码阅读(二) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇中我们在iOS Example代码中提到了AFHTTPSessionMa ...
随机推荐
- (转)秒杀系统中如何动态生成下单随机URL
秒杀系统中通常会避免用户之间访问下单页面的URL(避免使用爬虫来造成不公平).所有需要将URL动态化,即使秒杀系统的开发人员也无法在知晓在秒杀开始时的URL.解决办法是在获取秒杀URL的接口中,返回一 ...
- iOS用户响应者链的那些事儿
这篇文章想跟大家分享的主旨是iOS捕获用户事件的各种情况,以及内部封装的一些特殊事件. 我们先从UIButton谈起,UIButton大家使用的太多了,他特殊的地方就在于其内置的普通Default/高 ...
- window linux 文件传输
window 安装:pscp.exe (放在C:\Windows\System32 目录下) Linux 安装: 1: 先更新apt-getroot@ubuntu:/home/ubuntu# sudo ...
- 工具分享:GitHub的克隆工具Cl0neMast3r,轻松搞定各种测试
GitHub,相信大家并不陌生,咱搞技术的应该都会用到它,GitHub主要是进行代码工具的存储.下载等工作.今天介绍一款让我们操作GitHub相关工作变的更简单的工具, GitHub的克隆工具. Cl ...
- Linux内核锁与中断处理
Linux内核锁 在Linux内核里面,一般采用了如下几种锁的机制,来保证多线程的同步与互斥: (1)原子操作 atomic_t v: void atomic_set(atomic_t *v, int ...
- 【Hadoop】HIVE 数据表 使用
3 使用 3.1 数据导入 3.1.1 可以使用命令行导入,也可以直接上传到HDFS的特定目录 3.1.2 格式问题 3.1.2.1 缺失/不合法字段默认值为NULL 3.1.2.2 最好数据是格式化 ...
- 转:提高ios通过率的注意点
http://bugly.qq.com/bbs/forum.php?mod=viewthread&tid=431 Bugly 技术干货系列内容主要涉及移动开发方向,是由 Bugly 邀请腾讯内 ...
- 10. 修改端口号【从零开始学Spring Boot】
转载:http://blog.csdn.net/linxingliang/article/details/51637017 spring boot 默认端口是8080,如果想要进行更改的话,只需要修改 ...
- 新Android工程src和layout目录为空的问题
问题症状:eclipse创建的新Android工程,发现src下为空,res\layout目录下也为空. 原因:升级了SDK,新版本sdk与ADT冲突.具体冲突的版本号为ADT 23.X与SDK22. ...
- 为什么我获取不到这个css样式?js原生获取css样式总结
还是自己遇到的一个坑的总结吧!与其说是坑不如说自己学艺不精,让我先哭一会!! 需求 简单就是获取一个css的height (好吧 就是一个这么简单的需求) 实践 好吧 长时间的JQ 我已经对原生无能了 ...