不入侵业务代码使用xxljob定时任务2.3.0
xxl-job-core
1.ExecutorBizImpl
新增private JobHandlerGenerator jobHandlerGenerator = new XxlJobHandlerGenerator();
源码 run方法改 IJobHadeler newJobHandler = this.jobHandlerGenerator .loadJobHandler(triggerParam);
2.TriggerParam
新增private String executorHandlerMethod; set,get,toString方法
3.新增XxlJobAirEExecutor类
public class XxlJobAirExecutor extends XxlJobSpringExecutor{
private static final Logger LOGGER = LoggerFactory.getLogger(XxlJobAirExecutor.class);
private static ApplicationContext applicationContext;
@Override
public void afterSingletonsInstantiated(){
super.afterSingletonsInstantiated();
}
private static ConcurrentMap<String,IJobHandler> airJobHandlerRepository = new ConcurrentHashMap<>();
//获取jobhandler jobhandler名称 执行方法名称
public static IJobHandler loadJobHandler(String jobHandler,String executeMethod){
return airJobHandlerRepository.computeIfAbsent(creatJobHandlerFlag(jobHandler,executeMethod),
key->doCreatAirJobHandler(jobHandler,executeMethod));
}
pirvate static String creatJobHandlerFlag(String jobHandler,String executeMethod){
return jobHandler + "#" + executeMethod;
}
//创建AirJobHandler
private static AirJobHandler doCreatAirJobHandler(String jobHandler,String executeMethod){
try{
Object handler = applicationContext.getBean(jobHandler);
Method method = ReflectionUtils.findMethod(handler.getClass(),executeMethod);
LOGGER.info(">>xxl-job register jobhandler success,name:{},jobHandler:{}",jobHandler,executeMethod);
return new AirJobHandler(handler,method);
}catch(Exception e){
LOGGER.error("找不到jobhandler");
return null;
}
}
@Override
public void destroy(){super.destroy();}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throw BeansException{
XxlJobAirExecutor.applicationContext=applicationContext;
super.setApplicationContext(applicationContext);
}
}
4.新增JobHandlerGenerator接口
public interface JobHandlerGenerator{
IJobHandler loadJobHandler(TriggerParam triggerParam);
}
5.新增XxlJobHandlerGenerator类
public class XxlJobHandlerGenerator{
@Override
public IjobHandler loadJobHandler(TriggerParam triggerParam){
String handler = triggerParam.getExecutorHandler();
String method = triggerParam.getExecutorHanlerMethod();
return StringUtils.hasText(method) ? XxlJobAirExecutor.loadJobHandler(handler,method):XxlJobExecutor.loadJobHandler(handler);
}
}
6.新增AirJobHandler
public class AirJobHandler extends IJobHandler{
private final Object target;
private final Method executeMethod;
public AirJobHandler(Objcet target,Method executeMethod){
this.target = target;
this.executeMethod = executeMethod;
}
@Override
public void execute() throws Exception{
Class<?>[] paramTypes = executerMethod.getParameterTypes();
if(paramTypes.length>0){
executeMethod.invoke(target,new Object[paramTypes.length]);
}else{
executeMethod.invoke(target);
}
}
}
xxl-job-admin
1.XxlJobInfo修改
新增 private String executorHandlerMethod; get,set
2.XxlJobTrigger修改
新增triggerParam.setExecutorHanlerMethod(jobInfo.getExecutorHandlerMethod);
3.XxlJobInfoMapper.xml
save update 新增 excutor_handler_method
4.XxlJobServiceImpl
276行 exists_jobInfo.setExecutorHandlerMethod(jobInfo.getExecutorHandlerMethod());
sql xxl_job_info 表
新增excutor_handler_method字段
jobinfo.index.ftl
job新增、更新中 增加 executorHandlerMethod
jobinfo.index.1.js
update方法中 565行新增executeHandlerMethod回显