开发者

What is the standard behaviour in OSGI for the container to pick a package that is exported by multiple bundles?

开发者 https://www.devze.com 2023-04-01 02:21 出处:网络
I was just wondering how does the container select which package to load a class if the same package is exported multiple times by different bundles.

I was just wondering how does the container select which package to load a class if the same package is exported multiple times by different bundles.

Given the following what is true. Note the list also contains the actual order the bundles were deployed.

If a 4th bundle is added and it needs 'package.x.SomeClass' 1-2 from where will it be selected?

  • Does it randomly pick from either A or B?
  • Does it fail to deploy B because of the clash?
  • Does it pick A because it was first?

Do all containers do the same thing or is the behaviour different between the available popular packages?


The framework will pick either A or B. It does not do so "randomly", but the heuristics are complicated and it is better not to attempt to predict what will happen. Also the behaviour in this case is not specified and is subject to differences between OSGi framework implementations.


OSGi is a component framework, the whole idea is that these kind of issues are useless to discuss since they can vary depending on the framework and set of installed bundles. ANY unspecified assumption you make is likely to be violated and crash your code. The beauty of OSGi is that it allows YOU to specify YOUR constraints. OSGi frameworks will never violate your constraints, that is your guarantee. How it finds a solution in a particular case should be utterly irrelevant since any implicit assumption is likely to cause bugs in other situations.


In Felix, the container starts at version 0.0.0 of an package and then increments upward. It then will wire to the first version of the bundle it hits. So, if you have two bundles, version 1.1.1 and version 1.2.0, and you attempt to wire to that package but don't specify a version number, Felix should always choose version 1.1.1.

0

精彩评论

暂无评论...
验证码 换一张
取 消