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

转载于:https://www.cnblogs.com/clds/p/5981768.html

你可能感兴趣的:(TBSchedule源码阅读1-TBScheduleManagerFactory)