Chapter 2. Mastering modularity

 

This chapter covers

  • Understanding modularity and why it’s desirable
  • Using metadata to describe OSGi bundles (aka modules)
  • Explaining how bundle metadata is used to manage code visibility
  • Illustrating how bundles are used to create an application

In the previous chapter, we took a whistle-stop tour of the OSGi landscape. We made a number of observations about how standard Java is broken with respect to modularity and gave you examples where OSGi can help. We also introduced you to some OSGi concepts, including the core layers of the OSGi framework: module, life-cycle, and service.

In this chapter, we’ll deal specifically with the module layer, because its features are the initial attraction for most Java developers to OSGi. The module layer is the foundation on which everything else rests in the OSGi world. We’ll provide you with a full understanding of what OSGi modularity is, why modularity is important in a general sense, and how it can help you in designing, building, and maintaining Java applications in the future.

The goal of this chapter is to get you thinking in terms of modules rather than JAR files. We’ll teach you about OSGi module metadata, and you’ll learn how to describe your application’s modularity characteristics with it. To illustrate these concepts, we’ll continue the simple paint program example that we introduced in chapter 1; you’ll convert it from a monolithic application into a modular one. Let’s get started with modularity.

2.1. What is modularity?

2.2. Why modularize?

2.3. Modularizing a simple paint program

2.4. Introducing bundles

2.5. Defining bundles with metadata

2.6. Finalizing the paint program design

2.7. OSGi dependency resolution

2.8. Reviewing the benefits of the modular paint program

2.9. Summary

sitemap