Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the SPI ClassLoader mechanism to handle more complex scenarios #1088

Merged
merged 2 commits into from
Oct 23, 2019

Conversation

sczyh30
Copy link
Member

@sczyh30 sczyh30 commented Oct 15, 2019

Describe what this PR does / why we need it

Improve the SPI ClassLoader mechanism to handle more complex scenarios.

Does this pull request fix one issue?

Resolves #1087

Describe how you did it

  • Add a property csp.sentinel.spi.classloader to indicate which ClassLoader should be used when loading SPI implementations. By default Sentinel will use the default ClassLoader (i.e. clazz.getClassLoader()). Only if the property is set to context, Sentinel will try to load SPI implementations with the thread context ClassLoader.
  • Add a ServiceLoaderUtil class as the universal ServiceLoader wrapper, and improve the SpiLoader.
  • Change all SPI providers to use ServiceLoaderUtil instead.

Describe how to verify it

Run all test cases and demo.

Special notes for reviews

This PR contains internal breaking change. Please verify it in scenarios with advanced ClassLoader mechanism.

… SpiLoader

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
@sczyh30 sczyh30 added kind/enhancement Category issues or prs related to enhancement. to-review To review labels Oct 15, 2019
@codecov-io
Copy link

Codecov Report

Merging #1088 into master will increase coverage by 0.06%.
The diff coverage is 47.22%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1088      +/-   ##
============================================
+ Coverage      42.7%   42.76%   +0.06%     
- Complexity     1491     1494       +3     
============================================
  Files           319      320       +1     
  Lines          9378     9383       +5     
  Branches       1279     1278       -1     
============================================
+ Hits           4005     4013       +8     
+ Misses         4878     4875       -3     
  Partials        495      495
Impacted Files Coverage Δ Complexity Δ
...om/alibaba/csp/sentinel/config/SentinelConfig.java 57.74% <ø> (ø) 14 <0> (ø) ⬇️
.../sentinel/cluster/server/TokenServiceProvider.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...ter/server/processor/RequestProcessorProvider.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...va/com/alibaba/csp/sentinel/init/InitExecutor.java 60.52% <100%> (ø) 6 <0> (ø) ⬇️
...baba/csp/sentinel/slotchain/SlotChainProvider.java 70% <100%> (+6.84%) 3 <0> (-2) ⬇️
.../java/com/alibaba/csp/sentinel/util/SpiLoader.java 16.32% <47.61%> (+7.68%) 4 <2> (+2) ⬆️
...om/alibaba/csp/sentinel/spi/ServiceLoaderUtil.java 60% <60%> (ø) 2 <2> (?)
...a/csp/sentinel/slots/statistic/base/LeapArray.java 67.32% <0%> (-2.98%) 33% <0%> (-1%)
...p/sentinel/datasource/consul/ConsulDataSource.java 69.56% <0%> (+4.34%) 7% <0%> (ø) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 826447b...20789ef. Read the comment docs.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sczyh30 sczyh30 merged commit b090554 into alibaba:master Oct 23, 2019
@sczyh30 sczyh30 removed the to-review To review label Oct 23, 2019
@sczyh30 sczyh30 deleted the spi-classloader branch October 23, 2019 11:21
@sczyh30 sczyh30 added this to the 1.7.0 milestone Oct 23, 2019
CST11021 pushed a commit to CST11021/Sentinel that referenced this pull request Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the SPI classloader mechanism
2 participants