About this Book

The OSGi specifications are well written and elaborate, so if you need to know details about OSGi technology, the specifications are the place to look. If you do, you’ll discover that they were written for someone who is going to implement the specifications, not use them. This book started out as an attempt to remedy this situation by creating a user-oriented companion guide for the specifications. Our goal wasn’t to create an OSGi cookbook but to thoroughly describe the important aspects of OSGi and show how to use them. Our main idea was to more simply explain the OSGi specifications by ignoring the implementation details and including additional usage information.

To that end, we’ve tried to limit ourselves to discussing the most common concepts, features, and mechanisms needed to work with OSGi technology throughout the book. That doesn’t mean we were able to avoid all the esoteric details. As you’ll find when you begin working with OSGi, it enforces a new level of strictness when it comes to modularity, which will likely break some of your old practices. In the end, you need to understand what’s going on under the covers in some places to be able to effectively debug and diagnose the situations in which you find yourself.

As our writing progressed, the book chapters began to separate naturally into three parts:

  1. Explaining the core OSGi specification
  2. Describing how to work with the specification in practice
  3. Introducing advanced OSGi-related topics

In part 1 of the book, we focus on explaining the most common aspects of the OSGi core specification from the user’s perspective. We introduce OSGi according to its three-layer architecture: module, lifecycle, and services. This isn’t the only approach to take in explaining OSGi; most explanations of OSGi start out with a simple bundle implementing a simple service. The downside of this type of approach, in our view, is that it cuts across all three OSGi layers at once, which would require us to explain all three layers at once.

The advantage of following a layered approach is that doing so creates a clear division among the concepts we need to discuss. For example, the modularity chapter focuses on modularity concepts and can largely ignore lifecycle and services. This approach also creates a natural progression, because modularity is the foundation of OSGi, lifecycle builds on it, and services are on top of lifecycle. We can also highlight how to use lower layers of the OSGi architecture without using the upper layers, which is sometimes worthwhile.

Part 2 of the book takes the knowledge about the OSGi core specification from part 1 and shows how you can use the technology from a more pragmatic viewpoint. We look into converting existing JAR files to bundles as well as testing, debugging, and managing bundles. These first two parts of the book should be of general interest to anyone wanting to learn more about using OSGi.

Part 3 covers various advanced topics, such as service-oriented component models, framework launching, security, and distributed computing technologies. This last part serves as a springboard to the world of possibilities available to you in the OSGi universe.

Roadmap

Chapter 1 presents a high-level view of OSGi technology and the issues it’s intended to address. To keep the chapter from being totally abstract, we present a few “Hello, world!” examples to illustrate the different layers of the OSGi framework, but the real meat of our OSGi discussion is in the following chapters. We also look at the state of modularity support in Java as well as in some related technologies.

Chapter 2 explores the module layer of the OSGi framework. We start with a general discussion of modularity in computing and then continue by describing OSGi’s module concept, called a bundle. We present OSGi’s declarative metadata-based approach for creating modules and show how to use it to modularize a simple paint program. We also investigate one of the key OSGi tasks: bundle dependency resolution.

Chapter 3 looks at the lifecycle layer of the OSGi framework. We discuss lifecycle management in general and describe how OSGi provides dynamic lifecycle management of bundles. We present OSGi’s lifecycle-related APIs by creating a simple OSGi shell and also adapt our paint program to make it lifecycle aware.

Chapter 4 examines the services layer of the OSGi framework. We describe what services are and discuss why and when you need them. We walk you through providing and using services with some toy examples and then take an iterative approach to describing how to deal with the unique aspect of service dynamism. We finish our service discussion by adapting the paint program, this time to use dynamic services.

Chapter 5 returns to the module layer and examines its more advanced or nuanced capabilities. We describe additional ways for bundles to deal with dependencies and content using bundle-level dependencies and bundle fragments. You also learn how bundles can deal with execution environments and native libraries.

Chapter 6 gives practical advice for converting JAR files into bundles, including how to define bundle metadata, package your bundle content, and add lifecycle support. We also describe how to go about dividing an application into bundles, demonstrating techniques on an existing open source project.

Chapter 7 shows how to test bundles and OSGi-based applications. We look into running your existing tests in OSGi and mocking OSGi APIs. In addition to unit and integration testing, we discuss management testing and explore some tools to help you along the way.

Chapter 8 follows testing by describing how to debug your bundles. We look into simple, command-line debugging as well as debugging with the Eclipse IDE. We show how to set up your development environment to get you up to speed quickly. We also explain some of the typical issues you encounter when working with OSGi and how to deal with them.

