The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

zaxxon (1) [Avatar] Offline
#1
Hello,

I would like to see in this book some descriptions of and solutions to the following issues I have experienced with using OSGi so far:

1. Instantiating an object via Spring.
Here a bean is declared in a spring XML file, and the type of the bean is implemented in a class that is in a bundle. I have been doing this in the context of eclipse RCP applications, and to make it work, I had to:
a) Take the spring JAR file and create a bundle out of it
b) In the new spring bundle I had to edit the manifest file and declare the bundle as "registered"
c) In the bundle that contains the implementation class, I have to register the spring module as a buddy (with the Eclipse-RegisterBuddy directive).

This all seems cumbersome. Is this something eclipse or OSGi specific? Does OSGi offer a better/simpler way?

2. Suppose I have a trading application GUI that allows the end user to create strategies. I would like this framework to be extensible, so when a strategy is created, the user can enter the name/path to a module that implements the strategy. So the end user might write some class that implements a Strategy interface, create a bundle out of it, and this bundle must be available to the application. All this without having to stop/restart the application.

How can such mechanism be implemented with OSGi?

Best regards,
Levente
richard.hall (87) [Avatar] Offline
#2
Re: OSGi with Spring + dinamically picking up new modules
I am not sure what to say about (1), but for (2) this is pretty much what we are doing with the paint example in chapters 3 and 4. In ch3 we use the bundle lifecycle layer to provide extensibility (i.e., the extender pattern) and in ch4 we use services to provide extensibility.

If you wanted the user to be able to install bundles dynamically, then you just need to create a GUI to allow them to specify where the bundle is located or you could create a directory you monitor and simply have them copy it in there. Internally, once you have a new bundle from the user, you call BundleContext.installBundle() (and probably Bundle.start()) to make it available at run time.