瀏覽代碼

执行器移除GlueLoader依赖,GLUE源码改为推送方式;

xueli.xue 8 年之前
父節點
當前提交
1b3ad6fbbe

+ 1 - 1
xxl-job-admin/src/main/java/com/xxl/job/admin/core/jobbean/RemoteHttpJobBean.java 查看文件

@@ -10,7 +10,6 @@ import com.xxl.job.admin.core.thread.JobRegistryHelper;
10 10
 import com.xxl.job.core.biz.ExecutorBiz;
11 11
 import com.xxl.job.core.biz.model.ReturnT;
12 12
 import com.xxl.job.core.biz.model.TriggerParam;
13
-import com.xxl.job.core.glue.GlueTypeEnum;
14 13
 import com.xxl.job.core.registry.RegistHelper;
15 14
 import com.xxl.job.core.rpc.netcom.NetComClientProxy;
16 15
 import org.apache.commons.collections.CollectionUtils;
@@ -61,6 +60,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
61 60
 		triggerParam.setExecutorHandler(jobInfo.getExecutorHandler());
62 61
 		triggerParam.setExecutorParams(jobInfo.getExecutorParam());
63 62
 		triggerParam.setGlueType(jobInfo.getGlueType());
63
+		triggerParam.setGlueSource(jobInfo.getGlueSource());
64 64
 		triggerParam.setGlueUpdatetime(jobInfo.getGlueUpdatetime().getTime());
65 65
 		triggerParam.setLogId(jobLog.getId());
66 66
 		triggerParam.setLogDateTim(jobLog.getTriggerTime().getTime());

+ 2 - 9
xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java 查看文件

@@ -58,7 +58,6 @@ public class ExecutorBizImpl implements ExecutorBiz {
58 58
         JobThread jobThread = XxlJobExecutor.loadJobThread(triggerParam.getJobId());
59 59
 
60 60
         if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) {
61
-            // bean model
62 61
 
63 62
             // valid handler
64 63
             IJobHandler jobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler());
@@ -80,13 +79,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
80 79
                 jobThread = XxlJobExecutor.registJobThread(triggerParam.getJobId(), jobHandler);
81 80
             }
82 81
 
83
-        } else {
84
-            // glue model
85
-
86
-            // valid glueloader
87
-            if (!GlueFactory.isActive()) {
88
-                return new ReturnT<String>(ReturnT.FAIL_CODE, "glueLoader for JobId=[" + triggerParam.getJobId() + "] not found.");
89
-            }
82
+        } else if (GlueTypeEnum.GLUE_GROOVY==GlueTypeEnum.match(triggerParam.getGlueType())) {
90 83
 
91 84
             // valid exists job thread:change handler or glue timeout, need kill old thread
92 85
             if (jobThread != null &&
@@ -103,7 +96,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
103 96
             if (jobThread == null) {
104 97
                 IJobHandler jobHandler = null;
105 98
                 try {
106
-                    jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getJobId());
99
+                    jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getGlueSource());
107 100
                 } catch (Exception e) {
108 101
                     logger.error("", e);
109 102
                     return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());

+ 9 - 0
xxl-job-core/src/main/java/com/xxl/job/core/biz/model/TriggerParam.java 查看文件

@@ -15,6 +15,7 @@ public class TriggerParam implements Serializable{
15 15
     private String executorParams;
16 16
 
17 17
     private String glueType;
18
+    private String glueSource;
18 19
     private long glueUpdatetime;
19 20
 
20 21
     private int logId;
@@ -54,6 +55,14 @@ public class TriggerParam implements Serializable{
54 55
         this.glueType = glueType;
55 56
     }
56 57
 
58
+    public String getGlueSource() {
59
+        return glueSource;
60
+    }
61
+
62
+    public void setGlueSource(String glueSource) {
63
+        this.glueSource = glueSource;
64
+    }
65
+
57 66
     public long getGlueUpdatetime() {
58 67
         return glueUpdatetime;
59 68
     }

+ 2 - 18
xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java 查看文件

@@ -1,6 +1,5 @@
1 1
 package com.xxl.job.core.glue;
2 2
 
3
-import com.xxl.job.core.glue.loader.GlueLoader;
4 3
 import com.xxl.job.core.handler.IJobHandler;
5 4
 import groovy.lang.GroovyClassLoader;
6 5
 import org.slf4j.Logger;
@@ -27,17 +26,6 @@ public class GlueFactory implements ApplicationContextAware {
27 26
 	 * groovy class loader
28 27
 	 */
29 28
 	private GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
30
-	
31
-	/**
32
-	 * code source loader
33
-	 */
34
-	private GlueLoader glueLoader;
35
-	public void setGlueLoader(GlueLoader glueLoader) {
36
-		this.glueLoader = glueLoader;
37
-	}
38
-	public static boolean isActive() {
39
-		return GlueFactory.glueFactory.glueLoader!=null;
40
-	}
41 29
 
42 30
 	// ----------------------------- spring support -----------------------------
43 31
 	private static ApplicationContext applicationContext;
@@ -56,7 +44,7 @@ public class GlueFactory implements ApplicationContextAware {
56 44
 	 * inject action of spring
57 45
 	 * @param instance
58 46
 	 */
59
-	public void injectService(Object instance){
47
+	private void injectService(Object instance){
60 48
 		if (instance==null) {
61 49
 			return;
62 50
 		}
@@ -106,11 +94,7 @@ public class GlueFactory implements ApplicationContextAware {
106 94
 	
107 95
 	// ----------------------------- load instance -----------------------------
108 96
 	// load new instance, prototype
109
-	public IJobHandler loadNewInstance(int jobId) throws Exception{
110
-		if (jobId==0) {
111
-			return null;
112
-		}
113
-		String codeSource = glueLoader.load(jobId);
97
+	public IJobHandler loadNewInstance(String codeSource) throws Exception{
114 98
 		if (codeSource!=null && codeSource.trim().length()>0) {
115 99
 			Class<?> clazz = groovyClassLoader.parseClass(codeSource);
116 100
 			if (clazz != null) {

+ 2 - 11
xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml 查看文件

@@ -41,18 +41,9 @@
41 41
     <!-- ********************************* "GlueFactory" 配置, 仅在启动 "GLUE模式任务" 时才需要, 否则可删除 ********************************* -->
42 42
 
43 43
 	<!-- 配置03、GlueFactory -->
44
-	<bean id="glueFactory" class="com.xxl.job.core.glue.GlueFactory">
45
-		<!-- GLUE源码加载器,默认使用系统提供的 "DbGlueLoader", 推荐将其改为公共的RPC服务 -->
46
-		<property name="glueLoader" >
47
-            <!-- DbGlueLoader, 依赖 "XXL-JOB公共数据源" -->
48
-			<bean class="com.xxl.job.core.glue.loader.impl.DbGlueLoader" >
49
-				<!-- XXL-JOB公共数据源 -->
50
-				<property name="dataSource" ref="xxlJobDataSource" />
51
-			</bean>
52
-		</property>
53
-	</bean>
44
+	<bean id="glueFactory" class="com.xxl.job.core.glue.GlueFactory" />
54 45
 
55
-    <!-- ********************************* "XXL-JOB公共数据源" 配置, 仅在启动 "DbRegistHelper" 或 "DbGlueLoader" 时才需要, 否则可删除 ********************************* -->
46
+    <!-- ********************************* "XXL-JOB公共数据源" 配置, 仅在启动 "DbRegistHelper" 时才需要, 否则可删除 ********************************* -->
56 47
 
57 48
 	<!-- 配置04、XXL-JOB公共数据源 -->
58 49
 	<bean id="xxlJobDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">