|
@@ -33,9 +33,7 @@ public class GlueFactory {
|
33
|
33
|
* groovy class loader
|
34
|
34
|
*/
|
35
|
35
|
private GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
|
36
|
|
-
|
37
|
|
- private static final ConcurrentHashMap<String, Class<?>> CLASS_CACHE = new ConcurrentHashMap<>();
|
38
|
|
- private static final ConcurrentHashMap<Long, String> JOBID_MD5KEY_CACHE = new ConcurrentHashMap<>();
|
|
36
|
+ private ConcurrentHashMap<String, Class<?>> CLASS_CACHE = new ConcurrentHashMap<>();
|
39
|
37
|
|
40
|
38
|
/**
|
41
|
39
|
* load new instance, prototype
|
|
@@ -44,9 +42,9 @@ public class GlueFactory {
|
44
|
42
|
* @return
|
45
|
43
|
* @throws Exception
|
46
|
44
|
*/
|
47
|
|
- public IJobHandler loadNewInstance(long jobId, String codeSource) throws Exception{
|
|
45
|
+ public IJobHandler loadNewInstance(String codeSource) throws Exception{
|
48
|
46
|
if (codeSource!=null && codeSource.trim().length()>0) {
|
49
|
|
- Class<?> clazz = getCodeSourceClass(jobId, codeSource);
|
|
47
|
+ Class<?> clazz = getCodeSourceClass(codeSource);
|
50
|
48
|
if (clazz != null) {
|
51
|
49
|
Object instance = clazz.newInstance();
|
52
|
50
|
if (instance!=null) {
|
|
@@ -62,38 +60,30 @@ public class GlueFactory {
|
62
|
60
|
}
|
63
|
61
|
throw new IllegalArgumentException(">>>>>>>>>>> xxl-glue, loadNewInstance error, instance is null");
|
64
|
62
|
}
|
65
|
|
-
|
66
|
|
- /**
|
67
|
|
- * inject service of bean field
|
68
|
|
- *
|
69
|
|
- * @param instance
|
70
|
|
- */
|
71
|
|
- public void injectService(Object instance) {
|
72
|
|
- // do something
|
73
|
|
- }
|
74
|
|
-
|
75
|
|
- private Class<?> getCodeSourceClass(long jobId, String codeSource){
|
|
63
|
+ private Class<?> getCodeSourceClass(String codeSource){
|
76
|
64
|
try {
|
77
|
|
- MessageDigest md = MessageDigest.getInstance("MD5");
|
78
|
|
- byte[] md5 = md.digest(codeSource.getBytes());
|
79
|
|
- BigInteger no = new BigInteger(1, md5);
|
80
|
|
- String md5Str = no.toString(16);
|
|
65
|
+ // md5
|
|
66
|
+ byte[] md5 = MessageDigest.getInstance("MD5").digest(codeSource.getBytes());
|
|
67
|
+ String md5Str = new BigInteger(1, md5).toString(16);
|
|
68
|
+
|
81
|
69
|
Class<?> clazz = CLASS_CACHE.get(md5Str);
|
82
|
70
|
if(clazz == null){
|
83
|
71
|
clazz = groovyClassLoader.parseClass(codeSource);
|
84
|
|
- Class<?> preClazz = CLASS_CACHE.putIfAbsent(md5Str, clazz);
|
85
|
|
-
|
86
|
|
- // 如果代碼有變化則刪除之前class緩存
|
87
|
|
- if(preClazz == null){
|
88
|
|
- String preMd5 = JOBID_MD5KEY_CACHE.put(jobId, md5Str);
|
89
|
|
- if(preMd5 != null){
|
90
|
|
- CLASS_CACHE.remove(preMd5);
|
91
|
|
- }
|
92
|
|
- }
|
|
72
|
+ CLASS_CACHE.putIfAbsent(md5Str, clazz);
|
93
|
73
|
}
|
94
|
74
|
return clazz;
|
95
|
75
|
} catch (Exception e) {
|
96
|
76
|
return groovyClassLoader.parseClass(codeSource);
|
97
|
77
|
}
|
98
|
78
|
}
|
|
79
|
+
|
|
80
|
+ /**
|
|
81
|
+ * inject service of bean field
|
|
82
|
+ *
|
|
83
|
+ * @param instance
|
|
84
|
+ */
|
|
85
|
+ public void injectService(Object instance) {
|
|
86
|
+ // do something
|
|
87
|
+ }
|
|
88
|
+
|
99
|
89
|
}
|