OSGi in Practice
Neil Bartlett
OSGi in Practice
Nuts and Bolts
What is a Module?
The Problem(s) with JARs
Class Loading and the Global Classpath
Conflicting Classes
Lack of Explicit Dependencies
Lack of Version Information
Lack of Information Hiding Across JARs
Recap: JARs Are Not Modules
J2EE Class Loading
OSGi: A Simple Idea
From Trees to Graphs
Information Hiding in OSGi Bundles
Versioning and Side-by-Side Versions
Dynamic Modules
The OSGi Alliance and Standards
OSGi Implementations
Alternatives to OSGi
Build Tools: Maven and Ivy
Eclipse Plug-in System
JSR 277
First Steps in OSGi
Bundle Construction
OSGi Development Tools
Eclipse Plug-in Development Environment
Installing a Framework
Setting up Eclipse
Running Equinox
Installing bnd
Hello, World!
Bundle Lifecycle
Incremental Development
Interacting with the Framework
Starting and Stopping Threads
Manipulating Bundles
Bundle Dependencies
Introducing the Example Application
Defining an API
Exporting the API
Importing the API
Interlude: How Bnd Works
Requiring a Bundle
Version Numbers and Ranges
Version Numbers
Versioning Bundles
Versioning Packages
Version Ranges
Versioning Import-Package and Require-Bundle
Class Loading in OSGi
JRE Packages
Execution Environments
Fragment Bundles
Class Space Consistency and "Uses" Constraints
Late Binding in Java
Dependency Injection Frameworks
Dynamic Services
Registering a Service
Unregistering a Service
Looking up a Service
Service Properties
Introduction to Service Trackers
Listening to Services
Tracking Services
Filtering on Properties
Cardinality and Selection Rules
Optional, Unary
Optional, Multiple
Mandatory, Unary
Mandatory, Multiple
Service Factories
Example: Mailbox Reader GUI
The Mailbox Table Model and Panel
The Mailbox Tracker
The Main Window
The Bundle Activator
Putting it Together
Concurrency and OSGi
The Price of Freedom
Shared Mutable State
Safe Publication
Safe Publication in Services
Safe Publication in Framework Callbacks
Don't Hold Locks when Calling Foreign Code
GUI Development
Using Executors
Interrupting Threads
The Whiteboard Pattern and Event Admin
The Classic Observer Pattern
Problems with the Observer Pattern
Fixing the Observer Pattern
Using the Whiteboard Pattern
Registering the Listener
Sending Events
Event Admin
Sending Events
The Event Object
Receiving Events
Running the Example
Synchronous versus Asynchronous Delivery
Ordered Delivery
Reliable Delivery
The Extender Model
Looking for Bundle Entries
Inspecting Headers
Bundle States
Using a Bundle Tracker
Testing the Help Extender
Bundle Events and Asynchronous Listeners
The Eclipse Extension Registry
Impersonating a Bundle
Configuration and Metadata
Configuration Admin
Building Configurable Objects
Configured Singletons
Running the Example with FileInstall
Configured Singleton Services
Multiple Configured Objects
Multiple Configured Objects with FileInstall
A Common Mistake
Multiple Configured Service Objects
Configuration Binding
Describing Configuration Data
Metatype Concepts
Creating a Metadata File
Building a Configuration Management Agent
Listing and Viewing Configurations
Creating and Updating Configurations
Creating Bound and Unbound Configurations
Creating a Simple Configuration Entry
Component Oriented Development
Introduction to Component Oriented Development
What is a Software Component?
Declarative Services
The Goal: Declarative Living
Summary of Declarative Services Features
A Note on Terminology and Versions
Declaring a Minimal Component
Running the Example
Providing a Service
Lazy Service Creation
Forcing Immediate Service Creation
Providing Service Properties
References to Services
Optional vs Mandatory References
Static vs Dynamic References
Minimising Churn
Implementing the Dynamic Policy
Service Replacement
Running the Example
Minimising Churn with Dynamic References
Recap of Dynamic Reference Implementation
Component Lifecycle
Lifecycle and Service Binding/Unbinding
Handling Errors in Component Lifecycle Methods
Unary vs Multiple References
Static Policy with Multiple References
Implementing Multiple References
Discussion: Are These True POJOs?
Using Bnd to Generate XML Descriptors
Bnd Headers for XML Generation
XML Generation from Java Source Annotations
Automatic Service Publication
Configured Components
Sources of Configuration Data
Testing with FileInstall
Dealing with Bad Configuration Data
Dynamically Changing Configuration
Configuration Policies
Example Usage of Required Configuration
Singletons, Factories and Adapters
Practical OSGi
Using Third-Party Libraries
Step Zero: Don't Use That Library!
Augmenting the Bundle Classpath
Embedding JARs inside a Bundle
Problems with Augmenting the Bundle Classpath
Finding OSGi Bundles for Common Libraries
Transforming JARs into Bundles, Part I
Step 1: Obtain and Analyse Library
Step 2: Generate and Check
Transforming JARS into Bundles, Part II
Step 3: Correcting Imports
Step 4: Submit to Repository
Runtime Issues
Reflection-Based Dependencies
Hidden Static Dependencies
Dynamic Dependencies
ClassLoader Shenanigans
Testing OSGi Bundles
Building Web Applications
ANT Build System for Bnd
The book hasn't received reviews yet.