-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Add SPI Interface ApplicationLifecycleManager for dubbo-core refactor #12750
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
Merged
AlbumenJ
merged 119 commits into
apache:3.3-config-api-refactor
from
namelessssssssssss:dubbo-core-ref-lifemanager
Sep 10, 2023
Merged
Add SPI Interface ApplicationLifecycleManager for dubbo-core refactor #12750
AlbumenJ
merged 119 commits into
apache:3.3-config-api-refactor
from
namelessssssssssss:dubbo-core-ref-lifemanager
Sep 10, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Code style fix * Remove unused dependencies from dubbo-config-api
… and MetricsApplicationLifecycle
… dubbo-core-ref-lifemanager
… dubbo-core-ref-lifemanager
… dubbo-core-ref-lifemanager
… dubbo-core-ref-lifemanager
… dubbo-core-ref-lifemanager
… dubbo-core-ref-lifemanager
Contributor
Author
|
@qinliujie PTAL |
|
Kudos, SonarCloud Quality Gate passed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.








What is the purpose of the change
Through the new SPI interface ApplicationLifecycle, the life cycle management method of each module in dubbo-config is dispersed back to each module itself, so as to minimize the dubbo-config dependency.
ModelContext is the internal lifecycle attribute aggregate of ScopeModel. It acts as context of model lifecycle, and provides a way to trigger a model life-changing process.
This allows Deployer's responsibility to be a pure process managing, without fields related to the current state of life.
Brief changelog
Call sequence of lifecycles
Full changelog (Chinese)
Lifecycle 相关变更
变动的中心为:添加 ApplicationLifecycle SPI接口,其提供了几个生命周期管理方法,随着DefaultApplicationDeployer 中对应的方法而调用。
包括 :
start-应用启动时调用
initialize-应用初始化时调用,早于start
preDestroy 应用关闭前调用
postDestroy 应用关闭后调用
preModuleChanged、postModuleChanged 应用中模块状态发生变化时调用
refreshServiceInstance 应用中新模块注册时调用
1、该接口的实现通过@activate + 多个实现的形式来实现加载顺序的编排操作,整体加载顺序如下:

https://boardmix.cn/app/share/CAE.CJbbqwwgASoQLZUgu_72RIU63KXPgkKo7DAGQAE/AhUMjA,
点击链接加入boardmix中的文件「未命名文件」
编排后Lifecycle实现的调用顺序保证与原有DefaultApplicationDeployer中的逻辑调用顺序相同。
2、dubbo-config-api解耦的最终目标是使其依赖关系反转,使所有外部模块依赖它,而其本身不依赖外部模块。
但由于dubbo-config-api的依赖尚未完全解耦,目前暂时保留大多数模块的依赖,因此这些实现暂时放在config-api包中,防止循环依赖。这些实现对应的SPI声明文件已放在它应在的包中。
3、拆分的指导思想是:尽量复用原有的逻辑,且保证不改变语义。Lifecycle实现中大多数方法是对原有DefaultApplicationDeployer中逻辑的重新编排,保证最大程度的兼容性。
按照加载流程分析拆分出的实现:
initialize:

preDestroy:
该方法共两个实现,ApplicationOfflineLifecycle 和 MetricsApplicationLifecycle
首先,ApplicationOfflineLifecycle 在应用关闭时注销元数据服务(注销所有模块中服务的url)
最后,MetricsApplicationLifecycle 注销指标服务。
postDestroy:
该方法共两个实现,RegistryApplicationLifecycle 和 MetadataApplicationLifecycle,分别完成服务在注册中心的注销操作和服务在元数据中心的注销操作。
pre/postModuleChanged:
应用下的模块状态发生变化时,该方法会被调用。
preModuleChanged:
首先,MetricsExportApplicationLifecycle先被调用。如果其判断状态发生变化的模块的新状态为已开始,(STARTED),且当前应用未完成注册,会尝试导出指标服务。
之后,RegistryApplicaitonLifecycle 若判断状态发生变化的模块的新状态为已开始,且当前服务为未注册,会将当前服务标记为已注册,执行服务注册逻辑。
之后执行postModuleChanged:
MetricsApplicationLifecycle 被调用。如果它判断模块新状态为已开始,且当前应用的状态为启动中(Starting),会执行指标收集器初始化的相关逻辑。
RegistryApplicationLifecycle 也会被调用。如果模块的新状态不是正在启动(Starting),它会刷新应用元数据。
refreshServiceInstance:
该方法只被MetadataApplicationLifecycle实现,在应用下有新模块启动时被调用。每次被调用都会刷新当前应用的元数据和实例信息。
其它变更