DiversIT Europe

Veelzijdig in IT

« @jkuipers Dank.Net je OSGi Spr…

@Kengkee Just use http, not ht… »

My first look at OSGi

After hearing lots about OSGi on Devoxx last week I just had to get into it. Last couple of days I have been reading and trying out OSGi. Some good information is available on the OSGi Alliance site. The ‘OSGi architecture’ and ‘Where to start’ give a good starting point for learning about OSGi.
But then … how to get started with it? These couple of links gave me a good starting point for gettings started with OSGi.

Also the free OSGi and Modular applications training from SpringSource by Joris Kuipers is pretty good.
As I was trying out OSGi, creating bundles and deploying them on Apache Felix or Equinox (in Eclipse) I found that doing the easy stuff is pretty simple, but it’s hard to find information about the advanced OSGi stuff. The OSGi API contains dozens of classes, but only a few ones like BundleActivator, BundleContext, ServiceReference, ServiceFactory, Filter are used in those simple examples.
If you go through the API you’ll also find about Bundle, BundleListener, BundleEvent, FrameworkListener, FrameworkEvent, ServiceListener and ServiceEvent with which you can do some pretty advanced stuff like being notified whenever a bundle gets installed, started or uninstalled. Via Bundle.getResources(..) you can even look into the bundle and find resources like Spring contexts or custom config files and uses those to do something. This is how Spring DM is able to detect new Spring bundles being deployed and is constructing a Spring context for you binding all services together.

But what about all those other classes in the OSGi API? How to get a HttpService or a LogService? The Equinox in Eclipse does not seems to have these. What to do with ComponentFactory, Consumer or ConfigurationListener? I have not been able to find out any info about these, apparently advanced, OSGi features.

OSGi also makes simple things we’re so used to using a lot more complex. For example: logging. I think it should still be possible to use log4j within your bundle, but then you must package the log4j jar in your bundle and thus increasing your bundle size every time with this library. The other option is to use a logging service, but this seems to be very hard looking at all the posts which have been written just about this subject like Logging in OSGi Enterprise and OSGi-Logging. If you google for ‘osgi logging’ you’ll find a lot of posts, proposals and howto’s, but I have yet to find a simple solution that works on all OSGi platforms.

OSGi definitely is a very cool technology and does need some more investigation. I’m eager to know more about the ins and outs of OSGi and get more into the core of it.

Tags:
November 26, 2009 - 11:00 AM
Leave a reply

Switch to our mobile site