From 66adbd687faf8ae1298d9f2268dec2aee65cec95 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Fri, 20 May 2016 21:05:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4clazz=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/client/glue/GlueFactory.java | 47 +++++-------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/xxl-job-client/src/main/java/com/xxl/job/client/glue/GlueFactory.java b/xxl-job-client/src/main/java/com/xxl/job/client/glue/GlueFactory.java index 946409f9..795b1d09 100644 --- a/xxl-job-client/src/main/java/com/xxl/job/client/glue/GlueFactory.java +++ b/xxl-job-client/src/main/java/com/xxl/job/client/glue/GlueFactory.java @@ -101,48 +101,25 @@ public class GlueFactory implements ApplicationContextAware { } // ----------------------------- load instance ----------------------------- - - // load class, - public static String generateClassCacheKey(String job_group, String job_name){ - return job_group.concat("_").concat(job_name).concat("_class"); - } - public Class loadClass(String job_group, String job_name) throws Exception{ + // load new instance, prototype + public IJobHandler loadNewInstance(String job_group, String job_name) throws Exception{ if (job_group==null || job_group.trim().length()==0 || job_name==null || job_name.trim().length()==0) { return null; } - String cacheClassKey = generateClassCacheKey(job_group, job_name); - Object cacheClass = LocalCache.getInstance().get(cacheClassKey); - if (cacheClass != null) { - return (Class) cacheClass; - } String codeSource = glueLoader.load(job_group, job_name); if (codeSource!=null && codeSource.trim().length()>0) { Class clazz = groovyClassLoader.parseClass(codeSource); - if (clazz!=null) { - LocalCache.getInstance().set(cacheClassKey, clazz, cacheTimeout); - logger.info(">>>>>>>>>>>> xxl-glue, fresh class, cacheClassKey:{}", cacheClassKey); - return clazz; - } - } - return null; - } - - // load new instance, prototype - public IJobHandler loadNewInstance(String job_group, String job_name) throws Exception{ - if (job_group==null || job_group.trim().length()==0 || job_name==null || job_name.trim().length()==0) { - return null; - } - Class clazz = loadClass(job_group, job_name); - if (clazz!=null) { - Object instance = clazz.newInstance(); - if (instance!=null) { - if (!(instance instanceof IJobHandler)) { - throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, " - + "cannot convert from instance["+ instance.getClass() +"] to IJobHandler"); + if (clazz != null) { + Object instance = clazz.newInstance(); + if (instance!=null) { + if (instance instanceof IJobHandler) { + this.injectService(instance); + return (IJobHandler) instance; + } else { + throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, " + + "cannot convert from instance["+ instance.getClass() +"] to IJobHandler"); + } } - - this.injectService(instance); - return (IJobHandler) instance; } } throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null");