[ Monday, January 03, 2005 ]

OSGi framework to improve Java platform

I saw this thread of Java.net community forums about missing features to administrate libraries in Java.
OSGi helps with two shortcomings of the Java platform (not Java language):

  • Component Versioning
  • Published Interfaces

Component Versioning

There is already a notion of versioning in Jar specification. But I'm not aware of simple tools to take advantage of it (a.k.a "write you own ClassLoader").
With OSGi, you can state the version of the bundle you want to import. It also takes into account compatible versions. Since bundles have their own classloaders, you can have different bundles using different versions of the same library without conflict.

Published Interfaces

Another useful feature of OSGi bundles is the idea of published API (see Martin Fowler's article "Public versus Published Interfaces" for a definition of published interface).
You have to state in the manifest of your bundle the packages of the other bundles you're depending on. Your bundle can then only load classes from these packages and not from any other packages.
Eclipse plug-ins makes the distinction by putting their published interfaces in org.eclipse.foo package and the public API in org.eclipse.foo.internal.
It is not recommended to make your plug-in dependant of internal packages but you still have the freedom to do so at your own risk if you really need it (e.g. to circumvent a bug or to extend the plug-in if it does not expose a feature as an extension point).

I really like the idea to make an explicit distinction between the public interfaces of a component and the published ones.
These days, thanks to autocompletion in the IDEs you can inadvertantly import and use a part of a component which is not meant to be used by its clients.
With OSGi, you can't use a package if it's not explicitely stated in the import-package header of its manifest file. Of course, you can still import internal packages but it has to be done explicitely in the manifest file. The advantage of OSGi is that with a quick look at the manifest file, you can see the boundaries of your bundle:

  • what it depends on
  • what it provides (at package level)
While with "standard" jars, it is more difficult to see all its dependencies in one look.

Since Eclipse 3.0, OSGi framework has been under my radar but I hadn't had the opportunity to develop an application based on it. I'm not aware of Open Source applications based on top of OSGi (other than Eclipse) but I think there is a lot of potential to develop an application on top of it. Not only for the two features I described but for a lot of other reasons (hot deployment, remote administration).
Another cool example is that application help could be written in HTML and available as a Bundle taking advantage of OSGi embedded web container (e.g. like Eclipse Help). That way, you have simple to write documentation without the need to keep all the versions of the documentation of the available versions of your application on your web site.

7 Comments:

Eric said...

Keep us updated on your OSGi investigations. This looks like good stuff!

1/04/2005 04:56:20 PM  
RefuX said...

Yeah keep us posted!
I'm working on a Java and .Net project, I want them both to use OSGi functionality.
I found there is also a .NET OSGi framework called: Knopflerfish (http://www.knopflerfish.org/)

1/04/2005 08:34:10 PM  
juss said...

See my blog "Fun with OSGi" over at http://osgifun.blogspot.com

1/14/2005 11:46:38 AM  
JavierMF said...

I do not how Knopflerfish relates to .NET, but it runs fine on Linux. I'm currently using it in Ubuntu and runs smoothly.

OSGi really rules, but all the code overload because of the search and tracking of services is a serious drawback. You know: the more functionality, the more complexity.

1/14/2005 01:01:06 PM  
wistrand said...

As a comment to refux, Knopflerfish is _not_ a .NET framework, it's simply an open source OSGi framework. Which is pure java.

There is however an onging .NET "OSGi lookalike/similar API" project called Physalis, mentioned on the KF web site. But the projects are not related.

3/05/2005 06:54:32 PM  
Gyowanny & Viviana said...

Is there any possible to uses the OSGi and the NetBeans platform together to build an application? I want to use the OSGi (Knopflerfish) to manages the engine and the netbeans to manages the GUI.

Thanks

12/07/2005 07:03:58 PM  
Peter said...

The overhead of OSGi is quite minimal. The OSCAR open source framework was 250K, the Equinox framework (Eclipse) is around 800K but has been written to handle 5000+ bundles. So the amount of overhead is really not that much. You get an amazing amount of functionality for this.

3/16/2006 07:11:27 PM  

Post a Comment

<< Home