- OSGi Annotations
Those of you who are comfortable in OSGi application development, you might be accustomed to using the Eclipse PDE (Plugin Development Environment) to develop OSGi Bundles. In addition to it, some of OSGi Developers prefer to use Maven Bundle Plugin. OSGi provides lots of benefits in regard to modular Software Development but it also incorporates some boiler plate tasks such as modifying manifest headers each and every time you add a package. If you want your package to be private, it needs to be added to the manifest.
Do we have a solution?
OSGi Bundle Annotations
This is a RFC proposal to incorporate several annotation which expedites OSGi Bundle Development.
I have previously talked about the benefits of using OSGi enRoute for rapid application development using OSGi. It incorporates the reference implementation of the aforementioned OSGi Bundle Annotations.
Let’s have a look on few snippets on how to use them.
This annotation is used to annotate a class which would be used as a Declarative Service Component. By default, it would expose this component as service implementations of the interfaces that it implements. Here, the service interfaces are Managed Service and REST.
@Reference is used to inject OSGi service dependencies dynamically. Finally no pain in creating declarative service component descriptor file to inject such dependencies.
This annotation is closely related to service components. You can annotate methods with this annotation to mark it as an activator method for the Service Component
This can be used to annotate methods to mark as a deactivator method in Service Component.
@ObjectClassDefinition and @AttributeDefinition
This annotation is used to annotate your custom interfaces which would contribute to OSGi Metatype Configuration.
After you create OSGi Metatype Configruation, it is necessary to listen to configuration updates. We can make use of this annotation to listen to the configuration changes.
This class implements ManagedService to listen to the changes of the LedConfiguration
This annotation is used to categorize the bundle by providing the comma-separated list of category names.
It says it all. You can use it to mention the list of contributors. The runtime bundle manifest will comprise Bundle-Contributors header.
Developers can make use of this to incorporate copyright specification information.
It is as same as the @BundleContributors which is used to mention the list of names of developers.
Used to generate Bundle-DocURL header comprising URL pointing to documentation.
It generates Bundle-License header which comprises the licensing information for the bundle distribution.
OSGi enRoute includes some license specific annotations which indicate that the annotated class depends on the specified license.
This indicates that Utils class depends on Eclipse Public License.
In addition to it, it provides huge array of licenses such as Apache Lincense, GPL, MIT, CPL, CDDL etc.
This annotation is used to annotate other annotations to define the requirement and capabilities of a bundle.
The previous code snippet has been taken from OSGi enRoute for better comprehension. The aforementioned annotation @RequireWebServerExtender is annotated with @RequireCapability.
Now, let’s look at how to use it.
This class MQTTLedApplication is annotated with RequireWebServerExtender which specifies its requirement at runtime.
It works the same way as @RequireCapability works, instead it provides a capability at runtime.
OSGi enRoute Specific
OSGi enRoute has taken the responsibility to take the hassles of OSGi Application Development off our shoulder. It provides all necessary abstractions to develop rapid OSGi applications. Amongst its several benefits, it provides huge array of annotations for Angular JS Application development, Scheduling, Authentication and Authorization, IoT Application Development etc.