Skip to content

Commit

Permalink
保存图片和草稿
Browse files Browse the repository at this point in the history
  • Loading branch information
diguage committed May 22, 2022
1 parent b7380b5 commit c61cce7
Show file tree
Hide file tree
Showing 22 changed files with 2,103 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ $RECYCLE.BIN/

.vscode/

*.drawio.bkp
*.drawio.bkp

static/diagrams/*.svg
24 changes: 13 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env bash

rm -rf public

hugo --minify

cd ./public/

rsync -avz . [email protected]:/home/deployer/diguage.com/www

cd ..

echo -en "\n\nSucceed publishing...\n\n"
#rm -rf public
#
#hugo --minify
#
#cd ./public/
#
#rsync -avz . [email protected]:/home/deployer/diguage.com/www
#
#cd ..
#
#echo -en "\n\nSucceed publishing...\n\n"

bash ./static/diagrams/build.sh
2 changes: 2 additions & 0 deletions content/post/dive-into-encoding-and-character-set.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ thumbnail: "images/encoding/unicode-logo.svg"
weight: 1
---

TODO

:icons: font
:source-highlighter: pygments
:pygments-style: monokai
Expand Down
87 changes: 87 additions & 0 deletions content/post/hessian-protocol-interpretation-and-practice-4.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ thumbnail: "images/common/confused-target-vector.jpg"
weight: 1
---

TODO

:icons: font
:source-highlighter: pygments
:pygments-style: monokai
Expand All @@ -31,6 +33,91 @@ weight: 1
基础工具方法就不再赘述,请直接参考 https://www.diguage.com/post/hessian-protocol-interpretation-and-practice-1/#helper-methods[Hessian 协议解释与实战(一):基础工具方法^] 中提到的几个方法。


[#object]
== 对象

[plantuml, format=svg]
....
abstract class AbstractSerializerFactory {
+ Serializer getSerializer(Class cl);
+ Deserializer getDeserializer(Class cl);
}
class ExtSerializerFactory extends AbstractSerializerFactory
note bottom of ExtSerializerFactory : 没有被引用!
class SerializerFactory extends AbstractSerializerFactory
class BeanSerializerFactory extends SerializerFactory
class JMXSerializerFactory extends AbstractSerializerFactory
note bottom of JMXSerializerFactory : 序列化 JMX 对象。\n没有被引用!
....

[plantuml, format=svg]
....
scale 600 width
interface Serializer {
+ void writeObject(Object obj, AbstractHessianOutput out);
}
interface ObjectSerializer {
public Serializer getObjectSerializer();
}
abstract class AbstractSerializer implements Serializer
class AnnotationSerializer extends AbstractSerializer
class ArraySerializer extends AbstractSerializer
class BasicSerializer extends AbstractSerializer implements ObjectSerializer
class ByteArraySerializer extends AbstractSerializer implements ObjectSerializer
class BeanSerializer extends AbstractSerializer
class CalendarSerializer extends AbstractSerializer
class ClassSerializer extends AbstractSerializer
class CollectionSerializer extends AbstractSerializer
class EnumerationSerializer extends AbstractSerializer
class EnumSerializer extends AbstractSerializer
class InetAddressSerializer extends AbstractSerializer
class InputStreamSerializer extends AbstractSerializer
class IteratorSerializer extends AbstractSerializer
class JavaSerializer extends AbstractSerializer
class JavaUnsharedSerializer extends JavaSerializer
class LocaleSerializer extends AbstractSerializer
class MapSerializer extends AbstractSerializer
class ObjectHandleSerializer extends AbstractSerializer
class RemoteSerializer extends AbstractSerializer
class SqlDateSerializer extends AbstractSerializer
class StringValueSerializer extends AbstractSerializer
class UnsafeSerializer extends AbstractSerializer
class UnsafeUnsharedSerializer extends UnsafeSerializer
....


[#list]
== 链表数据
Expand Down
66 changes: 66 additions & 0 deletions content/post/hessian-source-analysis-for-java.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: "Hessian 源码分析(Java)"
date: 2022-05-21T09:39:44+08:00
draft: true
keywords: ["Hessian","序列化","协议","Java","微服务","架构","程序设计"]
tags: ["Java","微服务","架构","设计","序列化"]
categories: ["系统架构","程序设计"]
thumbnail: "images/common/confused-target-vector.jpg"

weight: 1
---

:icons: font
:source-highlighter: pygments
:pygments-style: monokai
:pygments-linenums-mode: table
:source_attr: indent=0
:image_attr: align=center,width=100%

前面通过几篇文章,解释并实践了一下 Hessian 的序列化协议。文章目录如下:

. https://www.diguage.com/post/hessian-protocol-interpretation-and-practice-1/[Hessian 协议解释与实战(一):布尔、日期、浮点数与整数^] -- 介绍布尔型数据、日期类型、浮点类型数据和整数类型数据等四种类型的数据的处理。
. https://www.diguage.com/post/hessian-protocol-interpretation-and-practice-2/[Hessian 协议解释与实战(二):长整型、二进制数据与 Null^] -- 介绍长整数类型数据、二进制数据和 `null` 等三种类型的数据的处理。
. https://www.diguage.com/post/hessian-protocol-interpretation-and-practice-3/[Hessian 协议解释与实战(三):字符串^] -- 专门介绍了关于字符串的处理。由于字符串需要铺垫的基础知识比较多,处理细节也有繁琐,所以单独成篇来介绍。
. 未完待续,敬请继续关注 https://www.diguage.com/["地瓜哥"博客网^]。

该系列第四篇文章准备详细介绍一下 Hessian 对对象、链表以及 `Map` 等处理。但是,越调试代码,越发觉得应该先对 Hessian 的实现做一个源码分析。于是,就有了本文。

这里有几点需要声明一下:

. 在上面“解释与实战”系列文章中提到的代码就不再重复说明。
. 通过“解释与实战”系列文章,大家应该可以领略到,处理序列化有大量的细节。但是,本文并不打算涉及。本文重点是介绍 Hessian 的 Java 实现的架构蓝图。相当于给指明一条路,沿着这条路,大家就可以探索 Hessian 的各种细节。

image::/images/marshal/hessian-architecture.svg[{image_attr}]

== 序列化时序图

image::/images/marshal/Hessian2Output-writeObject.svg[{image_attr}]

image::/images/marshal/Hessian2Input-readObject.svg[{image_attr}]

image::/images/marshal/hessian-AbstractSerializerFactory.svg[{image_attr}]

image::/images/marshal/hessian-AbstractHessianOutput.svg[{image_attr}]

image::/images/marshal/hessian-AbstractHessianInput.svg[{image_attr}]

image::/images/marshal/hessian-Serializer.svg[{image_attr}]

image::/images/marshal/hessian-Deserializer.svg[{image_attr}]


== 一些新发现

=== 对 `enum` 的支持



=== 日志打印

== 参考资料

. https://developer.aliyun.com/article/14698[hessian序列化源码分析^]



61 changes: 61 additions & 0 deletions static/diagrams/Hessian2Input-readObject.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
seqdiag {
edge_length = 200;

Acter => Hessian2Input[label="readObject()"] {
Hessian2Input => Hessian2Input[label="read()", note=" \n读取标志位\n_"];
=== 处理链表(含数组、List、Set、Iterator、Enumeration 等) ===
Hessian2Input => Hessian2Input[label="readType()", note=" \n读取类型信息\n_"] {
Hessian2Input => Hessian2Input[label="read()", note=" \n读取标志位\n_"];
Hessian2Input => Hessian2Input[label="readString()", note=" \n读取字符串\n这里包含了大量大量的细节!\n_"];
Hessian2Input => Hessian2Input[label="readInt()", note=" \n读取数字\n这里包含了大量大量的细节!\n_"];
}

Hessian2Input => Hessian2Input[label="findSerializerFactory()", note=" \n查找 SerializerFactory\n_"] {
Hessian2Input => SerializerFactory[label="createDefault()"];
}

Hessian2Input => SerializerFactory[label="readList(AbstractHessianInput in, int length, String type)"] {
SerializerFactory => SerializerFactory[label="getDeserializer(String type)", note=" \n后面处理流程一样,\n直接引用这里,\n不再重复声明!\n_"] {
SerializerFactory => SerializerFactory[label="loadSerializedClass(String className)"] {
SerializerFactory => ClassFactory[label="load(String className)"];
}
SerializerFactory => SerializerFactory[label="getDeserializer(String type)"] {
SerializerFactory => SerializerFactory[label="loadDeserializer(Class cl)"] {
SerializerFactory => AbstractSerializerFactory[label="getDeserializer(Class cl)"];
SerializerFactory => ContextSerializerFactory[label="getDeserializer(String className)"];
SerializerFactory => ContextSerializerFactory[label="create(ClassLoader loader)"];
SerializerFactory => ContextSerializerFactory[label="getDeserializer(String className)"];
SerializerFactory => ContextSerializerFactory[label="getCustomDeserializer(Class cl)"];
SerializerFactory => SerializerFactory[label="new", note=" \n这里上下有很多根据类型直接\n new出来的Deserializer实例\n_"];
}
}
}
SerializerFactory => Deserializer[label="readList(AbstractHessianInput in, int length)"];
SerializerFactory => CollectionDeserializer[label="readList(AbstractHessianInput in, int length)"];
}

=== 处理 Map ===
Hessian2Input => SerializerFactory[label="readMap(AbstractHessianInput in, String type)"] {
SerializerFactory => SerializerFactory[label="getDeserializer(String type)", note=" \n与上面处理链表中过程一样,\n不再重复声明!\n_"];
SerializerFactory => Deserializer[label="readMap(AbstractHessianInput in)"];
}

=== 处理 对象 ===
Hessian2Input => Hessian2Input[label="readObjectDefinition(Class<?> cl)", note=" \n读取对象定义\n_"] {
Hessian2Input => Hessian2Input[label="readString()", note=" \n读取字符串\n_"];
Hessian2Input => Hessian2Input[label="readInt()", note=" \n读取长度\n_"];
Hessian2Input => Hessian2Input[label="findSerializerFactory()", note=" \n查找 SerializerFactory\n_"] {
Hessian2Input => SerializerFactory[label="createDefault()"];
}
Hessian2Input => SerializerFactory[label="getObjectDeserializer(String type, Class cl)"] {
SerializerFactory => SerializerFactory[label="getObjectDeserializer(String type)"] {
SerializerFactory => SerializerFactory[label="getDeserializer(String type)", note=" \n与上面处理链表中过程一样,\n不再重复声明!\n_"];
}
}
}

Hessian2Input => Hessian2Input[label="readObject()", note=" \n读取对象\n递归调用自身\n_"];
}

=== D瓜哥 · https://www.diguage.com · 出品 ===
}
35 changes: 35 additions & 0 deletions static/diagrams/Hessian2Output-writeObject.diag
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
seqdiag {
edge_length = 150;

Acter => Hessian2Output[label="writeObject\n(Object object)"] {
Hessian2Output => AbstractHessianOutput[label="findSerializerFactory()", note=" \n查找 SerializerFactory\n_"] {
AbstractHessianOutput => SerializerFactory[label="createDefault()"];
}

Hessian2Output => SerializerFactory[label="getObjectSerializer(Class<?> cl)", note=" \n根据 Class 获得 Serializer\n_"] {
SerializerFactory => SerializerFactory[label="getSerializer\n(Class c)"] {
SerializerFactory => SerializerFactory[label="loadSerializer\n(Class cl)", note=" \n扩展点\n可以扫描出提前添加的 SerializerFactory\n_"] {
SerializerFactory => AbstractSerializerFactory[label="getSerializer(Class cl)"];

SerializerFactory => ContextSerializerFactory[label="getSerializer(String className)"];

SerializerFactory => ContextSerializerFactory[label="create(ClassLoader loader)"];

SerializerFactory => ContextSerializerFactory[label="getCustomSerializer(Class cl)", note=" \n扩展点\n根据 Class 获得自定义的 Serializer\n_"];

SerializerFactory => UnsafeSerializer[label="create(Class<?> cl)"];

SerializerFactory => JavaSerializer[label="create(Class<?> cl)"];

SerializerFactory => IteratorSerializer[label="create()"];

SerializerFactory => EnumerationSerializer[label="create()"];
}
}
}

Hessian2Output => Serializer[label="writeObject(Object obj, AbstractHessianOutput out)", leftnote=" \n将对象序列化\n_"];
}

=== D瓜哥 · https://www.diguage.com · 出品 ===
}
37 changes: 37 additions & 0 deletions static/diagrams/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# get base dir
baseDir=$(cd $(dirname $BASH_SOURCE) && pwd)
echo "baseDir=${baseDir}"

echo "start to convert ${baseDir}/Hessian2Output-writeObject.diag"
seqdiag -Tsvg ${baseDir}/Hessian2Output-writeObject.diag
cp -f ${baseDir}/Hessian2Output-writeObject.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/Hessian2Input-readObject.diag"
seqdiag -Tsvg ${baseDir}/Hessian2Input-readObject.diag
cp -f ${baseDir}/Hessian2Input-readObject.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-AbstractSerializerFactory.puml"
plantuml -tsvg ${baseDir}/hessian-AbstractSerializerFactory.puml
cp -f ${baseDir}/hessian-AbstractSerializerFactory.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-AbstractHessianOutput.puml"
plantuml -tsvg ${baseDir}/hessian-AbstractHessianOutput.puml
cp -f ${baseDir}/hessian-AbstractHessianOutput.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-AbstractHessianInput.puml"
plantuml -tsvg ${baseDir}/hessian-AbstractHessianInput.puml
cp -f ${baseDir}/hessian-AbstractHessianInput.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-Serializer.puml"
plantuml -tsvg ${baseDir}/hessian-Serializer.puml
cp -f ${baseDir}/hessian-Serializer.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-Deserializer.puml"
plantuml -tsvg ${baseDir}/hessian-Deserializer.puml
cp -f ${baseDir}/hessian-Deserializer.svg ${baseDir}/../images/marshal/

echo "start to convert ${baseDir}/hessian-architecture.puml"
plantuml -tsvg ${baseDir}/hessian-architecture.puml
cp -f ${baseDir}/hessian-architecture.svg ${baseDir}/../images/marshal/
37 changes: 37 additions & 0 deletions static/diagrams/hessian-AbstractHessianInput.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@startuml
skinparam titleFontSize 30
title **Hessian AbstractHessianInput 类图**

abstract class AbstractHessianInput {
+void setSerializerFactory(SerializerFactory ser)
+{abstract} boolean readBoolean()
+{abstract} void readNull()
+{abstract} int readInt()
+{abstract} long readLong()
+{abstract} double readDouble()
+{abstract} long readUTCDate()
+{abstract} String readString()
+{abstract} byte []readBytes()
+{abstract} Object readObject(Class expectedClass)
+{abstract} Object readObject()
+{abstract} Object readRef()
+{abstract} int addRef(Object obj)
+{abstract} void setRef(int i, Object obj)
+{abstract} int readListStart()
+{abstract} int readLength()
+{abstract} int readMapStart()
+{abstract} String readType()
+{abstract} boolean isEnd()
+{abstract} void readEnd()
+{abstract} void readMapEnd()
+{abstract} void readListEnd()
+void close()
}

class HessianInput extends AbstractHessianInput

class Hessian2Input extends AbstractHessianInput implements Hessian2Constants

skinparam footerFontSize 20
footer D瓜哥 · https://www.diguage.com · 出品
@enduml
Loading

0 comments on commit c61cce7

Please sign in to comment.