Expand my Community achievements bar.

SOLVED

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

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

4 Replies

Avatar

Correct answer by
Level 9

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

Avatar

Community Advisor

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 @reference. 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-o...

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



Arun Patidar

Avatar

Level 2

I know this 

Service References: Declarative Services (DS) allow bundles to declare references to other services using @reference. 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 

Avatar

Employee Advisor

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.