I’m going to be spending some time over the next couple of weeks learning about OSGi – there is an application at work that we want to try and make more modular. In particular, we’d like to be able to share the back tier with more front end clients. The more conventional modularisation techniques, such as EJBs, have been tried and didn’t work fairly well. Simply creating more deployments is prohibitive, due to hardward And before someone asks “why not just stick a web service on it and share that way” – some of the front end clients will be those web services. To cut a long story short, one of the options we want to check out is OSGi.
The only problem is that there isn’t much in the way written up on the web about writing OSGi components – at least not without invoking magic tools (e.g. Maven plugins) that don’t work on any version of any tool developed six months later. Which is odd, because OSGi, as a spec, doesn’t look that hard to write too. So, I thought I’d write up a series describing the initial investigative spikes, starting as close to the metal as possible and working up.
The application I’m going to build for my spike is a very simple concept: two servlets, talking to a shared service. The shared service keeps track of a counter; one servlet gets the status of the count, and the other increments it. We’ll start with the entire app in one single normal WAR, and evolve it in progressed stages into three distinct OSGi bundles – with the Counter Bundle being shared.
For the spike, I’ll be working with Glassfish V3. The examples use Maven, but I’m deliberately going to avoid the various OSGi plugins; there’s nothing special about OSGi bundles – they’re just normal JAR files with special entries in the MANIFEST.MF file. If you want to try the examples yourself (I will be posting them), but don’t want to use Maven, it should be simple enough to use Ant instead.
My main reference will be the OSGi specs, but where I get reference from other sources, I’ll be sure to cite them.
The first post in the series (which should be up tomorrow) will cover what it takes to get an OSGi-enabled web application up, as a stepping stone to the end goal. As a starter, though, feel free to check out the initial starting point.
3 thoughts on “OSGi Diaries – A short series”
If you are using Ant you may be interested in the Sigil development tooling project available as a sub-project of Apache Felix (http://felix.apache.org/site/sigil-key-features.html). This provides unified IDE (Eclipse) and server side build (Ant/Ivy) tooling.
These days, I’m using Maven, at least at work and I don’t do enough personal coding to bother looking elsewhere. Sigil sounds interesting – using OSGi runtime data about dependencies would probably solve the worst of the dependency nightmares you get with Maven (which are mostly caused by the over-eager transitive dependencies).
For the purposes of these examples, I intend to keep very tool free – anyone should be able to follow even if they use a tool besides Maven. No plugin magic for now. Eventually, I’ll expand outwards to tool support – I will see if I can fit in an Ant example with Sigil then.