|
@@ -4,7 +4,6 @@ import com.xxl.job.core.biz.AdminBiz;
|
|
import com.xxl.job.core.biz.ExecutorBiz;
|
|
import com.xxl.job.core.biz.ExecutorBiz;
|
|
import com.xxl.job.core.biz.impl.ExecutorBizImpl;
|
|
import com.xxl.job.core.biz.impl.ExecutorBizImpl;
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
-import com.xxl.job.core.handler.annotation.JobHandler;
|
|
|
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
|
import com.xxl.job.core.thread.ExecutorRegistryThread;
|
|
import com.xxl.job.core.thread.ExecutorRegistryThread;
|
|
import com.xxl.job.core.thread.JobLogFileCleanThread;
|
|
import com.xxl.job.core.thread.JobLogFileCleanThread;
|
|
@@ -21,9 +20,6 @@ import com.xxl.rpc.util.IpUtil;
|
|
import com.xxl.rpc.util.NetUtil;
|
|
import com.xxl.rpc.util.NetUtil;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.beans.BeansException;
|
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
|
-import org.springframework.context.ApplicationContextAware;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
@@ -31,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
|
/**
|
|
* Created by xuxueli on 2016/3/2 21:14.
|
|
* Created by xuxueli on 2016/3/2 21:14.
|
|
*/
|
|
*/
|
|
-public class XxlJobExecutor implements ApplicationContextAware {
|
|
|
|
|
|
+public class XxlJobExecutor {
|
|
private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class);
|
|
|
|
|
|
// ---------------------- param ----------------------
|
|
// ---------------------- param ----------------------
|
|
@@ -65,16 +61,6 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
this.logRetentionDays = logRetentionDays;
|
|
this.logRetentionDays = logRetentionDays;
|
|
}
|
|
}
|
|
|
|
|
|
- // ---------------------- applicationContext ----------------------
|
|
|
|
- private static ApplicationContext applicationContext;
|
|
|
|
- @Override
|
|
|
|
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
|
- this.applicationContext = applicationContext;
|
|
|
|
- }
|
|
|
|
- public static ApplicationContext getApplicationContext() {
|
|
|
|
- return applicationContext;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
|
|
// ---------------------- start + stop ----------------------
|
|
// ---------------------- start + stop ----------------------
|
|
public void start() throws Exception {
|
|
public void start() throws Exception {
|
|
@@ -82,12 +68,10 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
// init logpath
|
|
// init logpath
|
|
XxlJobFileAppender.initLogPath(logPath);
|
|
XxlJobFileAppender.initLogPath(logPath);
|
|
|
|
|
|
- // init JobHandler Repository
|
|
|
|
- initJobHandlerRepository(applicationContext);
|
|
|
|
-
|
|
|
|
// init admin-client
|
|
// init admin-client
|
|
initAdminBizList(adminAddresses, accessToken);
|
|
initAdminBizList(adminAddresses, accessToken);
|
|
|
|
|
|
|
|
+
|
|
// init JobLogFileCleanThread
|
|
// init JobLogFileCleanThread
|
|
JobLogFileCleanThread.getInstance().start(logRetentionDays);
|
|
JobLogFileCleanThread.getInstance().start(logRetentionDays);
|
|
|
|
|
|
@@ -108,6 +92,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
jobThreadRepository.clear();
|
|
jobThreadRepository.clear();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
// destory JobLogFileCleanThread
|
|
// destory JobLogFileCleanThread
|
|
JobLogFileCleanThread.getInstance().toStop();
|
|
JobLogFileCleanThread.getInstance().toStop();
|
|
|
|
|
|
@@ -228,27 +213,6 @@ public class XxlJobExecutor implements ApplicationContextAware {
|
|
public static IJobHandler loadJobHandler(String name){
|
|
public static IJobHandler loadJobHandler(String name){
|
|
return jobHandlerRepository.get(name);
|
|
return jobHandlerRepository.get(name);
|
|
}
|
|
}
|
|
- private void initJobHandlerRepository(ApplicationContext applicationContext){
|
|
|
|
- if (applicationContext == null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // init job handler action
|
|
|
|
- Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
|
|
|
|
-
|
|
|
|
- if (serviceBeanMap!=null && serviceBeanMap.size()>0) {
|
|
|
|
- for (Object serviceBean : serviceBeanMap.values()) {
|
|
|
|
- if (serviceBean instanceof IJobHandler){
|
|
|
|
- String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
|
|
|
|
- IJobHandler handler = (IJobHandler) serviceBean;
|
|
|
|
- if (loadJobHandler(name) != null) {
|
|
|
|
- throw new RuntimeException("xxl-job jobhandler naming conflicts.");
|
|
|
|
- }
|
|
|
|
- registJobHandler(name, handler);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------- job thread repository ----------------------
|
|
// ---------------------- job thread repository ----------------------
|