Tutorial 2: Service Properties and Filters

The goal of this tutorial is to teach the use of service properties for advertising particular characteristics of an exported service, and the use of service filters to select the particular characteristics of an imported service.

Service properties are a useful way for a bundle to distinguish the services it registers from services of the same type that are registered by other bundles. Also, by registering service properties a service implementation is able to provided additional information without requiring the service interface to be changed to support a query API.

For a bundle that wishes to import a service, being able to select the particular registered service based on an LDAP filter is simpler than having to acquire every service of a particular type and query them via an API. An LDAP filter can be arbitrarily complicated and SAT ensures that it is applied whenever they change or when the registered services are changed or modify their registered service properties.

After completing this tutorial you will have an understanding of how to register exported services with properties, and how to acquire imported services using an LDAP filter.

The Prerequisites

Before you start this tutorial you should have:

Tutorial 2

The Vendor Application, Revisited

The diagram on the right shows the topology of the tutorial application.

The Steps

This tutorial consists of the following steps:

  1. Updating the Vendor Service Bundle to Include a Spiciness Constant: In this step the Vendor Service bundle is updated to include a spiciness constant that will be used by bundles that export a VendorService with properties, as well as by bundles that import a VendorService using an LDAP filter.
  2. Updating the Hotdog Vendor Bundle to Export a Service with Registered Properties: In this step the Hotdog Vendor bundle is updated to export an implementation of the VendorService with a service property that describes its spiciness.
  3. Updating the Popcorn Vendor Bundle to Export a Services with Registered Properties: In this step the Popcorn Vendor bundle is updated to export an implementation of the VendorService with a service property that describes its spiciness.
  4. Updating the Customer Bundle to Import a Vendor Service using a Filter: In this step the Customer bundle is updated to acquire a VendorService using an LDAP filter that specifies a spiciness property.
  5. Launching the Vendor Application: In this step the Equinox OSGi Framework will be launched with our application bundles installed and started.
  6. Testing the Vendor Application: In this step the application will be tested using the OSGi console commands.

Source Projects

The source projects for this tutorial are available as a zip file that may be extracted into the file system and imported into your Eclipse workspace.