Browse Source

底层RPC序列化协议调整为hessian2;

xuxueli 7 years ago
parent
commit
61f1c5f158

+ 4 - 3
doc/XXL-JOB官方文档.md View File

1268
 - 29、GLUE脚本文件自动清理功能,及时清理过期脚本文件;
1268
 - 29、GLUE脚本文件自动清理功能,及时清理过期脚本文件;
1269
 - 30、执行器注册方式切换优化,切换自动注册时主动同步在线机器,避免执行器为空的问题;
1269
 - 30、执行器注册方式切换优化,切换自动注册时主动同步在线机器,避免执行器为空的问题;
1270
 - 31、跨平台:除了提供Java、Python、PHP等十来种任务模式之外,新增提供基于HTTP的任务模式;
1270
 - 31、跨平台:除了提供Java、Python、PHP等十来种任务模式之外,新增提供基于HTTP的任务模式;
1271
-- 32、【迭代中】分片任务失败重试优化,仅重试当前失败的分片;
1272
-- 33、【迭代中】支持通过API服务操作任务信息;
1273
-- 34、【迭代中】底层RPC协议更换为hessian2;
1271
+- 32、底层RPC序列化协议调整为hessian2;
1272
+- 33、【迭代中】分片任务失败重试优化,仅重试当前失败的分片;
1273
+- 34、【迭代中】支持通过API服务操作任务信息;
1274
+
1274
 
1275
 
1275
 
1276
 
1276
 ### TODO LIST
1277
 ### TODO LIST

+ 31 - 6
xxl-job-core/src/main/java/com/xxl/job/core/rpc/serialize/HessianSerializer.java View File

1
 package com.xxl.job.core.rpc.serialize;
1
 package com.xxl.job.core.rpc.serialize;
2
 
2
 
3
-import com.caucho.hessian.io.HessianInput;
4
-import com.caucho.hessian.io.HessianOutput;
3
+import com.caucho.hessian.io.Hessian2Input;
4
+import com.caucho.hessian.io.Hessian2Output;
5
 
5
 
6
 import java.io.ByteArrayInputStream;
6
 import java.io.ByteArrayInputStream;
7
 import java.io.ByteArrayOutputStream;
7
 import java.io.ByteArrayOutputStream;
15
 
15
 
16
 	public static <T> byte[] serialize(T obj){
16
 	public static <T> byte[] serialize(T obj){
17
 		ByteArrayOutputStream os = new ByteArrayOutputStream();
17
 		ByteArrayOutputStream os = new ByteArrayOutputStream();
18
-		HessianOutput ho = new HessianOutput(os);
18
+		Hessian2Output ho = new Hessian2Output(os);
19
 		try {
19
 		try {
20
 			ho.writeObject(obj);
20
 			ho.writeObject(obj);
21
+			ho.flush();
22
+			byte[] result = os.toByteArray();
23
+			return result;
21
 		} catch (IOException e) {
24
 		} catch (IOException e) {
22
 			throw new IllegalStateException(e.getMessage(), e);
25
 			throw new IllegalStateException(e.getMessage(), e);
26
+		} finally {
27
+			try {
28
+				ho.close();
29
+			} catch (IOException e) {
30
+				throw new IllegalStateException(e.getMessage(), e);
31
+			}
32
+			try {
33
+				os.close();
34
+			} catch (IOException e) {
35
+				throw new IllegalStateException(e.getMessage(), e);
36
+			}
23
 		}
37
 		}
24
-		return os.toByteArray();
25
 	}
38
 	}
26
 
39
 
27
 	public static <T> Object deserialize(byte[] bytes, Class<T> clazz) {
40
 	public static <T> Object deserialize(byte[] bytes, Class<T> clazz) {
28
 		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
41
 		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
29
-		HessianInput hi = new HessianInput(is);
42
+		Hessian2Input hi = new Hessian2Input(is);
30
 		try {
43
 		try {
31
-			return hi.readObject();
44
+			Object result = hi.readObject();
45
+			return result;
32
 		} catch (IOException e) {
46
 		} catch (IOException e) {
33
 			throw new IllegalStateException(e.getMessage(), e);
47
 			throw new IllegalStateException(e.getMessage(), e);
48
+		} finally {
49
+			try {
50
+				hi.close();
51
+			} catch (Exception e) {
52
+				throw new IllegalStateException(e.getMessage(), e);
53
+			}
54
+			try {
55
+				is.close();
56
+			} catch (IOException e) {
57
+				throw new IllegalStateException(e.getMessage(), e);
58
+			}
34
 		}
59
 		}
35
 	}
60
 	}
36
 	
61