OSGi in Action
Manning have today published OSGi in Action, by Richard S Hall, Karl Pauls, Stuart McCulloch and David Savage. Written by long-term OSGi users and committers on the Apache Felix runtime, the depth of knowledge in the book comes across with subtleties and specific gotchas documented. A public table of contents available.
The first part of the book introduces the OSGi modularity model, its lifecycle and communicating with services. A sample chapter on OSGi revealed presents the style of the book and introduces how OSGi modularity compares to other approaches (both current and future).
The modularity part also looks into the differences between wiring up bundles, including the differences between
Import-Package, and when you should choose to make available entries via fragments. Much attention is given to OSGi's dynamic nature and considerations when services may come and go; although it notes that the latter part covers component models which may avoid having to deal with this directly. Specific attention is given to
DynamicImport-Package and the circumstances in which it should be used.
The second part looks at OSGi in practice, and it's here that the authors' experience with OGSi shines through. Instead of just listing some common patterns (such as the extender and whiteboard patterns) they dive into specific cases where mis-implementation can lead to problems; explain why those problems occur; and how to fix the issue. An excerpt from the Moving towards Bundles chapter describes ways in which a monolithic Java application can be recursively broken down into smaller modules using an iterative process.
There are also real world use-cases, including how to test and debug OSGi bundles at development time, and how to configure applications (using ConfigAdmin, Metatype and Preferences services), as well as subtleties when applications as sets of bundles are installed into a runtime.
The final part looks at advanced OSGi topics, such as component modules including declarative services, blueprint service and Apache Felix's iPOJO. Since these all operate on the baseline of OSGi services, they can be freely mixed and matched instead of having to implement a one-size-fits-all model.
There are also chapters on embedding OSGi within an existing Java application, using the security model to constrain the runtime behaviour and using web bundles to host a servlet-oriented application within an OSGi runtime.
There are many nuggets of useful information in the book, from explaining the difference between
NoClassDefFoundError, to why
Class.forName() is bad and how memory leaks can occur through leaking of classloaders during dynamic restarts (including subtleties on the use of
ThreadLocal storage). Even for experienced users of the OSGi platform there are things to learn, and for the beginner the helpful code examples (available on-line) provide a step-by-step mechanism to get you started with OSGi and what pitfalls to watch out for.
OSGi in Action is available from book retailers (ISBN 1933988916) as well as an eBook in PDF from the Manning book page. For today, use code "dotd0406" to get 50% off the print book.
Shane Hastie Aug 30, 2014
Roy Rapoport Aug 28, 2014