如何立即获取 ManagedService 配置?
我正在使用 Felix Configuration Admin 库来读取和应用OSGi 服务的配置文件。我配置的许多服务都是第三方的(例如org.ops4j.pax.web.pax-web-jetty和org.ops4j.pax.url.mvn >) 并使用简单的 BundleActivator
而不是声明式服务。我发现这些服务都初始化两次,因为
- 在激活时它们会调用
ManagedService#updated(null)
, - 不久之后,Felix
ConfigurationManager .UpdateThread
异步调用ManagedService#update(non-null)
。
我讨厌应用配置时出现这种延迟。由于固有的竞争条件,它会导致不稳定的故障。是否有替代的 CM 实现可以同步应用配置以避免此问题?或者我可以让Felix同步吗? (从源代码和 托管服务 javadoc。)
I'm using the Felix Configuration Admin library to read and apply configuration files for OSGi services. Many of the services I'm configuring are third-party (e.g. org.ops4j.pax.web.pax-web-jetty and org.ops4j.pax.url.mvn) and use a simple BundleActivator
rather than Declarative Services. I've found that those services are each initialized twice because
- on activation they call
ManagedService#updated(null)
, and - a very short while later, the Felix
ConfigurationManager.UpdateThread
callsManagedService#update(non-null)
asynchronously.
I hate this delay for getting my configuration applied. It causes erratic failures due to the inherent race condition. Is there an alternative CM implementation that can apply configurations synchronously to avoid this problem? Or can I make Felix be synchronous? (It looks like no, from inspection of the source code and the ManagedService javadoc.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,从另一个线程回调
update()
是配置管理规范的要求。请参阅 R4 纲要规范第 104.5.3 节:不幸的是,这意味着您需要对 ManagedService 进行编码,以免出现不稳定的故障或固有的竞争条件。例如,如果在
ManagedService
之外的另一个接口下注册为服务,请等到收到非空update
后,再在该接口下注册。Actually the callback to
update()
from another thread is a requirement of the Config Admin specification. See section 104.5.3 of the R4 Compendium Spec:Unfortunately this means you need to code your ManagedService to not have erratic failures or inherent race conditions. For example, if registering as a service under another interface besides
ManagedService
, wait until the non-nullupdate
has been received before registering it under that interface.