Montag, 5. März 2012

Start buggy lazy Bundles

Yesterday I push to github a simple bundle, which I use in bnd and bndtools to activate buggy lazy bundles.

What is a buggy lazy Bundle?
Sometimes I have bundles with a Bundle-ActivationPolicy header, which is set to lazy. But no other bundle in the application loads classes from this bundle or use a service e.g. via DS from this bundle. In some cases the lazy bundle didn’t export anything.

When you like to use such lazy bundles, then this bundle must be start by hand. Examples are the Eclipse  ECF bundles. To use the ECF bundles (see also ticket ID-373475) some of the bundles must be start by hand because of the Bundle-ActivationPolicy header lazy. I think these are buggy bundles and the Bundle-ActivationPolicy header should be removed from the manifests.

When you use lazy bundles then this bundles should automatically started by the OSGi framework, when some other bundle in the application need the functionally of the lazy bundle. Think about before you use the Bundle-ActivationPolicy lazy. Only use lazy bundles when the OSGi framework could detect that some other bundle would like to use functionally which the lazy bundle provides.

Examples use lazy bundles when the bundle exports packages with classes and only when some other bundle loads a class from these exported packages the bundle should be in state active. Or when the bundle provides an OSGi service via DS and the bundle should only be in state active when some other bundle would like to use this service. So be careful with using the Bundle-ActivationPolicy header.

More about lazy activation bundle see the OSGi Alliance web site here.

Handling buggy lazy Bundles in Bnd
When you like to use a buggy lazy bundle with bnd or bndtools the bundle must be started by hand. For this I create a simple bundle, which I call “Start lazy Bundles”. The bundle implements an extender pattern which watch for starting bundles. When the starting bundle has a Bundle-ActivationPolicy lazy and the bundle symbolic name is set in a system property the “Start lazy Bundles” bundle try’s to start the bundle.

More details see the Github project: