Playing with Apache Felix

I'm trying to learn more about OSGI and become proefficient with it quickly. Neil Bartlett is writing a book about OSGI. It's available for free but it's not completed yet.

I looked at IPOJO from Apache Felix and managed to create a simple application with it. I think I'll start with plain OSGI programming first. Once I get it right, it will be easier to know what IPOJO or other tools can do for me and when it's better not to use them.

For example to build a simple GUI with plugins support using OSGI, the only thing I need to do if I understand, is :

  • Create few services, one can think about them as extension points
  • Create BundleActivators for each plugin
  • Register couple of services and use some ServiceTrackers
  • Layout and display your GUI application when all the bundles are activated
  • Launch background services if their startup needed to be delayed
I downloaded the SIP communicator's code. It's an audio/video Internet phone and instant messenger using Apache Felix. The graphical interface is nice and the code is "clean enough", quite good IMHO. I found a little bit strange/unconventional the way they package bundles. It seems that they build bundles from some packages/classes using an Ant build script, in a single project. I believe in an IDE it would look like a project with multiple source folders and a jar target for each source folder.

In XPontus XML Editor I have about 18 plugins which could become bundles. I started cleaning up some code. One shall never hurry too much to release, patch code here and there, leave too many unused packages, because the pain comes soon enough when you need to do some refractorings... .

In XPontus, I have 1 master project and about 30 sub-projects. Well it can be difficult to manage too, but I don't have to create many ant targets/tasks to build specific jars.

Project structure overview
  • xpontus_core
  • etc.
  • indentation_plugin(dummy maven pom project)
-> xml_indentation_plugin(sub-project, maven jar project)
-> html_indentation_plugin (sub-project, maven jar project)

The annoyance with a plugin architecture is about the deployment, but mostly the packaging. Most of the time the plugin framework or OSGI framework you'll find has a console or a main class from where you can launch the bundles/plugins. Usually in a big application, you want total control and a customized behaviour which means a custom launcher to embed the plugin framework or the OSGI framework.

Let's say I have a bundle called bundle0. I created it in Eclipse, I have few jars as dependencies, etc. How do you auto-package all that with minimal effort(zip file with the bundle0.jar, a lib directory holding the dependencies)?

In XPontus XML Editor the plugins have an "Eclipse like" folder structure
- com.mycompany.plugin
* plugin.xml
* lib(folder containing the jars)

Every time I want to deploy a plugin:
  • I create a plugin folder with a unique id
  • I add the plugin descriptor
  • Create a lib folder with all the jars needed by the plugin
  • I zip the folder and it could be ready to be deployed.

Bookmark the permalink. RSS feed for this post.

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.