OSGi教程:Class Space Consistency

此教程基于OSGi Core Release 7

 

OSGi类空间的一致性

 

详细内容上面英文教程有详细解答

下面主要是一些个人见解,若有不当之处,欢迎指出:

"Class space consistency can only be ensured if a bundle has only one exporter for each package."

也就是说要想保证类空间的一致性,就要保证一个bundle的每个import的package只能有一个来源。

 

比如像下图这个就会导致冲突:

                                                                            图1

 

如何解决这个问题呢?在org.tripplanner中使用uses指令

“If a bundle imports a package from an exporter then the export definition of that package can imply constraints on a number of other packages through the “uses” directive” – OSGi Specification R4.

 Export-Package: org.tripplanner;version=”1.0”;uses:org.transportation

现在关系就可以变成如下图所示了:

                                                                     图2

 

Note:

大家可能会问,为什么在图1中org.travel.agency 已经明确声明依赖org.transportation version = 1.0 ,后来却依赖了2.0呢?

因为在OSGi中,声明明确依赖单个版本意味着依赖这个package latest available version,这个被声明的版本代表着要被满足的最低版本。

 

文章参考自: 

Understanding OSGi uses directive

相关问题:

Solving OSGi "Uses" Constraint Violations

 

posted @ 2018-02-24 17:25  Hibou  阅读(159)  评论(0编辑  收藏  举报