Sonntag, 22. Februar 2015

Bndtools and OSGi 4.3 Capabilities Support

Since the version 4.3 of the OSGi specification there is a general model to define any kind of dependencies, the required and provided capability model. An OSGi bundle now can define a provide capability, to define that the bundle provide some feature, e.g. the bundle provide an OSGi service, extender or a whiteboard. To define such a capability a new bundle header in the manifest was defined, the Provide-Capability header. If a bundle depends on a capability, the bundle can define, via the Require-Capability header, the dependency.  Here an bndtools example for the configuration for a provider and consumer bundle, the provider bundle provides an whiteboard:
That’s a lot of code in the configuration, for this reason bnd/bndtools provides some nice annotation @ProvideCapability and @RequireCapability to define a capability. Now we can define the dependency in the Java Code via an annotation here an example for the consumer:
If you like to use the @RequireCapability in many bundles and you like not to repeat your self, in bndtools you can make your own annotation for that case. Here a example how such a own annotation can be defined:
Why should I use the capability model? In bndtools you can use the capabilities to resolve a list of bundles, which are needed at runtime. For example to run an JAX-RS OSGi application, the following few lines of a bnd run configuration is required: Bndtools can now automatically resolve the list of run bundles to: The latest bndtools version, which can be installed from the jenkins update site, provides a nice feature (its hot and not stable at moment) to add capability information to existing’s bundles in a file repository. Here my bndtools repository setup to add some capabilities to the jaxrs bundle and to the felix http jetty bundle. I really like the bnd annotation to define capabilities. I hope the augments feature, to add capabilities to existing bundles, for the file repository will be soon stable and released. The resolver and the capabilities features in bndtools I think provides new ways for OSGi based frameworks to handle run configurations.

More details about the bnd/bndtools Manifest Annotations read the bnd documentation:
http://bnd.bndtools.org/chapters/230-manifest-annotations.html

Keine Kommentare:

Kommentar veröffentlichen