瀏覽代碼

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

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

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

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

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

58
         JobThread jobThread = XxlJobExecutor.loadJobThread(triggerParam.getJobId());
58
         JobThread jobThread = XxlJobExecutor.loadJobThread(triggerParam.getJobId());
59
 
59
 
60
         if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) {
60
         if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) {
61
-            // bean model
62
 
61
 
63
             // valid handler
62
             // valid handler
64
             IJobHandler jobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler());
63
             IJobHandler jobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler());
80
                 jobThread = XxlJobExecutor.registJobThread(triggerParam.getJobId(), jobHandler);
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
             // valid exists job thread:change handler or glue timeout, need kill old thread
84
             // valid exists job thread:change handler or glue timeout, need kill old thread
92
             if (jobThread != null &&
85
             if (jobThread != null &&
103
             if (jobThread == null) {
96
             if (jobThread == null) {
104
                 IJobHandler jobHandler = null;
97
                 IJobHandler jobHandler = null;
105
                 try {
98
                 try {
106
-                    jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getJobId());
99
+                    jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getGlueSource());
107
                 } catch (Exception e) {
100
                 } catch (Exception e) {
108
                     logger.error("", e);
101
                     logger.error("", e);
109
                     return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());
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
     private String executorParams;
15
     private String executorParams;
16
 
16
 
17
     private String glueType;
17
     private String glueType;
18
+    private String glueSource;
18
     private long glueUpdatetime;
19
     private long glueUpdatetime;
19
 
20
 
20
     private int logId;
21
     private int logId;
54
         this.glueType = glueType;
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
     public long getGlueUpdatetime() {
66
     public long getGlueUpdatetime() {
58
         return glueUpdatetime;
67
         return glueUpdatetime;
59
     }
68
     }

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

1
 package com.xxl.job.core.glue;
1
 package com.xxl.job.core.glue;
2
 
2
 
3
-import com.xxl.job.core.glue.loader.GlueLoader;
4
 import com.xxl.job.core.handler.IJobHandler;
3
 import com.xxl.job.core.handler.IJobHandler;
5
 import groovy.lang.GroovyClassLoader;
4
 import groovy.lang.GroovyClassLoader;
6
 import org.slf4j.Logger;
5
 import org.slf4j.Logger;
27
 	 * groovy class loader
26
 	 * groovy class loader
28
 	 */
27
 	 */
29
 	private GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
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
 	// ----------------------------- spring support -----------------------------
30
 	// ----------------------------- spring support -----------------------------
43
 	private static ApplicationContext applicationContext;
31
 	private static ApplicationContext applicationContext;
56
 	 * inject action of spring
44
 	 * inject action of spring
57
 	 * @param instance
45
 	 * @param instance
58
 	 */
46
 	 */
59
-	public void injectService(Object instance){
47
+	private void injectService(Object instance){
60
 		if (instance==null) {
48
 		if (instance==null) {
61
 			return;
49
 			return;
62
 		}
50
 		}
106
 	
94
 	
107
 	// ----------------------------- load instance -----------------------------
95
 	// ----------------------------- load instance -----------------------------
108
 	// load new instance, prototype
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
 		if (codeSource!=null && codeSource.trim().length()>0) {
98
 		if (codeSource!=null && codeSource.trim().length()>0) {
115
 			Class<?> clazz = groovyClassLoader.parseClass(codeSource);
99
 			Class<?> clazz = groovyClassLoader.parseClass(codeSource);
116
 			if (clazz != null) {
100
 			if (clazz != null) {

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

41
     <!-- ********************************* "GlueFactory" 配置, 仅在启动 "GLUE模式任务" 时才需要, 否则可删除 ********************************* -->
41
     <!-- ********************************* "GlueFactory" 配置, 仅在启动 "GLUE模式任务" 时才需要, 否则可删除 ********************************* -->
42
 
42
 
43
 	<!-- 配置03、GlueFactory -->
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
 	<!-- 配置04、XXL-JOB公共数据源 -->
48
 	<!-- 配置04、XXL-JOB公共数据源 -->
58
 	<bean id="xxlJobDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
49
 	<bean id="xxlJobDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">