开发者

How can you get ManagedService configuration immediately?

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 becaus开发者_如何学编程e

  1. on activation they call ManagedService#updated(null), and
  2. a very short while later, the Felix ConfigurationManager.UpdateThread calls ManagedService#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.)


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:

The updated(Dictionary) callback from the Configuration Admin service to the Managed Service must take place asynchronously. This requirement allows the Managed Service to finish its initialization in a synchronized method without interference from the Configuration Admin service call- back.

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-null update has been received before registering it under that interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