Bläddra i källkod

GLUE任务调度时,执行器校验是否支持GLUE模式任务,校验GlueFactory的glueloader是否存在;

xueli.xue 9 år sedan
förälder
incheckning
552949167e

+ 5 - 2
xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java Visa fil

@@ -43,7 +43,10 @@ public class GlueFactory implements ApplicationContextAware {
43 43
 	public void setGlueLoader(GlueLoader glueLoader) {
44 44
 		this.glueLoader = glueLoader;
45 45
 	}
46
-	
46
+	public static boolean isActive() {
47
+		return GlueFactory.glueFactory.glueLoader!=null;
48
+	}
49
+
47 50
 	// ----------------------------- spring support -----------------------------
48 51
 	private static ApplicationContext applicationContext;
49 52
 	private static GlueFactory glueFactory;
@@ -122,7 +125,7 @@ public class GlueFactory implements ApplicationContextAware {
122 125
 	}
123 126
 	
124 127
 	// // load instance, singleton
125
-	public static String generateInstanceCacheKey(String job_group, String job_name){
128
+	private static String generateInstanceCacheKey(String job_group, String job_name){
126 129
 		return job_group.concat("_").concat(job_name).concat("_instance");
127 130
 	}
128 131
 	public IJobHandler loadInstance(String job_group, String job_name) throws Exception{

+ 8 - 1
xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java Visa fil

@@ -1,5 +1,6 @@
1 1
 package com.xxl.job.core.router.action;
2 2
 
3
+import com.xxl.job.core.glue.GlueFactory;
3 4
 import com.xxl.job.core.handler.IJobHandler;
4 5
 import com.xxl.job.core.handler.impl.GlueJobHandler;
5 6
 import com.xxl.job.core.router.HandlerRouter;
@@ -25,7 +26,7 @@ public class RunAction extends IAction {
25 26
         if (!requestModel.isGlueSwitch()) {
26 27
             // bean model
27 28
 
28
-            // handler instance
29
+            // valid handler instance
29 30
             IJobHandler jobHandler = HandlerRouter.loadJobHandler(requestModel.getExecutorHandler());
30 31
             if (jobHandler==null) {
31 32
                 return new ResponseModel(ResponseModel.FAIL, "job handler for jobKey=[" + jobKey + "] not found.");
@@ -46,6 +47,12 @@ public class RunAction extends IAction {
46 47
             }
47 48
         } else {
48 49
             // glue model
50
+
51
+            // valid glueloader
52
+            if (!GlueFactory.isActive()) {
53
+                return new ResponseModel(ResponseModel.FAIL, "glueLoader for jobKey=[" + jobKey + "] not found.");
54
+            }
55
+
49 56
             if (jobThread == null) {
50 57
                 jobThread = HandlerRouter.registJobThread(jobKey, new GlueJobHandler(requestModel.getJobGroup(), requestModel.getJobName()));
51 58
             } else {

+ 3 - 2
xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml Visa fil

@@ -15,9 +15,10 @@
15 15
 	<bean id="xxlJobExecutor" class="com.xxl.job.core.executor.jetty.XxlJobExecutor" init-method="start" destroy-method="destroy" >
16 16
 		<property name="port" value="9999" />
17 17
 	</bean>
18
-	
18
+
19
+	<!-- glue factory -->
19 20
 	<bean id="glueFactory" class="com.xxl.job.core.glue.GlueFactory">
20
-		<property name="cacheTimeout" value="5000" />
21
+		<property name="cacheTimeout" value="10000" />
21 22
 		<property name="glueLoader" ref="dbGlueLoader" />	<!-- GLUE 代码加载器,推荐将该服务配置成RPC服务 -->
22 23
 	</bean>
23 24