本文介绍了OSGi声明式服务vs. ManagedService用于配置服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近偶然发现,OSGi中的声明式服务可以将组件的配置设置为必需,以便组件在激活时接收它,消除组件激活和配置之间的差距。我也意识到这一点,你可以通过修改方法接收配置更新。

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.

此功能与通过实现 ManagedService 界面并作为您提供的服务之一提供的功能非常相似。

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.

看起来我完全可以忽略 ManagedService &只需使用DS配置注入。

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?

推荐答案

是的,您可以完全忽略 ManagedService ManagedServiceFactory 并且只使用Declarative Services组件。是的,我会推荐这种方法。

Yes, you can completely ignore ManagedService and ManagedServiceFactory and just use Declarative Services components. And yes I would recommend this approach.

只是想到这是不同的抽象层次。 MS / MSF是config admin的低级API,即使您没有运行DS软件包也可以使用它。这样做的优点是,您可以编写可配置的服务,而不必依赖于DS,这对某些系统级组件可能是理想的。

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.

取决于DS,例如对于应用程序级组件,然后使用DS的内置集成与config admin将使你的生活更容易。

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.

这篇关于OSGi声明式服务vs. ManagedService用于配置服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:28