Chapter 9 switches gears and discusses how to manage your bundles. We explain how to meaningfully define version numbers for packages and bundles. We look into managing bundle configuration data and in the process describe a handful of related OSGi services. We also cover an option for triggering automatic bundle startup and initialization.

Chapter 10 continues investigating management topics, but moves from single-bundle issues to multi-bundle ones. We look at a couple of approaches for deploying bundles and their dependencies. We also explain how you can control bundle startup order.

Chapter 11 describes how component-oriented programming relates to OSGi. As a concrete example, we look at a standard OSGi component framework called Declarative Services. We show how Declarative Services allows you to work with POJOs and simplifies some aspects of dealing with service dynamism.

Chapter 12 continues investigating more advanced component frameworks for OSGi. We look at Blueprint, which is targeted toward enterprise developers familiar with Spring technology. We also examine the Apache Felix iPOJO component framework. We show that one of the benefits of OSGi-based component frameworks is they can all work together via services.

Chapter 13 turns away from developing bundles and looks at launching the OSGi framework. We describe the standard approach for configuring and creating OSGi frameworks. We also show how you can use the standard API to embed an OSGi framework into an existing application.

Chapter 14 delves into operating OSGi in a secure environment. We describe the issues involved and approaches to alleviating them. We explain how OSGi extends the standard Java security architecture to make it more flexible and easier to manage. And we show how to set up an OSGi framework with security enabled and create a secure example application.

Chapter 15 closes the book with a quick look at using web-related technologies in OSGi. We discuss using some common web applications technologies, such as servlets, JSPs, and WAR files. We also look into how to publish and consume web services.

Code

The companion code for the examples in this book is freely available from Manning’s website, www.manning.com/OSGiinAction.

In the text, Courier typeface is used to denote code as well as JAR file manifest headers. References to methods generally don’t include the signature, except when it’s necessary to differentiate. The coding style adopts two-space indents and same-line braces to keep everything condensed and isn’t otherwise recommended. When presenting command or shell interaction, normal Courier typeface is used to indicate program output, while bold is used to indicate user input.

Code annotations accompany many of the listings, highlighting important concepts. In some cases, numbered bullets link to explanations that follow the listing.

Author Online

Purchase of OSGi in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/OSGiinAction. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It is not a commitment to any specific amount of participation on the part of the authors, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking them some challenging questions lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the title

By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration.

Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, re-telling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action book is that it is example-driven. It encourages the reader to try things out, to play with new code, and explore new ideas.

There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want, just when they want it. They need books that aid them in action. The books in this series are designed for such readers.

About the cover illustration

The figure on the cover of OSGi in Action is a “Soldier.” The illustration is taken from a collection of costumes of the Ottoman Empire published on January 1, 1802, by William Miller of Old Bond Street, London. The title page is missing from the collection and we have been unable to track it down to date. The book’s table of contents identifies the figures in both English and French, and each illustration bears the names of two artists who worked on it, both of whom would no doubt be surprised to find their art gracing the front cover of a computer programming book...two hundred years later.

The collection was purchased by a Manning editor at an antiquarian flea market in the “Garage” on West 26th Street in Manhattan. The seller was an American based in Ankara, Turkey, and the transaction took place just as he was packing up his stand for the day. The Manning editor did not have on his person the substantial amount of cash that was required for the purchase and a credit card and check were both politely turned down. With the seller flying back to Ankara that evening the situation was getting hopeless. What was the solution? It turned out to be nothing more than an old-fashioned verbal agreement sealed with a handshake. The seller simply proposed that the money be transferred to him by wire and the editor walked out with the bank information on a piece of paper and the portfolio of images under his arm. Needless to say, we transferred the funds the next day, and we remain grateful and impressed by this unknown person’s trust in one of us. It recalls something that might have happened a long time ago.

The pictures from the Ottoman collection, like the other illustrations that appear on our covers, bring to life the richness and variety of dress customs of two centuries ago. They recall the sense of isolation and distance of that period—and of every other historic period except our own hyperkinetic present. Dress codes have changed since then and the diversity by region, so rich at the time, has faded away. It is now often hard to tell the inhabitant of one continent from another. Perhaps, trying to view it optimistically, we have traded a cultural and visual diversity for a more varied personal life. Or a more varied and interesting intellectual and technical life.

We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by the pictures from this collection.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.172.130