Chapter 2. An OSGi framework primer

 

This chapter covers

  • Creating and sharing OSGi bundles
  • Importing and exporting bundle packages
  • Running bundles in an OSGi framework
  • Defining and retrieving OSGi services
  • Understanding the OSGi service registry

In this chapter you’ll expand your knowledge of the OSGi framework. I’ll describe two of the most important concepts related to OSGi: bundles and services. Bundles and services are the cornerstone of OSGi, and we’ll keep revisiting these two concepts throughout this book.

We’ll also cover the OSGi service registry and several less common, albeit still essential, APIs of the framework, such as the event listener interfaces.

As tradition dictates, to learn the basics, we’ll use an OSGi-powered hello world application. This will allow us to demonstrate the OSGi concepts in the scope of a single simplistic application. It’ll also allow us to compare the OSGi technology to other programming environments that, without doubt, are part of your background. Let’s start by creating a simple OSGi module.

2.1. Modules and information hiding

The unit of modularization in OSGi is called a bundle. Bundles allow us to enforce the principles of information hiding. As was brilliantly stated by D. Parnas as early as 1972, information hiding helps us achieve the following benefits:

  • Changeability
  • Comprehensibility
  • Independent development

2.2. Running and testing OSGi

2.3. Coping with changes to a module

2.4. Services and loose coupling

2.5. The OSGi layered architecture

2.6. Summary