Question

We have two bundles, both embed a different version of the same 3rd party library and we have to use them with different configurations. Unfortunately the library is only configurable via system properties.

So, we try to do the following the Activator classes:

  1. setting the required system properties,
  2. initializing the library,
  3. unsetting the former system properties.

It won't work if an OSGi framework starts the two bundles concurrently. Is it allowed for an OSGi framework implementation? Is this solution safe? Is there any other way to set the same system property to different values for different bundles?

(If it's possible we would like to avoid setting different start levels for these bundles.)

Was it helpful?

Solution

An OSGi framework implementation is allowed to start bundles, within a given start level, concurrently. So you can put the bundle's in different start levels to ensure one is started before the other.

OTHER TIPS

In Felix and Equinox, the bundle install/resolve/start/stop/uninstall actions all happen on a single thread. I can't recall for certain if the activators run on that same thread, but I think they do.

How about creating an OSGi service that wraps the library initialization. So you only have to do it once. Alternatively the service could synchronize the initializations and so make sure it does not happen concurrently.

Is it a strong requirement to have them in separate bundles? What do you do with the libraries, do you export them as java packages or do you create services out of them? If you can put both libraries in one and the same bundle you have full control which is initialized first and which one second.

Btw if you export them in the bundle manifest with Export-Package have in mind that exported packages can be used by other bundles even when the bundle is in the RESOLVED state, i.e. installed but not yet started. So it could happen that somebody calls methods of the lib even before your Bundle Activator has been created and has taken care of the initialization....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top