当为 osgi 使用声明性服务时,我可以在同一组件中提供和引用服务吗?

发布于 2024-10-08 09:59:53 字数 597 浏览 0 评论 0原文

<实现类=“test.sensor.version1.serviceImpl.SensorServiceImpl”/> <服务> <提供接口=“test.sensor.version1.serviceInterface.SensorServiceInterface”/> <参考bind=“setOntologyService”cardinality=“0..1”接口=“test.ontology.version1.serviceinterface.OntologyServiceInterface”名称=“OntologyServiceInterface”策略=“dynamic”unbind=“unsetOntologyService”/>

如上所示,在同一个组件中提供和引用服务可以吗? 例如,有两个bundle A和B,A提供服务供B使用,B也提供服务供A使用。遇到这种情况我该怎么办?

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="sensor_test">
<implementation class="test.sensor.version1.serviceImpl.SensorServiceImpl"/>
<service>
<provide interface="test.sensor.version1.serviceInterface.SensorServiceInterface"/>
</service>
<reference bind="setOntologyService" cardinality="0..1" interface="test.ontology.version1.serviceinterface.OntologyServiceInterface" name="OntologyServiceInterface" policy="dynamic" unbind="unsetOntologyService"/>
</scr:component>

For what is showed above, is that OK to provide and reference services in the same component?
For example, there are two bundles A and B. A provides a service for B to use, and B also provides a service for A to use. What should I do with this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2024-10-15 09:59:53

这看起来完全没问题,因为服务引用既是可选的又是动态的。

如果您定义了一个循环依赖关系,其中引用都是强制的,那么 DS 将报告错误。必须有一种方法首先创建一个组件,并且通过强制引用,在创建另一个组件之前,两个组件都无法创建(但是,第三个捆绑包“C”可以注册满足其中一个组件的服务)。

通过可选/动态引用,DS 可以构造一个未绑定引用的组件,然后构造另一个组件并将其注入回第一个组件。

This appears to be perfectly fine because the service reference is both optional and dynamic.

If you define a circular dependency where the references are both mandatory, then DS will report an error. There has to be a way to create one component first, and with mandatory references neither component can be created until the other is created (however, a third bundle "C" could register a service that satisfies one of the components).

With an optional/dynamic reference, DS can construct one component with the reference unbound, then construct the other component and inject it back into the first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文