移除clazz缓存

v1.3
xueli.xue 9 years ago
parent 6717d8d590
commit 66adbd687f

@ -101,48 +101,25 @@ public class GlueFactory implements ApplicationContextAware {
} }
// ----------------------------- load instance ----------------------------- // ----------------------------- load instance -----------------------------
// load new instance, prototype
// load class, public IJobHandler loadNewInstance(String job_group, String job_name) throws Exception{
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{
if (job_group==null || job_group.trim().length()==0 || job_name==null || job_name.trim().length()==0) { if (job_group==null || job_group.trim().length()==0 || job_name==null || job_name.trim().length()==0) {
return null; 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); String codeSource = glueLoader.load(job_group, job_name);
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) {
LocalCache.getInstance().set(cacheClassKey, clazz, cacheTimeout); Object instance = clazz.newInstance();
logger.info(">>>>>>>>>>>> xxl-glue, fresh class, cacheClassKey:{}", cacheClassKey); if (instance!=null) {
return clazz; if (instance instanceof IJobHandler) {
} this.injectService(instance);
} return (IJobHandler) instance;
return null; } else {
} throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, "
+ "cannot convert from instance["+ instance.getClass() +"] to IJobHandler");
// 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");
} }
this.injectService(instance);
return (IJobHandler) instance;
} }
} }
throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null"); throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null");

Loading…
Cancel
Save