Extender
Overview
As Peter Kriens defines "The extender pattern allows other bundles to extend the functionality in a specific domain.". (read more about on OSGi Alliance blog and Peter Kriens blog). Some projects that make use of this pattern are Pax Web Extender and Spring DM Extender.
The Extender is meant for those that need to implement an extender bundle and want to achieve this in easy way.
How do I make use of it?
As an extender bundle implementor you will have to:
- Implement your custom
BundleObserver
(what do you want to achieve with the extender) - Create and start a
BundleWatcher
, specifying the desiredBundleScanner
How does it work?
The BundleWatcher will watch for bundle life cycle events by using a synchronous bundle listener. As soon as a bundle gets started (and all previous started bundles), the BundleWatcher will inspect the bundle using the specified BundleScanner. If the BundleScanner returns any entry it will call the addingEntries on your custom BundleObserver passing along the bundle and the found entries. When a bundle gets stopped and that bundle generated any entry during the scanning process, the removingEntries on your custom BundleObserver will be called.
It's up to you as an extender bundle developer, what to do with the found entries.
Bundle Scanners
Bundle scanner's role is to process a starting bundle for specific types of artifacts such as for example specific files or specific entries in MANIFEST.MF
. As an extender bundle developer you can develop one of your own but there are built in bundle scanners that cover most of the common use cases such as:
- BundleURLScanner — scans for specific directory or files.
- BundleManifestScanner — scans a bundle manifest (META-INF/MANIFEST.MF) for specific entries (starting with version 0.2.0).
Examples
For examples check out built in bundle scanners.