Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using Annotations

To write an OSGi application is to first develop bundle dependencies using Import-Package or Export-Package headers. But bundles can also cooperate using services. Basically, using the OSGi Service Regsitry, a service providing bundle can publish a service (a Java object), while a client bundle can discover and bind to other services on which it depends. All these activities are dynamic and create a unique challenge when using services: when a service is required, it may not be available yet, so that the client service is left clumsy. On the other hand, even if the dependency service is registered and available, then it can be unregistered later, leaving the client service with a stale service reference. In this context, a first solution to handle service dependencies consists in using the OSGi API (BundleContext/ServiceTracker), but this programmatic API for registering and acquiring services is often challenging, and DependencyManager addresses theses issues.

Dependency Manager provides a compact and versatile java API, allowing to declaratively and programmatically register, acquire, and manage dynamic OSGi services. But since recently, support for annotations has been introduced in Dependency Manager, and you can also manage your service components, and their dynamic component dependencies using Java 5 annotations. In this chapter, we will detail the Dependency Manager Annotations which can be used to describe service components. We will also discuss the DM component lifecycle and how components can interract with the dynamic OSGi service model.

Table of Contents

  • Quick Tour helps you with the basic concepts using a SpellChecker sample code.
  • Reference Guide a full reference guide to lookup all annotation details.
  • Common Usages Covers some common usage scenarios using annotations
  • Compiling explains how to build annotated bundle using Maven, Bnd, or Ant.
  • Writing Components Explains how to write DM service components using annotations.
  • Using Dependencies Explains how to annotate dependencies for a given component.
  • Lifecycle Explains the DM component lifecycle and how components interact with the dynamic OSGI service model.
  • Composition Explains how a component may be implemented using multiple object instancesTesting shows how you can write junit tests using Pax Exams..