Wednesday, November 01, 2006

OSGi introduction

Some of my colleagues need to develop OSGi bundles and run them on Equinox. They are new to OSGi, so they asked me for some introductory reading. I thought I'd post it here for posterity and more general consumption.

I recommend starting with the technology overview on the OSGi web site, but skipping the sections on specific services on the first reading.

After reading this, you should have a feel for the three major layers in the OSGi framework.

The modularity layer enables you to package Java code with some metadata into a JAR known as a bundle, which is OSGi's module concept. Each bundle is loaded in its own class loader. Bundles share classes in a couple of ways. A bundle may import a package that another bundle exports or a bundle may require another bundle, which is similar to importing all the packages that the other 'required' bundle exports. Bundles may also contain native libraries and arbitrary kinds of resource files.

The life cycle layer allows you to dynamically install, uninstall, start, stop, and update bundles. This is essential when the OSGi framework needs to run for a long time but applications need to be managed, e.g. taken offline or have a bug fix applied, without restarting the framework, which would impact all the applications running in the framework.

The service layer enables bundles to provide services to other bundles. A service is a Java object that implements an agreed interface. Services are registered in a service registry so that users can locate the service they need, cast it to the agreed service interface, and then call the service.

If you would like to re-enforce these concepts or get a bit more detail, take a look at the architecture description.

After that, you could read about an example application, you could dip into the core specification, or you may prefer to try developing and running a simple bundle using one of the open source OSGi framework implementations. For example, the Equinox OSGi framework comes with a quick start guide.

Finally see this guide to writing a trivial bundle in 10 minutes with no special tools. Once you get beyond a "hello world" bundle, you'll want to refer to the javadoc on the OSGi web site.


Unknown said...

This is really well written. I have a roomate who works in Emerging Standards and after hearing him babel about OSGI, I figured I should know more about it. Reading this probably saved my a good 2-3 hours of reading in the early morning :) ... so Thanks.

Glyn said...

Glad it was useful. :-)

Zteve said...

This blog entry is still useful, but the links aren't all working now. Any chance you could update it?

I think it would form a good resource to answer some questions on Stack Overflow -- you I'd like to discuss this with you.


Glyn said...

Thanks Steve. I've overhauled the links. You're right about StackOverflow - let's discuss it.

one said...

It saved my lot of time ... thanks a lot :-)


OSGi (130) Virgo (59) Eclipse (10) Equinox (9) dm Server (8) Felix (4) WebSphere (3) Aries (2) GlassFish (2) JBoss (1) Newton (1) WebLogic (1)