Chapter 4. Studying services
This chapter covers
- Understanding what services are and why they’re useful
- Publishing and using services
- Dealing with service dynamism
- Modifying an application to use services
- Relating services to the module and lifecycle layers
So far, you’ve seen two layers of the OSGi framework. The module layer helps you separate an application into well-defined, reusable bundles, and the lifecycle layer builds on the module layer to help you manage and evolve bundles over time. Now we’ll make things even more dynamic with the third and final layer of OSGi: services.
We’ll start this chapter with a general discussion about services to make sure we’re all thinking about the same thing. We’ll then look at when you should (and shouldn’t) use services and walk through an example to demonstrate the OSGi service model. At this point, you should understand the basics, so we’ll take a closer look at how best to handle the dynamics of OSGi services, including common pitfalls and how to avoid them.
With these techniques in mind, you’ll update the ongoing paint program to use services and see how the service layer relates to the module and lifecycle layers. We’ll conclude with a review of standard OSGi framework services and tell you more about the compendium. As you can see, we have many useful and interesting topics to cover, so let’s get started and talk about services.