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

v1.7
xueli.xue 8 years ago
parent 617ed69727
commit 1b3ad6fbbe

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

@ -58,7 +58,6 @@ public class ExecutorBizImpl implements ExecutorBiz {
JobThread jobThread = XxlJobExecutor.loadJobThread(triggerParam.getJobId()); JobThread jobThread = XxlJobExecutor.loadJobThread(triggerParam.getJobId());
if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) { if (GlueTypeEnum.BEAN==GlueTypeEnum.match(triggerParam.getGlueType())) {
// bean model
// valid handler // valid handler
IJobHandler jobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler()); IJobHandler jobHandler = XxlJobExecutor.loadJobHandler(triggerParam.getExecutorHandler());
@ -80,13 +79,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
jobThread = XxlJobExecutor.registJobThread(triggerParam.getJobId(), jobHandler); jobThread = XxlJobExecutor.registJobThread(triggerParam.getJobId(), jobHandler);
} }
} else { } else if (GlueTypeEnum.GLUE_GROOVY==GlueTypeEnum.match(triggerParam.getGlueType())) {
// glue model
// valid glueloader
if (!GlueFactory.isActive()) {
return new ReturnT<String>(ReturnT.FAIL_CODE, "glueLoader for JobId=[" + triggerParam.getJobId() + "] not found.");
}
// valid exists job threadchange handler or glue timeout, need kill old thread // valid exists job threadchange handler or glue timeout, need kill old thread
if (jobThread != null && if (jobThread != null &&
@ -103,7 +96,7 @@ public class ExecutorBizImpl implements ExecutorBiz {
if (jobThread == null) { if (jobThread == null) {
IJobHandler jobHandler = null; IJobHandler jobHandler = null;
try { try {
jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getJobId()); jobHandler = GlueFactory.getInstance().loadNewInstance(triggerParam.getGlueSource());
} catch (Exception e) { } catch (Exception e) {
logger.error("", e); logger.error("", e);
return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage()); return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());

@ -15,6 +15,7 @@ public class TriggerParam implements Serializable{
private String executorParams; private String executorParams;
private String glueType; private String glueType;
private String glueSource;
private long glueUpdatetime; private long glueUpdatetime;
private int logId; private int logId;
@ -54,6 +55,14 @@ public class TriggerParam implements Serializable{
this.glueType = glueType; this.glueType = glueType;
} }
public String getGlueSource() {
return glueSource;
}
public void setGlueSource(String glueSource) {
this.glueSource = glueSource;
}
public long getGlueUpdatetime() { public long getGlueUpdatetime() {
return glueUpdatetime; return glueUpdatetime;
} }

@ -1,6 +1,5 @@
package com.xxl.job.core.glue; package com.xxl.job.core.glue;
import com.xxl.job.core.glue.loader.GlueLoader;
import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.IJobHandler;
import groovy.lang.GroovyClassLoader; import groovy.lang.GroovyClassLoader;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -27,17 +26,6 @@ public class GlueFactory implements ApplicationContextAware {
* groovy class loader * groovy class loader
*/ */
private GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); private GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
/**
* code source loader
*/
private GlueLoader glueLoader;
public void setGlueLoader(GlueLoader glueLoader) {
this.glueLoader = glueLoader;
}
public static boolean isActive() {
return GlueFactory.glueFactory.glueLoader!=null;
}
// ----------------------------- spring support ----------------------------- // ----------------------------- spring support -----------------------------
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
@ -56,7 +44,7 @@ public class GlueFactory implements ApplicationContextAware {
* inject action of spring * inject action of spring
* @param instance * @param instance
*/ */
public void injectService(Object instance){ private void injectService(Object instance){
if (instance==null) { if (instance==null) {
return; return;
} }
@ -106,11 +94,7 @@ public class GlueFactory implements ApplicationContextAware {
// ----------------------------- load instance ----------------------------- // ----------------------------- load instance -----------------------------
// load new instance, prototype // load new instance, prototype
public IJobHandler loadNewInstance(int jobId) throws Exception{ public IJobHandler loadNewInstance(String codeSource) throws Exception{
if (jobId==0) {
return null;
}
String codeSource = glueLoader.load(jobId);
if (codeSource!=null && codeSource.trim().length()>0) { if (codeSource!=null && codeSource.trim().length()>0) {
Class<?> clazz = groovyClassLoader.parseClass(codeSource); Class<?> clazz = groovyClassLoader.parseClass(codeSource);
if (clazz != null) { if (clazz != null) {

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

Loading…
Cancel
Save