spring dm, equinox, eclipse RCP and starting org.springframework.osgi.extender

 

I am trying to use the spring dynamic modules. It’s been a rough road because I did not fully understand what spring dm was trying to do. Essentially, it is creating an application context on the behalf of properly configured osgi bundles and then providing that application context as a service published by the respective bundle.

Because proper osgi bundles cannot share resources easily across bundles, the basic model of your application once you use spring dm is to further straight-jacket sharing. This decreases coupling which is good. The proper way using spring dm to share “service” (POJOs with a specific purpose) across bundles is to publish them as osgi services and hence collaborating bundles are really about wiring up services across bundles.

Within a bundle you can create hierarchical contexts by first accessing the service using ServiceTracker then using that “service” (which is really the application context) as the parent context. Hence, you use osgi preferred methods such as ServiceTracker to access the application context on a regular basis. ServiceTracker also tracks whether the service has been removed so you can adjust the running of your application accordingly. Generally, though, within a bundle, the application context will stay with that bundle through the bundle lifetime.

One issue came up while playing with spring dm, how do you start the extender bundle? The extender bundle by default will lazy start in the equinox environment. You could set the start level and autostart properties of the bundle to level 3 (for example) and autostart to true to star the bundle.  It is the extender bundle which actually creates the application contexts on behalf of a bundle (it is a listener to the bundle machinery inside of osgi). However, changing the start level of a bundle is more configuration work. For example, you can program a config.ini to have the start level set correctly but now you have to manually manage the config.ini for your application going forward.  Another way is to use code to ensure that the extender bundle has started. The idea comes from the spring dm forum: http://forum.springsource.org/showthread.php?t=54981&highlight=extender&page=2.

I recommend that in your application (IApplication) class, you put the following code in your start method. You could put this in the Activator method as well but the last point that you can activate the extender is right at the start of your application and right before any processing occurs that requires your application to access the application context in your bundles, hence, choose the last point at which it is possible to start the extender:

   1: public class YourApplication implements IApplication {
   2:  
   3: ... start(...) ... {
   4:     ...
   5:     Bundle springDM = Platform.getBundle("org.springframework.osgi.extender");
   6:     springDM.start();
   7:     ...
   8: }
   9:     

Comments

Popular posts from this blog

quick note on scala.js, react hooks, monix, auth

zio environment and modules pattern: zio, scala.js, react, query management

user experience, scala.js, cats-effect, IO