|
|
@ -3,6 +3,8 @@ package com.xxl.job.core.executor; |
|
|
|
import com.xxl.job.core.biz.AdminBiz; |
|
|
|
import com.xxl.job.core.biz.AdminBiz; |
|
|
|
import com.xxl.job.core.biz.client.AdminBizClient; |
|
|
|
import com.xxl.job.core.biz.client.AdminBizClient; |
|
|
|
import com.xxl.job.core.handler.IJobHandler; |
|
|
|
import com.xxl.job.core.handler.IJobHandler; |
|
|
|
|
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob; |
|
|
|
|
|
|
|
import com.xxl.job.core.handler.impl.MethodJobHandler; |
|
|
|
import com.xxl.job.core.log.XxlJobFileAppender; |
|
|
|
import com.xxl.job.core.log.XxlJobFileAppender; |
|
|
|
import com.xxl.job.core.server.EmbedServer; |
|
|
|
import com.xxl.job.core.server.EmbedServer; |
|
|
|
import com.xxl.job.core.thread.JobLogFileCleanThread; |
|
|
|
import com.xxl.job.core.thread.JobLogFileCleanThread; |
|
|
@ -13,6 +15,7 @@ import com.xxl.job.core.util.NetUtil; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
@ -110,6 +113,50 @@ public class XxlJobExecutor { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void registerJobHandler(XxlJob xxlJob, Object bean, Method executeMethod){ |
|
|
|
|
|
|
|
if (xxlJob == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String name = xxlJob.value(); |
|
|
|
|
|
|
|
//make and simplify the variables since they'll be called several times later
|
|
|
|
|
|
|
|
Class<?> clazz = bean.getClass(); |
|
|
|
|
|
|
|
String methodName = executeMethod.getName(); |
|
|
|
|
|
|
|
if (name.trim().length() == 0) { |
|
|
|
|
|
|
|
throw new RuntimeException("xxl-job method-jobhandler name invalid, for[" + clazz + "#" + methodName + "] ."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (loadJobHandler(name) != null) { |
|
|
|
|
|
|
|
throw new RuntimeException("xxl-job jobhandler[" + name + "] naming conflicts."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
executeMethod.setAccessible(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init and destroy
|
|
|
|
|
|
|
|
Method initMethod = null; |
|
|
|
|
|
|
|
Method destroyMethod = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (xxlJob.init().trim().length() > 0) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
initMethod = clazz.getDeclaredMethod(xxlJob.init()); |
|
|
|
|
|
|
|
initMethod.setAccessible(true); |
|
|
|
|
|
|
|
} catch (NoSuchMethodException e) { |
|
|
|
|
|
|
|
throw new RuntimeException("xxl-job method-jobhandler initMethod invalid, for[" + clazz + "#" + methodName + "] ."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (xxlJob.destroy().trim().length() > 0) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
destroyMethod = clazz.getDeclaredMethod(xxlJob.destroy()); |
|
|
|
|
|
|
|
destroyMethod.setAccessible(true); |
|
|
|
|
|
|
|
} catch (NoSuchMethodException e) { |
|
|
|
|
|
|
|
throw new RuntimeException("xxl-job method-jobhandler destroyMethod invalid, for[" + clazz + "#" + methodName + "] ."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// registry jobhandler
|
|
|
|
|
|
|
|
registJobHandler(name, new MethodJobHandler(bean, executeMethod, initMethod, destroyMethod)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------- admin-client (rpc invoker) ----------------------
|
|
|
|
// ---------------------- admin-client (rpc invoker) ----------------------
|
|
|
|
private static List<AdminBiz> adminBizList; |
|
|
|
private static List<AdminBiz> adminBizList; |
|
|
|