Destroy default ApplicationModel instance to restart dubbo service programmatically
Destroy default ApplicationModel instance, so that DubboBootstrap#stop() can thoroughly destroyed
The following code will run normally :
public class Main {
public static void main(String[] args) throws Exception {
// code1
// PojoUtils.isPojo(PojoUtils.class);
DubboBootstrap bootstrap = DubboBootstrap.newInstance(FrameworkModel.defaultModel())
.protocol(new ProtocolConfig(CommonConstants.DUBBO, 50051))
.service(ServiceBuilder.newBuilder().interfaceClass(DemoService.class).ref(new DemoServiceImpl()).build())
.start();
// stop it
bootstrap.stop();
// create new instance and restart it
bootstrap = DubboBootstrap.newInstance(FrameworkModel.defaultModel())
.protocol(new ProtocolConfig(CommonConstants.DUBBO, 50051))
.service(ServiceBuilder.newBuilder().interfaceClass(DemoService.class).ref(new DemoServiceImpl()).build())
.start();
bootstrap.stop();
}
public interface DemoService {
String sayHello(String name);
}
public static class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
return "Hello " + name + ", response from provider.";
}
}
}
But, if cancel comment at line 5, and run the code will get a IllegalStateException: ExtensionDirector is destroyed.
Because static property of PojoUtils#GENERIC_WITH_CLZ will create instance of ApplicationModel,and will cause the method of FrameworkModel#notifyProtocolDestroy never invoked, so DubboBootstrap#stop not thoroughly destroyed !
This commit fixed this question.
Checklist
- [x] Make sure there is a GitHub_issue field for the change.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
- [x] Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 60.45%. Comparing base (
89a7375) to head (da5ab3a). Report is 1 commits behind head on 3.3.
Additional details and impacted files
@@ Coverage Diff @@
## 3.3 #15457 +/- ##
============================================
- Coverage 60.94% 60.45% -0.50%
+ Complexity 11443 9652 -1791
============================================
Files 1888 1888
Lines 86327 86375 +48
Branches 12945 12958 +13
============================================
- Hits 52616 52221 -395
- Misses 28282 28667 +385
- Partials 5429 5487 +58
| Flag | Coverage Δ | |
|---|---|---|
| integration-tests-java17 | ? |
|
| integration-tests-java8 | ? |
|
| samples-tests-java17 | 31.46% <84.61%> (+<0.01%) |
:arrow_up: |
| samples-tests-java8 | 29.22% <84.61%> (-0.05%) |
:arrow_down: |
| unit-tests | 58.85% <100.00%> (-0.04%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
see https://github.com/apache/dubbo-integration-cases/blob/main/99-integration/dubbo-samples-memory-tri-server/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
destroy current FrameworkModel doesn't mean all ApplicationModels could be destroyed.
How can I make this PR example code pass the test without any exceptions?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: zrlw @.> Sent: Saturday, June 14, 2025 12:30:28 PM To: apache/dubbo @.> Cc: kfyty @.>; Author @.> Subject: Re: [apache/dubbo] Destroy default ApplicationModel instance, so DubboBootstrap#stop() can thoroughly destroyed (PR #15457)
[https://avatars.githubusercontent.com/u/40652892?s=20&v=4]zrlw left a comment (apache/dubbo#15457)https://github.com/apache/dubbo/pull/15457#issuecomment-2972247256
see https://github.com/apache/dubbo-integration-cases/blob/main/99-integration/dubbo-samples-memory-tri-server/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java
destroy current FrameworkModel doesn't mean all ApplicationModels could be destroyed.
― Reply to this email directly, view it on GitHubhttps://github.com/apache/dubbo/pull/15457#issuecomment-2972247256, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKZLIJUEBX4PURGO6MESR5D3DOQOJAVCNFSM6AAAAAB7HR4WV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZSGI2DOMRVGY. You are receiving this because you authored the thread.Message ID: @.***>
How can I make this PR example code pass the test without any exceptions?
No, you couldn't because this is by design, at least for now.
the simplest way might be destroying all your application models to empty pubApplicationModels of FrameworkModel before stop the bootstrap:
// if you have other application models, destroy all of them like this.
ApplicationModel.defaultModel().destroy();
// then stop the bootstrap.
bootstrap.stop();
by now, it's not easy to restart dubbo service programmatically, there are a lot of work to do.
Is there a development plan in the community that supports DubboBootstrap restart?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: zrlw @.> Sent: Monday, June 23, 2025 12:26:31 PM To: apache/dubbo @.> Cc: kfyty @.>; Author @.> Subject: Re: [apache/dubbo] Destroy default ApplicationModel instance, so DubboBootstrap#stop() can thoroughly destroyed (PR #15457)
[https://avatars.githubusercontent.com/u/40652892?s=20&v=4]zrlw left a comment (apache/dubbo#15457)https://github.com/apache/dubbo/pull/15457#issuecomment-2994870895
by now, it's not easy to restart dubbo application by program, there are a lot of work to do.
― Reply to this email directly, view it on GitHubhttps://github.com/apache/dubbo/pull/15457#issuecomment-2994870895, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKZLIJR533VHOZ5KJH73ONT3E56XPAVCNFSM6AAAAAB7HR4WV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJUHA3TAOBZGU. You are receiving this because you authored the thread.Message ID: @.***>
Is there a development plan in the community that supports DubboBootstrap restart?
need more contributors to contribute efforts