OSGi 声明式服务与 ManagedService 用于配置服务?
我最近偶然发现 OSGi 中的声明式服务可以将组件的配置设置为必需的,以便组件在激活时接收它,从而消除组件激活和配置之间的差距。我还意识到您可以通过修改的方法接收配置更新。
在我看来,此功能与通过实现 ManagedService 接口并将其发布为您提供的“服务”之一所提供的功能非常相似。
看来我可以完全忽略 ManagedService
&只需使用 DS 配置注入即可。
这些技术中的一种是否优于另一种,或者是否存在我没有看到的其他权衡?
I just recently stumbled upon the fact that Declarative Services in OSGi can set the configuration of a component to required so that the component receives it upon activation, removing the gap between component activation and configuration. I also realized with this that you can receive configuration updates via the modified
-method.
It seems to me like this functionality is quite similar to that provided by implementing the ManagedService
interface and publishing that as one of the "services" you provide.
It seems like I could completely ignore ManagedService
& just use the DS configuration injection.
Is one of these techniques preferred over the other or are there other trade-offs that I'm not seeing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以完全忽略
ManagedService
和ManagedServiceFactory
并仅使用声明式服务组件。是的,我会推荐这种方法。只需将其视为不同的抽象级别即可。 MS/MSF 是配置管理的低级 API,即使您没有运行 DS 捆绑包,它也可用。这样做的优点是您可以编写可配置的服务,而无需依赖 DS,这对于某些“系统级”组件来说可能是理想的。
然而,如果您愿意依赖 DS,例如“应用程序级”组件,那么使用 DS 与配置管理的内置集成将使您的生活变得更加轻松。
Yes, you can completely ignore
ManagedService
andManagedServiceFactory
and just use Declarative Services components. And yes I would recommend this approach.Just think of this as different levels of abstraction. MS/MSF is the low-level API for config admin, and it is available even when you don't have a DS bundle running. The advantage of this is you can write configurable services without having a dependency on DS, which may be desirable for certain "system level" components.
However, if you are happy to depend on DS, e.g. for "application level" components, then using DS's built-in integration with config admin will make your life a lot easier.
几个建筑的例子
声明式服务
工厂:
1)通过 配置管理
:
胡萝卜-osgi-scr-factory-cm 2
)通过组件工厂
:
胡萝卜-osgi-scr-factory-ds
查看用例测试;
couple of examples of building
declarative services
factories:
1) via config admin
:
carrot-osgi-scr-factory-cm
2) via component factory
:
carrot-osgi-scr-factory-ds
take a look on tests for use cases;