sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

Custom serializer register #1296

Closed Lo1nt closed 1 year ago

Lo1nt commented 1 year ago

Motivation:

Currently, the custom serializer is registered by static code block. And once it registered, it could not be modified.

When there are several classes that register custom serializer, the sequence, dependents on sequence of class loading, is unpredictable, and unmodifiable.

Thus, there's no way we define our own serializer (say, for SofaRequest.Class).

The pr here is aiming at making custom serializer registration sequentially.

P.S. And we here still don't want to change the unmodifiable feature (Once a serializer registered, it can never be changed).

Modification:

Apply extension-loader mechanism to let the register work in sequence.

Still, there is an override feature for extension loader, which enables us to substitute the origin register provided by sofa rpc.

Result:

  1. Let all register become instance managed by ExtensionLoader.
  2. Change call to static register method to get Extension instance and then call instances' register method.
codecov[bot] commented 1 year ago

Codecov Report

Merging #1296 (66cae3f) into master (a9af9cd) will decrease coverage by 0.01%. The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #1296      +/-   ##
============================================
- Coverage     71.95%   71.95%   -0.01%     
+ Complexity      784      783       -1     
============================================
  Files           415      416       +1     
  Lines         17654    17659       +5     
  Branches       2752     2752              
============================================
+ Hits          12703    12706       +3     
  Misses         3549     3549              
- Partials       1402     1404       +2     
Impacted Files Coverage Δ
...in/java/com/alipay/sofa/rpc/common/RpcOptions.java 100.00% <ø> (ø)
.../rpc/codec/bolt/AbstractSerializationRegister.java 100.00% <100.00%> (ø)
...a/rpc/codec/bolt/SofaRpcSerializationRegister.java 81.81% <100.00%> (+9.09%) :arrow_up:
...ipay/sofa/rpc/server/bolt/BoltServerProcessor.java 65.33% <100.00%> (+0.46%) :arrow_up:
...y/sofa/rpc/transport/bolt/BoltClientTransport.java 85.88% <100.00%> (+0.17%) :arrow_up:

... and 4 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.