- 触发:单节点周期性触发,运行事件如delayqueue; - 调度:集群竞争,负载方式协同处理,锁竞争-更新触发信息-推送时间轮-锁释放-锁竞争; - 2、底层表结构重构:移除11张quartz相关表,并对现有表结构优化梳理; - 3、底层线程模型重构:移除Quartz线程池,降低系统线程与内存开销;pull/10/head
parent
9353bdcbcf
commit
e01d2bc9b5
@ -1,168 +0,0 @@
|
||||
#
|
||||
# Quartz seems to work best with the driver mm.mysql-2.0.7-bin.jar
|
||||
#
|
||||
# PLEASE consider using mysql with innodb tables to avoid locking issues
|
||||
#
|
||||
# In your Quartz properties file, you'll need to set
|
||||
# org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
|
||||
#
|
||||
|
||||
DROP TABLE IF EXISTS QRTZ_FIRED_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS;
|
||||
DROP TABLE IF EXISTS QRTZ_SCHEDULER_STATE;
|
||||
DROP TABLE IF EXISTS QRTZ_LOCKS;
|
||||
DROP TABLE IF EXISTS QRTZ_SIMPLE_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_TRIGGERS;
|
||||
DROP TABLE IF EXISTS QRTZ_JOB_DETAILS;
|
||||
DROP TABLE IF EXISTS QRTZ_CALENDARS;
|
||||
|
||||
|
||||
CREATE TABLE QRTZ_JOB_DETAILS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
JOB_NAME VARCHAR(200) NOT NULL,
|
||||
JOB_GROUP VARCHAR(200) NOT NULL,
|
||||
DESCRIPTION VARCHAR(250) NULL,
|
||||
JOB_CLASS_NAME VARCHAR(250) NOT NULL,
|
||||
IS_DURABLE VARCHAR(1) NOT NULL,
|
||||
IS_NONCONCURRENT VARCHAR(1) NOT NULL,
|
||||
IS_UPDATE_DATA VARCHAR(1) NOT NULL,
|
||||
REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
|
||||
JOB_DATA BLOB NULL,
|
||||
PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
JOB_NAME VARCHAR(200) NOT NULL,
|
||||
JOB_GROUP VARCHAR(200) NOT NULL,
|
||||
DESCRIPTION VARCHAR(250) NULL,
|
||||
NEXT_FIRE_TIME BIGINT(13) NULL,
|
||||
PREV_FIRE_TIME BIGINT(13) NULL,
|
||||
PRIORITY INTEGER NULL,
|
||||
TRIGGER_STATE VARCHAR(16) NOT NULL,
|
||||
TRIGGER_TYPE VARCHAR(8) NOT NULL,
|
||||
START_TIME BIGINT(13) NOT NULL,
|
||||
END_TIME BIGINT(13) NULL,
|
||||
CALENDAR_NAME VARCHAR(200) NULL,
|
||||
MISFIRE_INSTR SMALLINT(2) NULL,
|
||||
JOB_DATA BLOB NULL,
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
|
||||
FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
|
||||
REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_SIMPLE_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
REPEAT_COUNT BIGINT(7) NOT NULL,
|
||||
REPEAT_INTERVAL BIGINT(12) NOT NULL,
|
||||
TIMES_TRIGGERED BIGINT(10) NOT NULL,
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
|
||||
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_CRON_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
CRON_EXPRESSION VARCHAR(200) NOT NULL,
|
||||
TIME_ZONE_ID VARCHAR(80),
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
|
||||
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_SIMPROP_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
STR_PROP_1 VARCHAR(512) NULL,
|
||||
STR_PROP_2 VARCHAR(512) NULL,
|
||||
STR_PROP_3 VARCHAR(512) NULL,
|
||||
INT_PROP_1 INT NULL,
|
||||
INT_PROP_2 INT NULL,
|
||||
LONG_PROP_1 BIGINT NULL,
|
||||
LONG_PROP_2 BIGINT NULL,
|
||||
DEC_PROP_1 NUMERIC(13,4) NULL,
|
||||
DEC_PROP_2 NUMERIC(13,4) NULL,
|
||||
BOOL_PROP_1 VARCHAR(1) NULL,
|
||||
BOOL_PROP_2 VARCHAR(1) NULL,
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
|
||||
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_BLOB_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
BLOB_DATA BLOB NULL,
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
|
||||
FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_CALENDARS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
CALENDAR_NAME VARCHAR(200) NOT NULL,
|
||||
CALENDAR BLOB NOT NULL,
|
||||
PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_FIRED_TRIGGERS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
ENTRY_ID VARCHAR(95) NOT NULL,
|
||||
TRIGGER_NAME VARCHAR(200) NOT NULL,
|
||||
TRIGGER_GROUP VARCHAR(200) NOT NULL,
|
||||
INSTANCE_NAME VARCHAR(200) NOT NULL,
|
||||
FIRED_TIME BIGINT(13) NOT NULL,
|
||||
SCHED_TIME BIGINT(13) NOT NULL,
|
||||
PRIORITY INTEGER NOT NULL,
|
||||
STATE VARCHAR(16) NOT NULL,
|
||||
JOB_NAME VARCHAR(200) NULL,
|
||||
JOB_GROUP VARCHAR(200) NULL,
|
||||
IS_NONCONCURRENT VARCHAR(1) NULL,
|
||||
REQUESTS_RECOVERY VARCHAR(1) NULL,
|
||||
PRIMARY KEY (SCHED_NAME,ENTRY_ID)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_SCHEDULER_STATE
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
INSTANCE_NAME VARCHAR(200) NOT NULL,
|
||||
LAST_CHECKIN_TIME BIGINT(13) NOT NULL,
|
||||
CHECKIN_INTERVAL BIGINT(13) NOT NULL,
|
||||
PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
|
||||
);
|
||||
|
||||
CREATE TABLE QRTZ_LOCKS
|
||||
(
|
||||
SCHED_NAME VARCHAR(120) NOT NULL,
|
||||
LOCK_NAME VARCHAR(40) NOT NULL,
|
||||
PRIMARY KEY (SCHED_NAME,LOCK_NAME)
|
||||
);
|
||||
|
||||
|
||||
commit;
|
@ -0,0 +1,147 @@
|
||||
package com.xxl.job.admin.core.conf;
|
||||
|
||||
import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
|
||||
import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
|
||||
import com.xxl.job.admin.core.thread.JobScheduleHelper;
|
||||
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.core.biz.AdminBiz;
|
||||
import com.xxl.job.core.biz.ExecutorBiz;
|
||||
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
||||
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
import com.xxl.rpc.remoting.invoker.call.CallType;
|
||||
import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
||||
import com.xxl.rpc.remoting.invoker.route.LoadBalance;
|
||||
import com.xxl.rpc.remoting.net.NetEnum;
|
||||
import com.xxl.rpc.remoting.net.impl.servlet.server.ServletServerHandler;
|
||||
import com.xxl.rpc.remoting.provider.XxlRpcProviderFactory;
|
||||
import com.xxl.rpc.serialize.Serializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-28 00:18:17
|
||||
*/
|
||||
@Configuration
|
||||
public class XxlJobScheduler implements InitializingBean, DisposableBean {
|
||||
private static final Logger logger = LoggerFactory.getLogger(XxlJobScheduler.class);
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
// init i18n
|
||||
initI18n();
|
||||
|
||||
// admin registry monitor run
|
||||
JobRegistryMonitorHelper.getInstance().start();
|
||||
|
||||
// admin monitor run
|
||||
JobFailMonitorHelper.getInstance().start();
|
||||
|
||||
// admin-server
|
||||
initRpcProvider();
|
||||
|
||||
// start-schedule
|
||||
JobScheduleHelper.getInstance().start();
|
||||
|
||||
logger.info(">>>>>>>>> init xxl-job admin success.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
// stop-schedule
|
||||
JobScheduleHelper.getInstance().toStop();
|
||||
|
||||
// admin trigger pool stop
|
||||
JobTriggerPoolHelper.toStop();
|
||||
|
||||
// admin registry stop
|
||||
JobRegistryMonitorHelper.getInstance().toStop();
|
||||
|
||||
// admin monitor stop
|
||||
JobFailMonitorHelper.getInstance().toStop();
|
||||
|
||||
// admin-server
|
||||
stopRpcProvider();
|
||||
}
|
||||
|
||||
// ---------------------- I18n ----------------------
|
||||
|
||||
private void initI18n(){
|
||||
for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
|
||||
item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------- admin rpc provider (no server version) ----------------------
|
||||
private static ServletServerHandler servletServerHandler;
|
||||
private void initRpcProvider(){
|
||||
// init
|
||||
XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
||||
xxlRpcProviderFactory.initConfig(
|
||||
NetEnum.NETTY_HTTP,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
null,
|
||||
0,
|
||||
XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
null,
|
||||
null);
|
||||
|
||||
// add services
|
||||
xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());
|
||||
|
||||
// servlet handler
|
||||
servletServerHandler = new ServletServerHandler(xxlRpcProviderFactory);
|
||||
}
|
||||
private void stopRpcProvider() throws Exception {
|
||||
XxlRpcInvokerFactory.getInstance().stop();
|
||||
}
|
||||
public static void invokeAdminService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
servletServerHandler.handle(null, request, response);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- executor-client ----------------------
|
||||
private static ConcurrentHashMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
|
||||
public static ExecutorBiz getExecutorBiz(String address) throws Exception {
|
||||
// valid
|
||||
if (address==null || address.trim().length()==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// load-cache
|
||||
address = address.trim();
|
||||
ExecutorBiz executorBiz = executorBizRepository.get(address);
|
||||
if (executorBiz != null) {
|
||||
return executorBiz;
|
||||
}
|
||||
|
||||
// set-cache
|
||||
executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
|
||||
NetEnum.NETTY_HTTP,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
CallType.SYNC,
|
||||
LoadBalance.ROUND,
|
||||
ExecutorBiz.class,
|
||||
null,
|
||||
5000,
|
||||
address,
|
||||
XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
null,
|
||||
null).getObject();
|
||||
|
||||
executorBizRepository.put(address, executorBiz);
|
||||
return executorBiz;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,33 +0,0 @@
|
||||
package com.xxl.job.admin.core.jobbean;
|
||||
|
||||
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.quartz.JobKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
/**
|
||||
* http job bean
|
||||
* “@DisallowConcurrentExecution” diable concurrent, thread size can not be only one, better given more
|
||||
* @author xuxueli 2015-12-17 18:20:34
|
||||
*/
|
||||
//@DisallowConcurrentExecution
|
||||
public class RemoteHttpJobBean extends QuartzJobBean {
|
||||
private static Logger logger = LoggerFactory.getLogger(RemoteHttpJobBean.class);
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context)
|
||||
throws JobExecutionException {
|
||||
|
||||
// load jobId
|
||||
JobKey jobKey = context.getTrigger().getJobKey();
|
||||
Integer jobId = Integer.valueOf(jobKey.getName());
|
||||
|
||||
// trigger
|
||||
JobTriggerPoolHelper.trigger(jobId, TriggerTypeEnum.CRON, -1, null, null);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
//package com.xxl.job.admin.core.jobbean;
|
||||
//
|
||||
//import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
//import com.xxl.job.admin.core.trigger.TriggerTypeEnum;
|
||||
//import org.quartz.JobExecutionContext;
|
||||
//import org.quartz.JobExecutionException;
|
||||
//import org.quartz.JobKey;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
//
|
||||
///**
|
||||
// * http job bean
|
||||
// * “@DisallowConcurrentExecution” diable concurrent, thread size can not be only one, better given more
|
||||
// * @author xuxueli 2015-12-17 18:20:34
|
||||
// */
|
||||
////@DisallowConcurrentExecution
|
||||
//public class RemoteHttpJobBean extends QuartzJobBean {
|
||||
// private static Logger logger = LoggerFactory.getLogger(RemoteHttpJobBean.class);
|
||||
//
|
||||
// @Override
|
||||
// protected void executeInternal(JobExecutionContext context)
|
||||
// throws JobExecutionException {
|
||||
//
|
||||
// // load jobId
|
||||
// JobKey jobKey = context.getTrigger().getJobKey();
|
||||
// Integer jobId = Integer.valueOf(jobKey.getName());
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,413 @@
|
||||
//package com.xxl.job.admin.core.schedule;
|
||||
//
|
||||
//import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
//import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean;
|
||||
//import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
//import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
|
||||
//import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
|
||||
//import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
//import com.xxl.job.admin.core.util.I18nUtil;
|
||||
//import com.xxl.job.core.biz.AdminBiz;
|
||||
//import com.xxl.job.core.biz.ExecutorBiz;
|
||||
//import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
||||
//import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
//import com.xxl.rpc.remoting.invoker.call.CallType;
|
||||
//import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
||||
//import com.xxl.rpc.remoting.invoker.route.LoadBalance;
|
||||
//import com.xxl.rpc.remoting.net.NetEnum;
|
||||
//import com.xxl.rpc.remoting.net.impl.servlet.server.ServletServerHandler;
|
||||
//import com.xxl.rpc.remoting.provider.XxlRpcProviderFactory;
|
||||
//import com.xxl.rpc.serialize.Serializer;
|
||||
//import org.quartz.*;
|
||||
//import org.quartz.Trigger.TriggerState;
|
||||
//import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.util.Assert;
|
||||
//
|
||||
//import javax.servlet.ServletException;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.IOException;
|
||||
//import java.util.Date;
|
||||
//import java.util.concurrent.ConcurrentHashMap;
|
||||
//
|
||||
///**
|
||||
// * base quartz scheduler util
|
||||
// * @author xuxueli 2015-12-19 16:13:53
|
||||
// */
|
||||
//public final class XxlJobDynamicScheduler {
|
||||
// private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler_old.class);
|
||||
//
|
||||
// // ---------------------- param ----------------------
|
||||
//
|
||||
// // scheduler
|
||||
// private static Scheduler scheduler;
|
||||
// public void setScheduler(Scheduler scheduler) {
|
||||
// XxlJobDynamicScheduler_old.scheduler = scheduler;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- init + destroy ----------------------
|
||||
// public void start() throws Exception {
|
||||
// // valid
|
||||
// Assert.notNull(scheduler, "quartz scheduler is null");
|
||||
//
|
||||
// // init i18n
|
||||
// initI18n();
|
||||
//
|
||||
// // admin registry monitor run
|
||||
// JobRegistryMonitorHelper.getInstance().start();
|
||||
//
|
||||
// // admin monitor run
|
||||
// JobFailMonitorHelper.getInstance().start();
|
||||
//
|
||||
// // admin-server
|
||||
// initRpcProvider();
|
||||
//
|
||||
// logger.info(">>>>>>>>> init xxl-job admin success.");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void destroy() throws Exception {
|
||||
// // admin trigger pool stop
|
||||
// JobTriggerPoolHelper.toStop();
|
||||
//
|
||||
// // admin registry stop
|
||||
// JobRegistryMonitorHelper.getInstance().toStop();
|
||||
//
|
||||
// // admin monitor stop
|
||||
// JobFailMonitorHelper.getInstance().toStop();
|
||||
//
|
||||
// // admin-server
|
||||
// stopRpcProvider();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- I18n ----------------------
|
||||
//
|
||||
// private void initI18n(){
|
||||
// for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
|
||||
// item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- admin rpc provider (no server version) ----------------------
|
||||
// private static ServletServerHandler servletServerHandler;
|
||||
// private void initRpcProvider(){
|
||||
// // init
|
||||
// XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
||||
// xxlRpcProviderFactory.initConfig(
|
||||
// NetEnum.NETTY_HTTP,
|
||||
// Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
// null,
|
||||
// 0,
|
||||
// XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
// null,
|
||||
// null);
|
||||
//
|
||||
// // add services
|
||||
// xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());
|
||||
//
|
||||
// // servlet handler
|
||||
// servletServerHandler = new ServletServerHandler(xxlRpcProviderFactory);
|
||||
// }
|
||||
// private void stopRpcProvider() throws Exception {
|
||||
// XxlRpcInvokerFactory.getInstance().stop();
|
||||
// }
|
||||
// public static void invokeAdminService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
// servletServerHandler.handle(null, request, response);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- executor-client ----------------------
|
||||
// private static ConcurrentHashMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
|
||||
// public static ExecutorBiz getExecutorBiz(String address) throws Exception {
|
||||
// // valid
|
||||
// if (address==null || address.trim().length()==0) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // load-cache
|
||||
// address = address.trim();
|
||||
// ExecutorBiz executorBiz = executorBizRepository.get(address);
|
||||
// if (executorBiz != null) {
|
||||
// return executorBiz;
|
||||
// }
|
||||
//
|
||||
// // set-cache
|
||||
// executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
|
||||
// NetEnum.NETTY_HTTP,
|
||||
// Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
// CallType.SYNC,
|
||||
// LoadBalance.ROUND,
|
||||
// ExecutorBiz.class,
|
||||
// null,
|
||||
// 5000,
|
||||
// address,
|
||||
// XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
// null,
|
||||
// null).getObject();
|
||||
//
|
||||
// executorBizRepository.put(address, executorBiz);
|
||||
// return executorBiz;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ---------------------- schedule util ----------------------
|
||||
//
|
||||
// /**
|
||||
// * fill job info
|
||||
// *
|
||||
// * @param jobInfo
|
||||
// */
|
||||
// public static void fillJobInfo(XxlJobInfo jobInfo) {
|
||||
//
|
||||
// String name = String.valueOf(jobInfo.getId());
|
||||
//
|
||||
// // trigger key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(name);
|
||||
// try {
|
||||
//
|
||||
// // trigger cron
|
||||
// Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
// if (trigger!=null && trigger instanceof CronTriggerImpl) {
|
||||
// String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
|
||||
// jobInfo.setJobCron(cronExpression);
|
||||
// }
|
||||
//
|
||||
// // trigger state
|
||||
// TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
// if (triggerState!=null) {
|
||||
// jobInfo.setJobStatus(triggerState.name());
|
||||
// }
|
||||
//
|
||||
// //JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
|
||||
// //JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
// //String jobClass = jobDetail.getJobClass().getName();
|
||||
//
|
||||
// } catch (SchedulerException e) {
|
||||
// logger.error(e.getMessage(), e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * add trigger + job
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @param cronExpression
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean addJob(String jobName, String cronExpression) throws SchedulerException {
|
||||
// // 1、job key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
//
|
||||
// // 2、valid
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// // 3、corn trigger
|
||||
// CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
|
||||
// CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
//
|
||||
// // 4、job detail
|
||||
// Class<? extends Job> jobClass_ = RemoteHttpJobBean.class; // Class.forName(jobInfo.getJobClass());
|
||||
// JobDetail jobDetail = JobBuilder.newJob(jobClass_).withIdentity(jobKey).build();
|
||||
//
|
||||
// /*if (jobInfo.getJobData()!=null) {
|
||||
// JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
||||
// jobDataMap.putAll(JacksonUtil.readValue(jobInfo.getJobData(), Map.class));
|
||||
// // JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
|
||||
// }*/
|
||||
//
|
||||
// // 5、schedule job
|
||||
// Date date = scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> addJob success(quartz), jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * remove trigger + job
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean removeJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
// scheduler.deleteJob(jobKey);
|
||||
//
|
||||
// /*TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.unscheduleJob(triggerKey); // trigger + job
|
||||
// }*/
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> removeJob success(quartz), jobKey:{}", jobKey);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * updateJobCron
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @param cronExpression
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// public static boolean updateJobCron(String jobName, String cronExpression) throws SchedulerException {
|
||||
//
|
||||
// // 1、job key
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// // 2、valid
|
||||
// if (!scheduler.checkExists(triggerKey)) {
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// CronTrigger oldTrigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||
//
|
||||
// // 3、avoid repeat cron
|
||||
// String oldCron = oldTrigger.getCronExpression();
|
||||
// if (oldCron.equals(cronExpression)){
|
||||
// return true; // PASS
|
||||
// }
|
||||
//
|
||||
// // 4、new cron trigger
|
||||
// CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
|
||||
// oldTrigger = oldTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
//
|
||||
// // 5、rescheduleJob
|
||||
// scheduler.rescheduleJob(triggerKey, oldTrigger);
|
||||
//
|
||||
// /*
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
//
|
||||
// // old job detail
|
||||
// JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
//
|
||||
// // new trigger
|
||||
// HashSet<Trigger> triggerSet = new HashSet<Trigger>();
|
||||
// triggerSet.add(cronTrigger);
|
||||
// // cover trigger of job detail
|
||||
// scheduler.scheduleJob(jobDetail, triggerSet, true);*/
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> resumeJob success, JobName:{}", jobName);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * pause
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean pauseJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.pauseTrigger(triggerKey);
|
||||
// result = true;
|
||||
// }
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> pauseJob {}, triggerKey:{}", (result?"success":"fail"),triggerKey);
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * resume
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean resumeJob(String jobName) throws SchedulerException {
|
||||
//
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.resumeTrigger(triggerKey);
|
||||
// result = true;
|
||||
// }
|
||||
//
|
||||
// logger.info(">>>>>>>>>>> resumeJob {}, triggerKey:{}", (result?"success":"fail"), triggerKey);
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * run
|
||||
// *
|
||||
// * @param jobName
|
||||
// * @return
|
||||
// * @throws SchedulerException
|
||||
// */
|
||||
// /*public static boolean triggerJob(String jobName) throws SchedulerException {
|
||||
// // TriggerKey : name + group
|
||||
// JobKey jobKey = new JobKey(jobName);
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
//
|
||||
// boolean result = false;
|
||||
// if (scheduler.checkExists(triggerKey)) {
|
||||
// scheduler.triggerJob(jobKey);
|
||||
// result = true;
|
||||
// logger.info(">>>>>>>>>>> runJob success, jobKey:{}", jobKey);
|
||||
// } else {
|
||||
// logger.info(">>>>>>>>>>> runJob fail, jobKey:{}", jobKey);
|
||||
// }
|
||||
// return result;
|
||||
// }*/
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * finaAllJobList
|
||||
// *
|
||||
// * @return
|
||||
// *//*
|
||||
// @Deprecated
|
||||
// public static List<Map<String, Object>> finaAllJobList(){
|
||||
// List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
|
||||
//
|
||||
// try {
|
||||
// if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
|
||||
// return null;
|
||||
// }
|
||||
// String groupName = scheduler.getJobGroupNames().get(0);
|
||||
// Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
|
||||
// if (jobKeys!=null && jobKeys.size()>0) {
|
||||
// for (JobKey jobKey : jobKeys) {
|
||||
// TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
|
||||
// Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
// JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
// TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
// Map<String, Object> jobMap = new HashMap<String, Object>();
|
||||
// jobMap.put("TriggerKey", triggerKey);
|
||||
// jobMap.put("Trigger", trigger);
|
||||
// jobMap.put("JobDetail", jobDetail);
|
||||
// jobMap.put("TriggerState", triggerState);
|
||||
// jobList.add(jobMap);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } catch (SchedulerException e) {
|
||||
// logger.error(e.getMessage(), e);
|
||||
// return null;
|
||||
// }
|
||||
// return jobList;
|
||||
// }*/
|
||||
//
|
||||
//}
|
@ -0,0 +1,58 @@
|
||||
//package com.xxl.job.admin.core.quartz;
|
||||
//
|
||||
//import org.quartz.SchedulerConfigException;
|
||||
//import org.quartz.spi.ThreadPool;
|
||||
//
|
||||
///**
|
||||
// * single thread pool, for async trigger
|
||||
// *
|
||||
// * @author xuxueli 2019-03-06
|
||||
// */
|
||||
//public class XxlJobThreadPool implements ThreadPool {
|
||||
//
|
||||
// @Override
|
||||
// public boolean runInThread(Runnable runnable) {
|
||||
//
|
||||
// // async run
|
||||
// runnable.run();
|
||||
// return true;
|
||||
//
|
||||
// //return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int blockForAvailableThreads() {
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void initialize() throws SchedulerConfigException {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void shutdown(boolean waitForJobsToComplete) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getPoolSize() {
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInstanceId(String schedInstId) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setInstanceName(String schedName) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// // support
|
||||
// public void setThreadCount(int count) {
|
||||
// //
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,58 +0,0 @@
|
||||
package com.xxl.job.admin.core.quartz;
|
||||
|
||||
import org.quartz.SchedulerConfigException;
|
||||
import org.quartz.spi.ThreadPool;
|
||||
|
||||
/**
|
||||
* single thread pool, for async trigger
|
||||
*
|
||||
* @author xuxueli 2019-03-06
|
||||
*/
|
||||
public class XxlJobThreadPool implements ThreadPool {
|
||||
|
||||
@Override
|
||||
public boolean runInThread(Runnable runnable) {
|
||||
|
||||
// async run
|
||||
runnable.run();
|
||||
return true;
|
||||
|
||||
//return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int blockForAvailableThreads() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() throws SchedulerConfigException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(boolean waitForJobsToComplete) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPoolSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInstanceId(String schedInstId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInstanceName(String schedName) {
|
||||
|
||||
}
|
||||
|
||||
// support
|
||||
public void setThreadCount(int count) {
|
||||
//
|
||||
}
|
||||
|
||||
}
|
@ -1,413 +0,0 @@
|
||||
package com.xxl.job.admin.core.schedule;
|
||||
|
||||
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.jobbean.RemoteHttpJobBean;
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.thread.JobFailMonitorHelper;
|
||||
import com.xxl.job.admin.core.thread.JobRegistryMonitorHelper;
|
||||
import com.xxl.job.admin.core.thread.JobTriggerPoolHelper;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import com.xxl.job.core.biz.AdminBiz;
|
||||
import com.xxl.job.core.biz.ExecutorBiz;
|
||||
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
||||
import com.xxl.rpc.remoting.invoker.XxlRpcInvokerFactory;
|
||||
import com.xxl.rpc.remoting.invoker.call.CallType;
|
||||
import com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean;
|
||||
import com.xxl.rpc.remoting.invoker.route.LoadBalance;
|
||||
import com.xxl.rpc.remoting.net.NetEnum;
|
||||
import com.xxl.rpc.remoting.net.impl.servlet.server.ServletServerHandler;
|
||||
import com.xxl.rpc.remoting.provider.XxlRpcProviderFactory;
|
||||
import com.xxl.rpc.serialize.Serializer;
|
||||
import org.quartz.*;
|
||||
import org.quartz.Trigger.TriggerState;
|
||||
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* base quartz scheduler util
|
||||
* @author xuxueli 2015-12-19 16:13:53
|
||||
*/
|
||||
public final class XxlJobDynamicScheduler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler.class);
|
||||
|
||||
// ---------------------- param ----------------------
|
||||
|
||||
// scheduler
|
||||
private static Scheduler scheduler;
|
||||
public void setScheduler(Scheduler scheduler) {
|
||||
XxlJobDynamicScheduler.scheduler = scheduler;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- init + destroy ----------------------
|
||||
public void start() throws Exception {
|
||||
// valid
|
||||
Assert.notNull(scheduler, "quartz scheduler is null");
|
||||
|
||||
// init i18n
|
||||
initI18n();
|
||||
|
||||
// admin registry monitor run
|
||||
JobRegistryMonitorHelper.getInstance().start();
|
||||
|
||||
// admin monitor run
|
||||
JobFailMonitorHelper.getInstance().start();
|
||||
|
||||
// admin-server
|
||||
initRpcProvider();
|
||||
|
||||
logger.info(">>>>>>>>> init xxl-job admin success.");
|
||||
}
|
||||
|
||||
|
||||
public void destroy() throws Exception {
|
||||
// admin trigger pool stop
|
||||
JobTriggerPoolHelper.toStop();
|
||||
|
||||
// admin registry stop
|
||||
JobRegistryMonitorHelper.getInstance().toStop();
|
||||
|
||||
// admin monitor stop
|
||||
JobFailMonitorHelper.getInstance().toStop();
|
||||
|
||||
// admin-server
|
||||
stopRpcProvider();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- I18n ----------------------
|
||||
|
||||
private void initI18n(){
|
||||
for (ExecutorBlockStrategyEnum item:ExecutorBlockStrategyEnum.values()) {
|
||||
item.setTitle(I18nUtil.getString("jobconf_block_".concat(item.name())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- admin rpc provider (no server version) ----------------------
|
||||
private static ServletServerHandler servletServerHandler;
|
||||
private void initRpcProvider(){
|
||||
// init
|
||||
XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
|
||||
xxlRpcProviderFactory.initConfig(
|
||||
NetEnum.NETTY_HTTP,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
null,
|
||||
0,
|
||||
XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
null,
|
||||
null);
|
||||
|
||||
// add services
|
||||
xxlRpcProviderFactory.addService(AdminBiz.class.getName(), null, XxlJobAdminConfig.getAdminConfig().getAdminBiz());
|
||||
|
||||
// servlet handler
|
||||
servletServerHandler = new ServletServerHandler(xxlRpcProviderFactory);
|
||||
}
|
||||
private void stopRpcProvider() throws Exception {
|
||||
XxlRpcInvokerFactory.getInstance().stop();
|
||||
}
|
||||
public static void invokeAdminService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
servletServerHandler.handle(null, request, response);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- executor-client ----------------------
|
||||
private static ConcurrentHashMap<String, ExecutorBiz> executorBizRepository = new ConcurrentHashMap<String, ExecutorBiz>();
|
||||
public static ExecutorBiz getExecutorBiz(String address) throws Exception {
|
||||
// valid
|
||||
if (address==null || address.trim().length()==0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// load-cache
|
||||
address = address.trim();
|
||||
ExecutorBiz executorBiz = executorBizRepository.get(address);
|
||||
if (executorBiz != null) {
|
||||
return executorBiz;
|
||||
}
|
||||
|
||||
// set-cache
|
||||
executorBiz = (ExecutorBiz) new XxlRpcReferenceBean(
|
||||
NetEnum.NETTY_HTTP,
|
||||
Serializer.SerializeEnum.HESSIAN.getSerializer(),
|
||||
CallType.SYNC,
|
||||
LoadBalance.ROUND,
|
||||
ExecutorBiz.class,
|
||||
null,
|
||||
5000,
|
||||
address,
|
||||
XxlJobAdminConfig.getAdminConfig().getAccessToken(),
|
||||
null,
|
||||
null).getObject();
|
||||
|
||||
executorBizRepository.put(address, executorBiz);
|
||||
return executorBiz;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------- schedule util ----------------------
|
||||
|
||||
/**
|
||||
* fill job info
|
||||
*
|
||||
* @param jobInfo
|
||||
*/
|
||||
public static void fillJobInfo(XxlJobInfo jobInfo) {
|
||||
|
||||
String name = String.valueOf(jobInfo.getId());
|
||||
|
||||
// trigger key
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(name);
|
||||
try {
|
||||
|
||||
// trigger cron
|
||||
Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
if (trigger!=null && trigger instanceof CronTriggerImpl) {
|
||||
String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
|
||||
jobInfo.setJobCron(cronExpression);
|
||||
}
|
||||
|
||||
// trigger state
|
||||
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
if (triggerState!=null) {
|
||||
jobInfo.setJobStatus(triggerState.name());
|
||||
}
|
||||
|
||||
//JobKey jobKey = new JobKey(jobInfo.getJobName(), String.valueOf(jobInfo.getJobGroup()));
|
||||
//JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
//String jobClass = jobDetail.getJobClass().getName();
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* add trigger + job
|
||||
*
|
||||
* @param jobName
|
||||
* @param cronExpression
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
public static boolean addJob(String jobName, String cronExpression) throws SchedulerException {
|
||||
// 1、job key
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
JobKey jobKey = new JobKey(jobName);
|
||||
|
||||
// 2、valid
|
||||
if (scheduler.checkExists(triggerKey)) {
|
||||
return true; // PASS
|
||||
}
|
||||
|
||||
// 3、corn trigger
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing(); // withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
|
||||
CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
|
||||
// 4、job detail
|
||||
Class<? extends Job> jobClass_ = RemoteHttpJobBean.class; // Class.forName(jobInfo.getJobClass());
|
||||
JobDetail jobDetail = JobBuilder.newJob(jobClass_).withIdentity(jobKey).build();
|
||||
|
||||
/*if (jobInfo.getJobData()!=null) {
|
||||
JobDataMap jobDataMap = jobDetail.getJobDataMap();
|
||||
jobDataMap.putAll(JacksonUtil.readValue(jobInfo.getJobData(), Map.class));
|
||||
// JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
|
||||
}*/
|
||||
|
||||
// 5、schedule job
|
||||
Date date = scheduler.scheduleJob(jobDetail, cronTrigger);
|
||||
|
||||
logger.info(">>>>>>>>>>> addJob success(quartz), jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* remove trigger + job
|
||||
*
|
||||
* @param jobName
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
public static boolean removeJob(String jobName) throws SchedulerException {
|
||||
|
||||
JobKey jobKey = new JobKey(jobName);
|
||||
scheduler.deleteJob(jobKey);
|
||||
|
||||
/*TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
if (scheduler.checkExists(triggerKey)) {
|
||||
scheduler.unscheduleJob(triggerKey); // trigger + job
|
||||
}*/
|
||||
|
||||
logger.info(">>>>>>>>>>> removeJob success(quartz), jobKey:{}", jobKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* updateJobCron
|
||||
*
|
||||
* @param jobName
|
||||
* @param cronExpression
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
public static boolean updateJobCron(String jobName, String cronExpression) throws SchedulerException {
|
||||
|
||||
// 1、job key
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
|
||||
// 2、valid
|
||||
if (!scheduler.checkExists(triggerKey)) {
|
||||
return true; // PASS
|
||||
}
|
||||
|
||||
CronTrigger oldTrigger = (CronTrigger) scheduler.getTrigger(triggerKey);
|
||||
|
||||
// 3、avoid repeat cron
|
||||
String oldCron = oldTrigger.getCronExpression();
|
||||
if (oldCron.equals(cronExpression)){
|
||||
return true; // PASS
|
||||
}
|
||||
|
||||
// 4、new cron trigger
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
|
||||
oldTrigger = oldTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();
|
||||
|
||||
// 5、rescheduleJob
|
||||
scheduler.rescheduleJob(triggerKey, oldTrigger);
|
||||
|
||||
/*
|
||||
JobKey jobKey = new JobKey(jobName);
|
||||
|
||||
// old job detail
|
||||
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
|
||||
// new trigger
|
||||
HashSet<Trigger> triggerSet = new HashSet<Trigger>();
|
||||
triggerSet.add(cronTrigger);
|
||||
// cover trigger of job detail
|
||||
scheduler.scheduleJob(jobDetail, triggerSet, true);*/
|
||||
|
||||
logger.info(">>>>>>>>>>> resumeJob success, JobName:{}", jobName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pause
|
||||
*
|
||||
* @param jobName
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
/*public static boolean pauseJob(String jobName) throws SchedulerException {
|
||||
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
|
||||
boolean result = false;
|
||||
if (scheduler.checkExists(triggerKey)) {
|
||||
scheduler.pauseTrigger(triggerKey);
|
||||
result = true;
|
||||
}
|
||||
|
||||
logger.info(">>>>>>>>>>> pauseJob {}, triggerKey:{}", (result?"success":"fail"),triggerKey);
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* resume
|
||||
*
|
||||
* @param jobName
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
/*public static boolean resumeJob(String jobName) throws SchedulerException {
|
||||
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
|
||||
boolean result = false;
|
||||
if (scheduler.checkExists(triggerKey)) {
|
||||
scheduler.resumeTrigger(triggerKey);
|
||||
result = true;
|
||||
}
|
||||
|
||||
logger.info(">>>>>>>>>>> resumeJob {}, triggerKey:{}", (result?"success":"fail"), triggerKey);
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* run
|
||||
*
|
||||
* @param jobName
|
||||
* @return
|
||||
* @throws SchedulerException
|
||||
*/
|
||||
/*public static boolean triggerJob(String jobName) throws SchedulerException {
|
||||
// TriggerKey : name + group
|
||||
JobKey jobKey = new JobKey(jobName);
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
|
||||
|
||||
boolean result = false;
|
||||
if (scheduler.checkExists(triggerKey)) {
|
||||
scheduler.triggerJob(jobKey);
|
||||
result = true;
|
||||
logger.info(">>>>>>>>>>> runJob success, jobKey:{}", jobKey);
|
||||
} else {
|
||||
logger.info(">>>>>>>>>>> runJob fail, jobKey:{}", jobKey);
|
||||
}
|
||||
return result;
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* finaAllJobList
|
||||
*
|
||||
* @return
|
||||
*//*
|
||||
@Deprecated
|
||||
public static List<Map<String, Object>> finaAllJobList(){
|
||||
List<Map<String, Object>> jobList = new ArrayList<Map<String,Object>>();
|
||||
|
||||
try {
|
||||
if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) {
|
||||
return null;
|
||||
}
|
||||
String groupName = scheduler.getJobGroupNames().get(0);
|
||||
Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName));
|
||||
if (jobKeys!=null && jobKeys.size()>0) {
|
||||
for (JobKey jobKey : jobKeys) {
|
||||
TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP);
|
||||
Trigger trigger = scheduler.getTrigger(triggerKey);
|
||||
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
|
||||
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
|
||||
Map<String, Object> jobMap = new HashMap<String, Object>();
|
||||
jobMap.put("TriggerKey", triggerKey);
|
||||
jobMap.put("Trigger", trigger);
|
||||
jobMap.put("JobDetail", jobDetail);
|
||||
jobMap.put("TriggerState", triggerState);
|
||||
jobList.add(jobMap);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
return jobList;
|
||||
}*/
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
# Default Properties file for use by StdSchedulerFactory
|
||||
# to create a Quartz Scheduler Instance, if a different
|
||||
# properties file is not explicitly specified.
|
||||
#
|
||||
|
||||
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
|
||||
org.quartz.scheduler.instanceId: AUTO
|
||||
org.quartz.scheduler.rmi.export: false
|
||||
org.quartz.scheduler.rmi.proxy: false
|
||||
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false
|
||||
|
||||
#org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
|
||||
#org.quartz.threadPool.threadCount: 5
|
||||
#org.quartz.threadPool.threadPriority: 5
|
||||
#org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
|
||||
|
||||
org.quartz.jobStore.misfireThreshold: 60000
|
||||
org.quartz.jobStore.maxMisfiresToHandleAtATime: 1
|
||||
|
||||
#org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
|
||||
|
||||
# for async trigger
|
||||
org.quartz.threadPool.class: com.xxl.job.admin.core.quartz.XxlJobThreadPool
|
||||
|
||||
# for cluster
|
||||
org.quartz.jobStore.tablePrefix: XXL_JOB_QRTZ_
|
||||
org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX
|
||||
org.quartz.jobStore.isClustered: true
|
||||
org.quartz.jobStore.clusterCheckinInterval: 5000
|
Loading…
Reference in new issue