潘志宝
2024-11-21 d338b50afd6504a9676f0a26b3ecbcc844483e7c
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.admin.core.scheduler;
H 2
3 import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
4 import com.xxl.job.admin.core.thread.*;
5 import com.xxl.job.admin.core.util.I18nUtil;
6 import com.xxl.job.core.biz.ExecutorBiz;
7 import com.xxl.job.core.biz.client.ExecutorBizClient;
8 import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14
15 /**
16  * @author xuxueli 2018-10-28 00:18:17
17  */
18
19 public class XxlJobScheduler  {
20     private static final Logger logger = LoggerFactory.getLogger(XxlJobScheduler.class);
21
22
23     public void init() throws Exception {
24         // init i18n
25         initI18n();
26
27         // admin trigger pool start
28         JobTriggerPoolHelper.toStart();
29
30         // admin registry monitor run
31         JobRegistryHelper.getInstance().start();
32
33         // admin fail-monitor run
34         JobFailMonitorHelper.getInstance().start();
35
36         // admin lose-monitor run ( depend on JobTriggerPoolHelper )
37         JobCompleteHelper.getInstance().start();
38
39         // admin log report start
40         JobLogReportHelper.getInstance().start();
41
42         // start-schedule  ( depend on JobTriggerPoolHelper )
43         JobScheduleHelper.getInstance().start();
44
45         logger.info(">>>>>>>>> init xxl-job admin success.");
46     }
47
48     
49     public void destroy() throws Exception {
50
51         // stop-schedule
52         JobScheduleHelper.getInstance().toStop();
53
54         // admin log report stop
55         JobLogReportHelper.getInstance().toStop();
56
57         // admin lose-monitor stop
58         JobCompleteHelper.getInstance().toStop();
59
60         // admin fail-monitor stop
61         JobFailMonitorHelper.getInstance().toStop();
62
63         // admin registry stop
64         JobRegistryHelper.getInstance().toStop();
65
66         // admin trigger pool stop
67         JobTriggerPoolHelper.toStop();
68
69     }
70
71     // ---------------------- I18n ----------------------
72
73     private void initI18n(){
74         for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
75             item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
76         }
77     }
78
79     // ---------------------- executor-client ----------------------
80     private static ConcurrentMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
81     public static ExecutorBiz getExecutorBiz(String address) throws Exception {
82         // valid
83         if (address==null || address.trim().length()==0) {
84             return null;
85         }
86
87         // load-cache
88         address = address.trim();
89         ExecutorBiz executorBiz = executorBizRepository.get(address);
90         if (executorBiz != null) {
91             return executorBiz;
92         }
93
94         // set-cache
95         executorBiz = new ExecutorBizClient(address, XxlJobAdminConfig.getAdminConfig().getAccessToken());
96
97         executorBizRepository.put(address, executorBiz);
98         return executorBiz;
99     }
100
101 }