If 2 bundles are inter depended on each other , how these bundles dependencies will be resolved and started | Community
Skip to main content
ashwinka
Level 2
October 24, 2024
Solved

If 2 bundles are inter depended on each other , how these bundles dependencies will be resolved and started

  • October 24, 2024
  • 3 replies
  • 960 views

Suppose BundleA is having depenedancy with BundleB and also BundleB is having dependancy on BundleA. So how this dependencies will be resolved . And when and how will this bundles be started

 

FYI: Just had a curiosity to know.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by daniel-strmecki

Hi @ashwinka,

TBH I have no idea how this is/would work, but having cyclic dependencies is never a good idea. In that case, I would strongly suggest refactoring the code.

 

Good luck,

Daniel

3 replies

daniel-strmecki
Community Advisor and Adobe Champion
daniel-strmeckiCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
October 24, 2024

Hi @ashwinka,

TBH I have no idea how this is/would work, but having cyclic dependencies is never a good idea. In that case, I would strongly suggest refactoring the code.

 

Good luck,

Daniel

arunpatidar
Community Advisor
Community Advisor
October 24, 2024

In OSGi, when two bundles have circular dependencies (e.g., BundleA depends on BundleB, and BundleB depends on BundleA), the resolution depends on how the OSGi Service Component Runtime (SCR) manages service registration and injection. OSGi uses a dynamic service model, meaning that services can be published and consumed dynamically, helping to resolve circular dependencies to some extent.

Here’s how the circular dependency is handled:

  1. Lazy Loading: OSGi services can be declared with lazy activation (Bundle-ActivationPolicy: lazy). This means a bundle is only activated when one of its services is actually used. This can help in managing circular dependencies because a service may not be activated until the dependent service is available.

  2. Service References: Declarative Services (DS) allow bundles to declare references to other services using @3214626. The SCR manages these references and can dynamically bind services once they become available. If both services depend on each other, OSGi resolves this lazily, activating the services when needed.



Please check

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/cyclic-references-in-two-osgi-services/m-p/392542

https://issues.apache.org/jira/browse/FELIX-6724 

Arun Patidar
Level 2
October 24, 2024

I know this 

Service References: Declarative Services (DS) allow bundles to declare references to other services using @3214626. The SCR manages these references and can dynamically bind services once they become available. If both services depend on each other, OSGi resolves this lazily, activating the services when needed.

will work but good luck writing test cases for it, I had similar issue 

joerghoh
Adobe Employee
Adobe Employee
October 24, 2024

I don't think that this will work at all, in the end the bundle dependencies need to form a directed tree, and not a graph with cycles.