OSGi 声明式服务与 ManagedService 用于配置服务?

发布于 2024-09-29 09:17:02 字数 271 浏览 0 评论 0原文

我最近偶然发现 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 技术交流群。

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

发布评论

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

评论(2

黒涩兲箜 2024-10-06 09:17:02

是的,您可以完全忽略 ManagedServiceManagedServiceFactory 并仅使用声明式服务组件。是的,我会推荐这种方法。

只需将其视为不同的抽象级别即可。 MS/MSF 是配置管理的低级 API,即使您没有运行 DS 捆绑包,它也可用。这样做的优点是您可以编写可配置的服务,而无需依赖 DS,这对于某些“系统级”组件来说可能是理想的。

然而,如果您愿意依赖 DS,例如“应用程序级”组件,那么使用 DS 与配置管理的内置集成将使您的生活变得更加轻松。

Yes, you can completely ignore ManagedService and ManagedServiceFactory 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.

倾其所爱 2024-10-06 09:17:02

几个建筑的例子
声明式服务
工厂:

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;

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