From 552949167ebb0f8dc981cb3a02588c97335236e2 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Fri, 30 Sep 2016 10:58:11 +0800 Subject: [PATCH] =?UTF-8?q?GLUE=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E6=97=B6,=E6=89=A7=E8=A1=8C=E5=99=A8=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=94=AF=E6=8C=81GLUE=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1,=E6=A0=A1=E9=AA=8CGlueFactory=E7=9A=84gluelo?= =?UTF-8?q?ader=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/xxl/job/core/glue/GlueFactory.java | 7 +++++-- .../java/com/xxl/job/core/router/action/RunAction.java | 9 ++++++++- .../src/main/resources/applicationcontext-xxl-job.xml | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java index 278ec6c2..922daf9b 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java @@ -43,7 +43,10 @@ public class GlueFactory implements ApplicationContextAware { public void setGlueLoader(GlueLoader glueLoader) { this.glueLoader = glueLoader; } - + public static boolean isActive() { + return GlueFactory.glueFactory.glueLoader!=null; + } + // ----------------------------- spring support ----------------------------- private static ApplicationContext applicationContext; private static GlueFactory glueFactory; @@ -122,7 +125,7 @@ public class GlueFactory implements ApplicationContextAware { } // // load instance, singleton - public static String generateInstanceCacheKey(String job_group, String job_name){ + private static String generateInstanceCacheKey(String job_group, String job_name){ return job_group.concat("_").concat(job_name).concat("_instance"); } public IJobHandler loadInstance(String job_group, String job_name) throws Exception{ diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java b/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java index cd052db7..d1c44e5d 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/router/action/RunAction.java @@ -1,5 +1,6 @@ package com.xxl.job.core.router.action; +import com.xxl.job.core.glue.GlueFactory; import com.xxl.job.core.handler.IJobHandler; import com.xxl.job.core.handler.impl.GlueJobHandler; import com.xxl.job.core.router.HandlerRouter; @@ -25,7 +26,7 @@ public class RunAction extends IAction { if (!requestModel.isGlueSwitch()) { // bean model - // handler instance + // valid handler instance IJobHandler jobHandler = HandlerRouter.loadJobHandler(requestModel.getExecutorHandler()); if (jobHandler==null) { return new ResponseModel(ResponseModel.FAIL, "job handler for jobKey=[" + jobKey + "] not found."); @@ -46,6 +47,12 @@ public class RunAction extends IAction { } } else { // glue model + + // valid glueloader + if (!GlueFactory.isActive()) { + return new ResponseModel(ResponseModel.FAIL, "glueLoader for jobKey=[" + jobKey + "] not found."); + } + if (jobThread == null) { jobThread = HandlerRouter.registJobThread(jobKey, new GlueJobHandler(requestModel.getJobGroup(), requestModel.getJobName())); } else { diff --git a/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml index cef7668a..7a753629 100644 --- a/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml +++ b/xxl-job-executor-example/src/main/resources/applicationcontext-xxl-job.xml @@ -15,9 +15,10 @@ - + + - +