Jira | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Issue Reported:
Application start up failing due to cyclic dependency :
┌─────┐
| notificationService defined in URL
[jar:file:/app/libs/cps-service-2.0.1-SNAPSHOT.jar!/org/onap/cps/notification/NotificationService.class]
↑ ↓
| cpsDataUpdatedEventFactory defined in URL
[jar:file:/app/libs/cps-service-2.0.1-SNAPSHOT.jar!/org/onap/cps/notification/CpsDataUpdatedEventFactory.class]
↑ ↓
| cpsDataServiceImpl (field private
org.onap.cps.notification.NotificationService
org.onap.cps.api.impl.CpsDataServiceImpl.notificationService)
└─────┘Why
What caused the cyclic dependency
...
CpsDataServiceImpl : Service component making calls to persistence layer.
...
:
...
NotificationService:
Spring by default performs the bean initialization at the startup of the application. Hence cyclic dependencies lead to issues because each components keep waiting for its dependencies to be initialized first.
Proposal 1:
...
To remove the cyclic dependency
Pros:
- Removes Cyclic Dependency
- Makes getDataNode and getAnchor method calls synchronous, thus addressing the issue related to data corruption in case of concurrent update.
Cons:
- Making getDataNode and getAnchor method calls synchronous could lead to increased latency of the APIs
Proposal 2 : Fixing the issue by Lazy Initialization
At present, cps-temporal always sends the entire data. When a patch update is made to the data, a query is made from the NotificationService - cpsDataUpdatedEventFactory - cpsDataServiceImpl.getAnchors(). And then the entire data is obtained from cps and then sent back to NotificationService for publishing to cps-temporal.
This has led to the cyclic dependency.
Instead of going back to cpsDataServiceImpl for making calls to persistence layer, make a direct call to persistence layer from NotificationService.
Proposal 2:
Lazy Intitialization of cpsDataServiceImpl in cpsDataUpdatedEventFactory component. The lazy initialization concept simply means initialize something when needed. So lazy initialization of bean means bean will be initialized at the time of its demand instead of start up. This will help in .
Lazy Intitialization of cpsDataServiceImpl in cpsDataUpdatedEventFactory component. This will ensure that CpsDataUpdatedEventFactory will not keep waiting for CpsDataServiceImpl to be initialized first thus resolving the cyclic dependency error at start up.